Professional Documents
Culture Documents
Greenfoot: RIP Flappy Bird (2013-2014)
Greenfoot: RIP Flappy Bird (2013-2014)
http://www.mrferrante.com/flappybird/flappy_bird.html
greenfoot lab 4
Flappy Bird
Day 1
1. Click here to download the project images. (Note: These images are newer and better
than what I show in the video. They come from the Enhanced Graphics section between
Day 5 and Day 6 below.)
2. Click here to watch today's video.
3. Day 1 Homework
When FlappyBird reaches bottom of screen stop the game and print "Game
Over" to the console window using System.out.println("Game Over");
Hints: To stop game execution, look for a method in the API for the Greenfoot
class. Go to the main Greenfoot window (where you play the game) and select
Help | Greenfoot Class Documentation. Then select Greenfoot. Look for a
function in this class that ends the game. To use the functions in this class,
write Greenfoot.functionName();
4. Day 1 Extension (Optional)
When FlappyBird reaches bottom of screen, stop the game and display a Game
Over image instead of printing to the console.
Hints: You can do this many ways. Here's one way: Create a new GameOver
actor using the "game over" image in the image folder. Next, inside your
FlappyBird code, when FlappyBird reaches the bottom of the screen you should
tell the World to add a new GameOver object to the center of the screen and
then stop the game.
Want further detail? When FlappyBird reaches the bottom of the screen use
the new keyword to create a new GameOver object and store it in a variable.
Then use getWorld() to get the World you're in and tell it to add the
GameOver object using the addObject() function. Finally stop the game using
the appropriate command from the Greenfoot class.
Day 2
1. Click here to watch today's video.
2. Day 2 Homework
Implement yesterday's optional extension. (Shown in today's video.)
Change Flappy Bird's angle depending on velocity. (Hint: Look for useful
functions inside the Actor class to change FlappyBird's angle.)
1
2
3
4
5
6
7
Finally, modify all variables in FlappyBird until the motion feels smooth and
accurate.
Day 3
1. Click here to watch today's video.
2. Day 3 Homework
1 de 4
08/09/2015 15:52
Java Programming
http://www.mrferrante.com/flappybird/flappy_bird.html
When a pipe is created, move it so the top of the pipe is a random height
between the bottom of the screen and somewhere above the middle. This is
explained at the end of the video.
Define variable SPACE_BETWEEN_PIPES and add a top pipe this far above each
bottom pipe as shown at the end of the video.
Day 4
1. Click here to watch today's video.
2. Day 4 Homework
Instead of displaying the score in the console window, tomorrow we will draw
the score on the screen. See if you can do this on your own first. One
possibility is to draw on top of a Score actor's image.
Day 5
1. Click here to watch today's video.
2. Day 5 Homework
Modify the Score font, color, and position to your liking.
Enhanced Graphics
1. Sorry, there is no video yet.
2. Click here to download the new images. (Note: These are the same as Day 1 since I
replaced the Day 1 graphics with the ones linked here.)
3. (Optional) If you want all images from Flappy Bird, here are the sprite sheets. To use
them, here are Photoshop directions:
a. Click here to download sprite sheet 1 (original graphics)
Click here to download sprite sheet 2 (version 2 graphics)
b. Open sprite sheet and use the Selection tool to select a sprite you want.
Crop it out using Image | Crop.
c. Next, double its size using Image | Image Size. Make it double the width
and height and select Nearest Neighbor (Preserve Hard Edges) for the
resample algorithm.
d. Choose Sava As from the File menu and save it in PNG format. Done!
Day 6
1. Sorry, there is no video yet.
2. Today, we're going to animate Flappy Bird. Here's the procedure:
a. Declare three GreenfootImage variables in the global variables section of
your FlappyBird class. Each image will be one animation frame (up wing,
straight wing, down wing).
b. Create a constructor for FlappyBird by adding a public FlappyBird()
function to your code. Then initialize the images in your constructor using
new GreenfootImage("filename").
c. Add global variable: int animFrame = 1;
d. Finally, add this logic to your FlappyBird code: Every act() step, increase
the animCounter. Base the image used on the animation counter. Use
setImage() to set the image of Flappy Bird.
3. Day 6 Homework
Instead of hardcoding the animation rate, add a global variable to FlappyBird
called ANIM_RATE, and use it to control the animation speed. If ANIM_RATE =
3, for example, switch to the next image after 3 act steps.
Memory management
1. Currently, pipes are created off-screen and then instructed to slide to the left. But after a
pipe has slid across the world and is no longer visible, where do they go? The answer is:
they keep going. The longer you play, the more off-screen pipes there are taking up
valuable memory space and processing power. Modify your Pipe code to remove pipes
when they are no longer visible on the screen.
Day 7
1. Sorry, there is no video yet.
2. Today, we're going to add a title screen to Flappy Bird.
a. On the title screen are two new Actors: A "Flappy Bird" title and a Start
button. You can create your own images, pull them from the original
2 de 4
08/09/2015 15:52
Java Programming
http://www.mrferrante.com/flappybird/flappy_bird.html
3 de 4
08/09/2015 15:52
Java Programming
http://www.mrferrante.com/flappybird/flappy_bird.html
e. Parallax background
Parallax is when multiple layers of the background move at different
speeds. I have this working in my demo game. Accomplishing this can be
easy to hard depending on how much hard-coding you do or don't use. I
generalized scrolling to work based on specifying an images speed and
repeat width.
f. Horizontal Flappy Movement
Although getting Flappy Bird to move horizontally is easy, getting your
score to syncronize with the horizontal motion is not. So, be aware of
this before beginning this challenge.
g. Pipes open/close like a miniature golf castle door
If you completed horizontal flappy movement, this is a great feature to
add.
h. Your own idea
There is almost no limit to what you can do. Add your own twist!
2010 MrFerrante.com | Design by styleshout | Valid XHTML | CSS
4 de 4
08/09/2015 15:52