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

2018/12/5

Gameover

Blyat Blyat

2018/12/5

#
How do I add a game over scenario ?
Blyat Blyat

2018/12/5

#
I've got problems by letting Greenfoot start a ''Gameover'' scenario. Don't know how to code this...
danpost danpost

2018/12/5

#
Blyat wrote...
I've got problems by letting Greenfoot start a ''Gameover'' scenario. Don't know how to code this...
Too vague and no code attempt. Start by creating a new subclass of World for when game is over.
epicgamez4201337 epicgamez4201337

2018/12/7

#
First you will need to create a subclass of World. In my game i named it "GameOver". You will have to make a code that changes to the game over world. In my case, this is when the life variable is 0.
if (life == 0) {

                    Greenfoot.setWorld(new GameOver()); //changes to the GameOver class

                            }
In the subclass, I've used this code
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
         
         
    }
}
You need to login to post a reply.