How do I add a game over scenario ?
if (life == 0) {
Greenfoot.setWorld(new GameOver()); //changes to the GameOver class
}
public class GameOver extends World
{
/**
* Constructor for objects of class LevelSelect.
*
*/
public GameOver()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1000, 800, 1);
}
public void act()
{
this.setBackground("gameover.png"); //this is an image i made. put this in the images map and make sure it is the same size as the world
if(Greenfoot.isKeyDown("space")){ //continue when the spacebar is pressed
Hero.life = 2; //this sets the life variable back to 2.
Greenfoot.setWorld(new LevelSelect());} //goes back to the level selection screen. change LevelSelect to the name of your world class
}
}