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

2014/2/15

How do you stop what is happening in the background?

dangamecreator dangamecreator

2014/2/15

#
I am making a game like flappy bird called flappy pig. I have written a code so that when you die your score comes up and a play button, but when you die the bird keeps on moving which means you can keep on playing. How do I stop that from happening?
 public void gameOver(int score) {
        addObject(new GameOver(score), getWidth() / 2, getHeight() / 2);
        Click button = new Click();  
        addObject(button, 306, 74);
        
    }
danpost danpost

2014/2/15

#
Put the code within the act method of the bird (or pig) in an 'if' block. Use the condition 'if (getWorld().getObjects(GameOver.class).isEmpty())'. Or, just insert as the first line in that method 'if (!getWorld().getObjects(GameOver.class).isEmpty()) return;'.
dangamecreator dangamecreator

2014/2/15

#
Thanks for your help, but the when you click, the pig can still fly (but you don't score points, which is a good thing), how do you stop the player from moving the pig?
danpost danpost

2014/2/15

#
Again, put the code where the player controls the flying of the pig in an 'if' block.
You need to login to post a reply.