I need help implementing gravity into FlappyBird using the applyGravity() method. I'm told it should be public and void. I've also been instructed that there should be 2 statements.
a) Use the setLocation(int x, int y) method and write a statement that will get the
current x and y for the bird and add the velocity variable to the Y coordinate.
b) Write an expression that will update the velocity variable by adding the gravity
variable to it.
This is the code for my bird.
This is the code for my world.
Any help is appreciated.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Bird1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bird1 extends SharedResources
{
/**
* Act - do whatever the Bird1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
Bird1 bird1 = new Bird1();
setImage("flappybird1.png");
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class FlyingBirdWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class FlyingBirdWorld extends World
{
/**
* Constructor for objects of class FlyingBirdWorld.
*
*/
public FlyingBirdWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
populate();
}
/**
* Objects added into game
*
*/
public void populate()
{
Bird1 b = new Bird1();
addObject(b, 40, 200);
BottomPipe a = new BottomPipe();
addObject(a, 300, 400);
TopPipe c = new TopPipe();
addObject(c, 300, 0);
BottomPipe d = new BottomPipe();
addObject(d, 450, 380);
TopPipe e = new TopPipe();
addObject(e, 450, -100);
Ground f = new Ground();
addObject(f, 600, 400);
Ground g = new Ground();
addObject(g, 300, 400);
}
public void act()
{
FlyingBirdWorld bgImage = new FlyingBirdWorld();
setBackground("background.png");
}
}
