This site requires JavaScript, please enable it in your browser!
Greenfoot back
hesh
hesh wrote ...

2011/3/22

Intersections

hesh hesh

2011/3/22

#
Hello again! Progressed big time on my project with the help of davmac. I'm nearly done with the basic stuff, though I've still got two small questions. First, when objects are moved onto each other one of their images will show on top. I want to see the images of one class on top at all times when these objects intersect. Is there a way to manage this? Second, I want the world to check whether several objects are intersecting with several others that are located on specific locations. It is the goal of my game to move objects to these locations. If this is the case the World should be doing something, for now simply launch the next level. Here's the info from my World that's probably relevant: (the crates can be moved, the goals is where they should be moved to) addObject(new Crate(), 4, 3); addObject(new Crate(), 3, 4); addObject(new Crate(), 4, 5); addObject(new Crate(), 5, 4); addObject(new Goal(), 3, 2); addObject(new Goal(), 6, 3); addObject(new Goal(), 2, 5); addObject(new Goal(), 5, 6); if(getObjectsAt(3, 2, Crate.class) != null && getObjectsAt(6, 3, Crate.class) != null && getObjectsAt(2, 5, Crate.class) != null && getObjectsAt(5, 6, Crate.class) != null) { levelTwo(); } With this in the code, it moves to level 2 straight away, without the player to have needed to move a thing in level 1. What am I missing? Why is this?
delmar delmar

2011/3/22

#
For your first question (showing one image always on top of another), look at the setPaintOrder method in the World class. It allows you to set the painting order by class (that is: objects of one class always painted on top of objects of another class). You cannot order individual objects, but ordering by class is usually fine. For your second problem: 'getObjectsAt' from the World class returns a list. If there are no objects at that location, you get an empty list, but you still get a list. You never get null. So instead of checking for null, you should check for an empty list: if( !getObjectsAt(3, 2, Crate.class).isEmpty() && ...
davmac davmac

2011/3/23

#
@delmar is correct, however, I think there is another problem with your code here. It looks like the check: if(getObjectsAt(3, 2, Crate.class) != null && getObjectsAt(6, 3, Crate.class) != null && getObjectsAt(2, 5, Crate.class) != null && getObjectsAt(5, 6, Crate.class) != null) { levelTwo(); } ... is meant to move to the next level (levelTwo()) once crates have been moved into the appropriate positions. However, you can't do this straight after setting up the first level - they definitely won't be in the right positions then! Instead you need to do it each simulation round, perhaps in the World's act() method.
jyatiz jyatiz

2011/11/2

#
I want to use the following code to detect when an object is in the cell, however it´s and it seems to loop back and forward as it turns around once it gets past the grass object if (puedoMover(getX(), getY()) == true && zacate != null){ girarMediaVuelta(); } public void girarMediaVuelta() { // Quiz #1 switch(getRotation()) { case ESTE: setRotation(OESTE); break; case SURESTE: setRotation(NOROESTE); break; case SUR: setRotation(NORTE); break; case SUROESTE: setRotation(NORESTE); break; case OESTE: setRotation(ESTE); break; case NOROESTE: setRotation(SURESTE); break; case NORTE: setRotation(SUR); break; case NORESTE: setRotation(SUROESTE); break; } } For some reason my greenfoot is unable to summon the isEmpty() method...can you tell me how to summon it to include it in my method? Thanks
You need to login to post a reply.