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

2017/12/11

How to stop the game?

agiastaee agiastaee

2017/12/11

#
how to stop this game?
import greenfoot.*; 

public class FlappyBird extends Actor
{
    double dy = 0 ;
    double g = 1.3 ;
    double BOOST_SPEED = -15 ;
    public void act() 
    {
        setLocation( getX(),(int)(getY() + dy));
        // jika tombol atas ditekan
        if (Greenfoot.isKeyDown("up") == true) {
            dy = BOOST_SPEED;
        }
        // jika flappy jatuh maka game over
        if (getY() > getWorld().getHeight()) {
            System.out.println("Game Over") ;
            Greenfoot.stop();
        }
        dy= dy + g ;
    }    
}
danpost danpost

2017/12/11

#
The height of the world is the number of cell rows given to your world. Your actor will never be at a row that is greater than that number. In fact, because the top-most row is row zero, the bottom-most will not even be the same value as the height, but one less than that. Change line 16 to:
if (getY() == getWorld().getHeight()-1) {
agiastaee agiastaee

2017/12/12

#
its work! thanks for your help
You need to login to post a reply.