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

2016/3/4

Game over starts at same level

PrincessPeach PrincessPeach

2016/3/4

#
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?
Super_Hippo Super_Hippo

2016/3/4

#
You can have a GameOver screen.
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));
    }
}
You need to login to post a reply.