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

2012/10/24

Changing levels

BradH BradH

2012/10/24

#
hello, I am creating a shooting game with multiple levels and I was wondering how to have the game proceed to the next level once the enemies in the level are destroyed, Thanks
erdelf erdelf

2012/10/24

#
this is the code for changing the world:
Greenfoot.setWorld(new YourWorld());
BradH BradH

2012/10/24

#
how can I set the world to change to another level after something happens, for example an if statement like if x is pressed in changes to the next level or once all the enemies are gone etc.?
danpost danpost

2012/10/24

#
In the world act method, say
if (getObjects(Enemy.class).isEmpty()) Greenfoot.setWorld(new ...World());
// or 
if (Greenfoot.isKeyDown("x")) Greenfoot.setWorld(new ...World());
BradH BradH

2012/10/24

#
I have public void nextlevel() { if (Greenfoot.isKeyDown("s")) Greenfoot.setWorld(new Level2()); } but It is not going to the next level
danpost danpost

2012/10/24

#
Are you calling 'nextlevel();' from an act method or from a method that it calls?
BradH BradH

2012/10/24

#
public void nextlevel() is the method in the first level, so I think an act method
danpost danpost

2012/10/24

#
You may want to download and look at the code for my Crayon Babies scenario. It demonstrates world-changing using both mouse click and keypress methods.
danpost danpost

2012/10/24

#
You need a 'public void act()' method with the 'nextlevel();' command in it, in the class that has the 'nextlevel()' method, to execute the 'nextlevel()' method.
BradH BradH

2012/10/24

#
Ok, I will check it out,thanks
You need to login to post a reply.