Hi,
when I press enter, I wanna load a new world in my game, if there is (or isn't) a certain object currently in my world.
How do i check if there is an object currently located in the world?


1 2 | List objectslookingfor = getObjects(ObjectLookingFor. class ); if (objectslookingfor.size() == 0 ) addObject( new ObjectLookingFor(), x, y); |
1 | import java.util.List; |
1 2 3 4 5 6 7 8 9 | String key = Greenfoot.getKey(); if (key != null ) { if ( "enter" .equals(key)) { getWorld().addObject( new Man(), x, y); // x and y can be literals or preset integer variables // getWorld().removeObject(this); *** if removing object also *** } } |
1 2 3 4 5 6 | private A theA; public A getA() { return theA; } |
1 2 3 4 5 6 7 8 | public static int x = 0 ; public static int y = 0 ; public void act() { x=getX(); y=getY(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public void addC() { Actor A; A=getOneIntersectingObject(A. class ); if (A != null ) { World world; world=getWorld(); world.addObject( new C(), getX(), getY()); } } |
1 | addObject( new C(), A.x, A.y); |
1 | if (intersectingB()) addC();' |
1 2 3 4 5 6 7 8 9 10 11 12 13 | private boolean intersectingB() { Actor b; b = getOneIntersectingObject(B. class ); return (b != null ) } private void addC() { World world; world.getWorld(); world.addObject( new C(), getX(), getY()); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public void addC() { Actor A; A=getOneIntersectingObject(A. class ); if (A != null ) { World world; world=getWorld(); world.addObject( new C(), getX(), getY()); } } |
1 | addObject( new C(), A.x, A.y); |
1 | addObject( new C(), A.getX(), A.getY()); |
1 2 3 4 5 6 | List cList = getIntersectingObjects(C. class ); if (cList.size() >= maxCperB) { getWorld().removeObjects(cList); // removing all c objects that are on this b object getWorld().removeObject( this ); // removing this b object } |