Dear fellow greenfooters,
I want a container, to get fixed at the top of the crane when I click on a container. I've been trying many codes and Im really stuck.
This is what I (with the help of another post on this forum) got by now.
Whats wrong with this code?
This screenshot might help in understanding the scenario:
Thanks in advance
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | public class Crane extends Actor { private Container7 container; public void act() { if (!getIntersectingObjects(Container7. class ).isEmpty()) { } if (container == null && Greenfoot.isKeyDown( "p" ) && !getObjectsInRange( 25 , Container. class ).isEmpty()) { container = (Container7) getObjectsInRange( 25 , Container7. class ).get( 0 ); } if (container != null && Greenfoot.isKeyDown( "d" )) { container = null ; } } public void setLocation( int x, int y) { super .setLocation(x, y); if (container != null ) { container.setLocation(x, y+ 5 ); } } |
