Hi, I want the Crane class to drop ALL the containers (they are numbered, and Container.class is the superclass) on the direction the crane is facing. Right now only one (Container.class) works correctly. All the other containers return to their place after I hit "d" cuz they have different act methods (they stay on different X and Y coordinates on the ship). Can somebody help me out so that the drop method doesnt only apply to one container but the other subclasses as well?
This is the pickUpAndDrop method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public void pickUpandDrop() { if (container == null && Greenfoot.isKeyDown( "p" )) { move(getImage().getWidth()/ 2 ); container = (Container) getOneObjectAtOffset( 0 , 0 , Container. class ); move(-getImage().getWidth()/ 2 ); if (container != null ) container.ship = null ; } if (container != null && Greenfoot.isKeyDown( "d" )) { container = null ; } } |