Flappy Parrot
Flappy Parrot
Raspberry Pi Projects
Flappy Parrot
Introduction
Create a game in which you have to guide a parrot through scrolling pipes to score points.
Software
Scratch 2.0 (either online (https://scratch.mit.edu/projects/editor/) or o ine
(https://scratch.mit.edu/scratch2download/))
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 1/15
11/05/2018 Raspberry Pi Projects
If you prefer to work o ine and have not installed the editor yet, you can download
it from jumpto.cc/scratch-o (http://jumpto.cc/scratch-o ).
The cat sprite that you can see is the Scratch mascot. If you need an empty
Scratch project, you can delete the cat by right-clicking it and then clicking delete.
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 2/15
11/05/2018 Raspberry Pi Projects
You can browse backdrops by category or theme. Click on a backdrop and click OK.
This opens the info panel. You can also right-click on a sprite and choose info.
You can edit the name of the sprite and then click the triangle to close the info panel.
The Pipes sprite will have a pair of pipes with a gap in the middle. You’ll be able to move
the sprite up and down to get the gap in a di erent place.
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 3/15
11/05/2018 Raspberry Pi Projects
This picture shows an example of how the pipes could be positioned, the parts outside
the stage are normally hidden, you only see it when you drag the sprite:
You can’t draw a pipe as big as the pipes need to be, but you can increase the size of a
sprite when it’s used.
This will make it easier to see how big you need to make the pipes.
When you are in bitmap mode you can click Convert to vector to switch to vector
mode.
In vector mode, the tools appear on the right side of the drawing area.
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 4/15
11/05/2018 Raspberry Pi Projects
Choose the select tool (the arrow) to move, resize, and rotate shapes and lines.
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 5/15
11/05/2018 Raspberry Pi Projects
Select the kind of gradient you want, and the two colours to which you want to apply
the gradient. Then click on the shape you want to ll.
Click on the duplicate (stamper) tool and then on your pipe to create a copy.
Drag the copy of the sprite to the bottom of the screen, in line with the top sprite.
If you like, you can add extra shaded rectangles to the ends of the pipes:
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 6/15
11/05/2018 Raspberry Pi Projects
Create a clone of your Pipes sprite every two seconds. Each clone should scroll across
the stage from right to left (towards the parrot).
Tip: you can stop the pipes scrolling by clicking the red stop button.
I need a hint
This is what your code should look like:
Now you should have lots of pipes, but the gap is always in the same place. Add some
variety by putting the gap between each set of pipes at a di erent height.
Scratch coordinates
Scratch coordinates
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 7/15
11/05/2018 Raspberry Pi Projects
In Scratch, the coordinates x:0, y:0 mark the central position on the Stage.
A position like x:-200, y:-100 is towards the bottom left on the Stage, and a
position like x:200, y:100 is near the top right.
You can see this for yourself by adding the xy-grid backdrop to your project.
I need a hint
This is what your code should look like:
Now you can add a sprite called Flappy. If you don’t press any keys, then Flappy should just
fall down the screen.
Add a sprite with two costumes, for ‘wings up’ and ‘wings down’. The parrot sprite is a
good choice. Name your sprite ‘Flappy’.
Flappy needs to be smaller — reducing the sprite’s size to about 25% should do it. You can
either use the Shrink tool or a set size to ( ) block.
When the game starts, Flappy should be just to the left of the centre of the screen, at
coordinates -50, 0. Code Flappy to go to the starting position at the start of the game.
Type in the x position and y position that you want your sprite to go to.
If you only want to set the x or y position, you can use either of the following two
blocks instead.
Now you need to make Flappy keep falling down the stage.
I need a hint
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 9/15
11/05/2018 Raspberry Pi Projects
Test your code to make sure Flappy starts in the middle of the screen and falls to the
bottom. When you drag Flappy to the top of the screen, the sprite should fall again.
Make Flappy y
Next we want Flappy to ap upwards when you press the space bar. You’ll need to time your
taps to get through the gaps in the pipes.
Can you add code to make Flappy y upwards when you tap the space bar?
I need a hint
Here’s how your code should look:
Click on the Costumes tab, and name the costumes wings up and wings down.
Can you make Flappy’s costume change to wings down when you press space, and
then to wings up halfway through the upward movement?
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 10/15
11/05/2018 Raspberry Pi Projects
I need a hint
Your code should look like this:
Now you can test your code. As you’ll see, nothing bad happens if you hit a pipe. In the
next step, you’ll change that.
Import a sound from the library that will play when Flappy collides with something. The
‘screech’ sound is a good choice.
Click the Sounds tab, and click Choose sound from library:
Sounds are organised by category, and you can click the Play button to hear a
sound. Choose a suitable sound and click OK.
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 11/15
11/05/2018 Raspberry Pi Projects
You should then see that your sprite has your chosen sound.
You’re going to use a wait until block to check for whether Flappy is touching the
pipes.
Any code you place after a wait until block will only run after the condition is met.
Can you add to the code so Flappy screeches if she touches a pipe or the edge of the
stage.
I need a hint
Your code should look like this:
Test your code. You might notice that you only hear the screech the rst time you have a
collision. That’s okay, because the game ends if you have a collision.
Add the highlighted code to stop the game after a collision is detected:
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 12/15
11/05/2018 Raspberry Pi Projects
The stop block stops other Flappy scripts that are running. Flappy won’t fall after a
collision.
The broadcast block tells other sprites that the game is over.
Add the following code to the Pipes sprite so that the pipes stop when a Game over
message is received.
Now test your game and see how long you can last!
Add scoring
The player should score a point every time Flappy makes it through a gap between pipes.
Let’s add that code for that next!
Each Pipes clone is going to wait until Flappy has own past, and then increase the
score.
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 13/15
11/05/2018 Raspberry Pi Projects
Complete the code so that a point is scored, and a sound of your choice is played, when
Flappy’s x position is greater than (>) the pipe’s x position.
Test your code and make sure you score a point every time Flappy gets past an obstacle.
Make sure the score goes back to 0 when you start a new game.
I need a hint
Your code should look like this:
Let’s say you have a variable called score, which gets set to zero at the beginning of
each game.
At the end of the game (or whenever you want to update the high score), you’ll need to
check whether you have a new high score.
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 14/15
11/05/2018 Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 15/15