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

2015/12/5

Tron Game Need Help

aang.18 aang.18

2015/12/5

#
Question, I used getOneIntersectingObject, but I can't stop the game since I have to say return false else return false, is there a way to end the game? Also how do I add the instruction screen and then populate and create the world? This code: public boolean collide() { Actor bluecycle = getOneIntersectingObject( BlueCycle.class ); if (bluecycle == null) { return false; } else { return true; } }
ElNo ElNo

2015/12/7

#
I hope that I'm understanding your question right, as it is a bit hazy... 1) As I understand you try to stop the game if there is a collision. Possible solutions: a) If you don't need the return value outside of your method collide and this test is just to determine whether to stop the game or not, you can simply change your type of return value to void. If there is no collision the method does nothing at all after checking for a collision. If there is a collision you can call the Greenfoot.stop() method. b) if you need the return value outside of the method collide you can integrate the stoppig on the program in the line of the method-call, something like:
if(collide()==true)
{
Greenfoot.stop();
}
2) If you want to change the world displayed, you have to create two subclasses of World, for example Instruction and Game. On the start the Instruction-World is shown. On some signal (like pressing a key) you can change the shown World with
Greenfoot.setWorld(new Game());
An other way would be use only one subclass of World, setting the size. You can have a subclass Instruction of Actor that has an image of your instructions as picture. On constructing your world you place an object of this class in your world. On a signal from the user you remove this object and populate the World by using the addObject-Method.
You need to login to post a reply.