In this activity you will create the game Flappy Bird. To do so, complete the following steps:
Create the bird sprite on the left side of the screen. If left alone the bird should fall off the screen due to gravity. If the screen is touched the bird should move up like it flapped its wings.
To get the bird to fall, continually update the bird’s y speed to increase by a fixed amount every frame. For example, if the strength of gravity is 10 and the bird’s y speed is 10 on the first frame, its speed would become 20. If its speed is 30, it would become 40. frame it’s speed bird’s speed is 0 the first frame, it should be increase due to gravity.
To get the bird to fly when the screen is touched, do not use the
board->touched
function. This will cause the bird to fly as long as the user holds their finger down, which would make the game too easy. Instead add aboard->on tap
function. This function has awhere tapped
in-line-function where you can specify what to do when the user taps the screen. Inside thewhere tapped
set the bird’s y speed to move it up.
Add the moving obstacles. The obstacles should have a fixed width but a random height. The obstacles should have random x positions and y positions that put them either at the top of the screen or the bottom of the screen.
Create a sprite set and use a
for
loop to add the sprites to the sprite set. You can useboard->create rectangle
to create the sprites. When creating the rectangles, specify the width and height so that they are all the same width, but are random heights.For each sprite, set its position to a random x value that will not overlap with the x position of the bird, otherwise the game will be over as soon as it starts. Half of the rectangles should have y coordinates on the top of the screen. The other half should have y coordinates on the bottom of the screen.
Also set each sprite’s x speed so that it is moving left.
Add interaction to the game. It should be possible to lose the game and the game should keep on going once all the rectangles have moved off of the screen.
End the game if the bird hits a rectangle, or if the bird goes off the top or bottom of the screen. Test for these situations in the
board->on every frame
function. Use thegame->end
function to end the game. To test if the bird hit any of the rectangles, you will need to use afor each
loop to check if the bird overlaps with each rectangle one at-a-time.To make the game continue indefinitely, continually add rectangles to the right side of the screen. Instead of deleting rectangles and creating new ones, the game can recycle the existing rectangles. When a rectangle goes off of the left side of the screen, add it a little bit off of the right side of the screen. Add it to a random location off of the screen so that they do not repeat the exact same pattern over and over. Test if a rectangle is off the screen inside the
for each
that is used to test if a rectangle overlaps with the bird.
Submission
Please show your source code and run your scripts for the instructor or lab assistant.