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

2016/1/14

Flappy Bird

sosimple sosimple

2016/1/14

#
Im trying to make a Flappy bird but i can seem to get the bird to move up smoothly. Any advise?
int timer;
    /**
     * Act - do whatever the Bird wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move();
        die();

        //gameOver();
    }   

    public void move()
    {

        if(Greenfoot.mouseClicked(null))
        {
            timer++;
            if(timer < 100)
            {
                setLocation(getX(), getY()-100);
                setRotation(-15);
            }
        }
        else
        {
            setLocation(getX(), getY()+5);
            setRotation(15);
        }
    }
thats what i have so far, it makes him go up for just one numAct then instantly goes back down. You wouldn't even notice it, its so quick.
danpost danpost

2016/1/14

#
In the 'move' method, you are using the Greenfoot class 'mouseClicked' method, which returns 'true' once each time a mouse button is released. Now, within the code that executes when a mouse button is released, you are incrementing the 'timer' field, which is currently just counting the number of mouse clicks detected. You should find that after 100 clicks, even the instantaneous going up will stop occurring. Basically, you need to re-think your logic so that the incrementing of the 'timer' field will continue once it has started. Also, you show the bird going down at a rate of 5 pixels per act and appear to want the bird to go 20 times faster in the up direction (by using '100' for the up movement offset as opposed to using '5' for the downward movement).
You need to login to post a reply.