When I'm in level 2 and I walk into an enemy, the game is over. Then I restart in level one. I want to restart in level 2, the same level as the game stopped.
Does somebody know how I can code that?
private int level = 0;
public GameOver(int lvl)
{
level = lvl;
//setImage(...);
}
public void act()
{
if (Greenfoot.mousePressed(this))
{
switch(level)
{
case 1: Greenfoot.setWorld(new Level1()); break;
case 2: Greenfoot.setWorld(new Level2()); break;
//case 3: Greenfoot.setWorld(new Level3()); break;
//...
}
//OR, if you have one world subclass for all levels, if could also look like this:
//Greenfoot.setWorld(new Level(level));
}
}