Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 1/18
Projects
Boat race
Create a boat-racing game in which you have to
avoid obstacles
Step 1 Introduction
In this resource, you are going to learn how to make a racing game. The player uses the mouse to navigate a boat
to an island without bumping into obstacles.
What you will make
What you will need
Hardware
A computer capable of running Scratch 3
Software
Scratch 3 (either online (https://rpf.io/scratchon) or o�ine (https://rpf.io/scratcho�))
Downloads
Downloads can be found here (http://rpf.io/p/en/boat-race-go).
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 2/18
What you will learn
Use operators to compare numbers in Scratch
Add code to detect when a sprite is touching a colour in Scratch
Use a variable to record the time in Scratch
Additional information for educators
If you need to print this project, please use the printer-friendly version (https://projects.raspberrypi.org/en/projects/boat-race/print).
You can �nd the completed project here (http://rpf.io/p/en/boat-race-get).
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 3/18
Step 2 Getting started
Open the starter project.
Online: open the online starter project at rpf.io/boat-race-starter-on (http://rpf.io/boat-race-starter-on).
If you have a Scratch account you can make a copy by clicking Remix.
O�ine: download the o�ine starter project from rpf.io/p/en/boat-race-go (http://rpf.io/p/en/boat-race-go), and then open it using the o�ine editor.
If you need to download and install the Scratch o�ine editor, you can �nd it at rpf.io/scratcho� (http://rpf.io/scratcho�).
The project includes a boat sprite, and a race course backdrop with:
Wood that the boat sprite has to avoid
A desert island that the boat has to reach
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 4/18
Step 3 Controlling the boat
The player will control the boat sprite with the mouse.
Add code to the boat sprite so that it starts in the bottom left-hand corner pointing up and then follows
the mouse pointer.
when clicked
point in direction 0
go to x: -190 y: -150
forever
point towards mouse-pointer
move 1 steps
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 5/18
Test your code by clicking the green �ag and moving the mouse. Does the boat sprite move towards the
mouse pointer?
What happens when the boat reaches the mouse pointer? Try it out to see what the problem is.
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 6/18
To stop this from happening, you need to add an if block to your code, so that the boat sprite only
moves if it is more than 5 pixels away from the mouse pointer.
This is what your code should look like:
when clicked
point in direction 0
go to x: -190 y: -150
forever
if distance to mouse-pointer > 5 then
point towards mouse-pointer
move 1 steps
Test your code again to check whether the problem is now �xed.
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 7/18
Step 4 Crashing!
At the moment, the boat sprite can simply sail through the wooden barriers! You’re going to �x that now.
You need two costumes for your boat sprite: one normal costume, and one for when the boat crashes.
Duplicate your boat sprite’s costume, and name one costume ‘normal’ and the other ‘hit’.
Click on your ‘hit’ costume, and use the Select tool to grab pieces of the costume and move and rotate
them to make the boat look like it has crashed to pieces.
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 8/18
Now add code to your boat so that it crashes and breaks up when it touches any brown wooden barriers.
Here’s what your code should look like:
when clicked
point in direction 0
go to x: -190 y: -150
forever
if distance to mouse-pointer > 5 then
point towards mouse-pointer
move 1 steps
if touching color ? then
switch costume to hit
say Noooooo! for 2 seconds
switch costume to normal
point in direction 0
go to x: -190 y: -150
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 9/18
You should also add code to make sure that your boat sprite always starts out looking ‘normal’.
Test your code again. If you try to sail the boat through a wooden barrier now, the boat should crash and
then move back to its starting position.
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 10/18
Step 5 Winning!
Now add another if statement to your boat sprite’s code so that the player wins when they make the
boat arrive at the yellow island.
When the boat gets to the island, the game should say ‘YEAH!’, and then it should end.
Here’s what your new code should look like:
Don’t forget that this new code needs to be inside the forever loop.
if touching color ? then
say YEAH! for 2 seconds
stop all
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 11/18
Challenge: sound e�ects
Can you add sound e�ects that play when the boat crashes or reaches the island?
You could even add background music!
Challenge!
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 12/18
Step 6 Adding a timer
Now you will add a timer to your game, so that the player has to get to the island as quickly as possible.
Add a new variable called time to your Stage.
You can also choose a look for your timer by changing how your new variable is displayed.
Now add code blocks to your Stage so that the timer counts up until the boat reaches the island.
Here’s what your new code should look like:
when clicked
set time to 0
forever
wait 0.1 seconds
change time by 0.1
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 13/18
Test out your game and see how quickly you can get the boat to the island!
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 14/18
Step 7 Obstacles and boosters
Right now the game is far too easy, so you will add some things to make it more interesting.
First, you’ll add some boosters to speed up the boat.
Next you’ll add a spinning gate that the boat has to avoid.
Edit your Stage backdrop by adding in some white booster arrows.
Now add more code blocks to your boat’s forever loop so that the boat sprite moves three extra steps
when it touches a white arrow.
if touching color ? then
move 3 steps
Test your game to see whether your new booster arrows speed up the boat.
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 15/18
Add a new sprite that looks like this, and call it ‘gate’:
Make sure that the colour of the gate sprite is the same as the colour of the wooden barriers.
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 16/18
Make sure that the centre of the gate sprite is positioned in the middle.
Add code to your gate sprite to make it spin slowly forever.
Here’s what your new code should look like:
when clicked
forever
turn 1 degrees
Test your game again. You should now have a spinning gate that you need to stir your boat around.
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 17/18
Challenge: improving your game
Can you add more obstacles to your game? For example, you could add green slime to your backdrop and
make changes to the code so that the slime slows the boat down when the player lets them touch.
You could add a moving obstacle, for example a log or a shark!
Can you turn your game into a race between two players? The second player will need to control their boat
using the up arrow to move forward and the left and right arrow keys to turn.
Can you create more levels by adding di�erent backdrops, and can you then allow the player to choose
between levels?
Challenge!
26/05/2020 Boat race | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/boat-race/print 18/18
Step 8 What next?
Congratulations on completing the ‘Boat race’ project! Would you like to try something a little more challenging?
You could try out the Memory (https://projects.raspberrypi.org/en/projects/memory?utm_source=pathway&utm_medium=whatnext&utm_campaign=projects) project.
Published by Raspberry Pi Foundation (https://www.raspberrypi.org) under a Creative Commonslicense (https://creativecommons.org/licenses/by-sa/4.0/).
View project & license on GitHub (https://github.com/RaspberryPiLearning/boat-race)
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 1/29
Projects
Dodgeball
Create a platform game in which you dodge moving
balls to reach the end of the level
Step 1 Introduction
You’ll learn how to create a platform game in which the player has to dodge moving balls to reach the end of the
level.
What you will need
Hardware
A computer capable of running Scratch 3
Software
Scratch 3 (either online (https://scratch.mit.edu/projects/editor/) or o�ine (https://scratch.mit.edu/download/))
Downloads
You can �nd the downloads here (http://rpf.io/p/en/dodgeball-go).
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 2/29
What you will learn
How to use the keyboard to control a sprite
How to use the if, then, else Scratch block
How to clone a sprite
Additional notes for educators
You can �nd the completed project here (http://rpf.io/p/en/dodgeball-get).
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 3/29
Step 2 Character movement
Start by creating a character that can move left and right, and can climb up ladders.
The project contains a backdrop with platforms:
Open the ‘Dodgeball’ Scratch starter project.
Online: open the starter project at rpf.io/dodgeball-on (http://rpf.io/dodgeball-on).
If you have a Scratch account you can make a copy by clicking Remix.
O�ine: download the starter project from rpf.io/p/en/dodgeball-get (http://rpf.io/p/en/dodgeball-get) and then open it using the o�ine editor.
Choose a new sprite as the character the player will control, and add it to your project. It’s best if you
choose a sprite with multiple costumes, so that you can make it look as though it’s walking.
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 4/29
Add code blocks to your character sprite so that the player can use the arrow keys to move the character
around. When the player presses the right arrow, the character should point right, move a few steps, and
change to the next costume:
when clicked
forever
if key right arrow pressed? then
point in direction 90
move 3 steps
next costume
If your sprite doesn’t �t, adjust its size.
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 5/29
Test out your character by clicking the �ag and then holding down the right arrow key. Does your
character move to the right? Does your character look like it is walking?
Add code blocks to the character sprite’s forever loop so that it walks left if the left arrow key is
pressed.
Your code should look like this now:
when clicked
forever
if key right arrow pressed? then
point in direction 90
move 3 steps
next costume
if key left arrow pressed? then
point in direction -90
move 3 steps
next costume
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 6/29
Test your new code to make sure that it works. Does your character turn upside-down when walking to
the left?
If so, you can �x this by clicking on the direction of your character sprite, and then clicking on the left-
right arrow.
Or if you prefer, you can also �x the problem by adding this block to the start of your character’s script:
set rotation style left-right
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 7/29
To climb a pink ladder, your character sprite should move a few steps upwards on the Stage whenever
the up arrow is pressed and the character is touching the correct colour.
Add inside your character’s forever loop to change the character’s y (vertical) position if the up
arrow is pressed and the character is touching the colour pink.
if key up arrow pressed? and touching color ? then
change y by 4
Test your code. Can you make the character climb the pink ladders and get to the end of the level?
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 8/29
Challenge: completing the level
Can you add more code blocks to your character sprite to make the sprite say something if it gets to the green
door?
Challenge!
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 9/29
Step 3 Gravity and jumping
Now you’re going to make your character move more realistically: you’re going to add gravity to your game and give
the character the ability to jump.
In the game, move your character so that it walks o� a platform. Do you see that it can walk into empty
space?
To �x this, add gravity to your game. To do this, create a new variable called gravity.
You can hide this variable from your Stage if you want to.
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 10/29
Add these new code blocks that set gravity to a negative number and use the value of gravity to
repeatedly change your character’s y-coordinate:
when clicked
set gravity to -4
forever
change y by gravity
Click the �ag, and then drag your character to the top of the Stage. What happens? Does the gravity
work as you expect?
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 11/29
Gravity shouldn’t move the character sprite through a platform or a ladder! Add an if block to your code
to only let the gravity work when the character is in mid-air. The gravity code should then look like this:
when clicked
set gravity to -4
forever
if not touching color ? or touching color ? then
change y by gravity
Test the game again to see whether gravity works correctly now. Does your character sprite stop falling
when it touches a platform or a ladder? Can you make the character walk o� the edge of platforms and
fall onto the level below?
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 12/29
Now add code to make your character jump whenever the player presses the space key. One very easy
way to do this is to move your character up a few times:
Because gravity is constantly pushing your character down by 4 pixels, you need to choose a number
greater than 4 in your change y by (4) block. Change the number until you’re happy with the height
the character jumps.
when space key pressed
repeat 10
change y by 4
Test out your code. Notice that the jumping movement isn’t very smooth. To make jumping look
smoother, you need to move your character sprite by smaller and smaller amounts, until it is not rising
any higher.
To do this, create a new variable called jump height. Again, you can hide this variable if you prefer.
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 13/29
Delete the jumping code you added to your character sprite, and add this code instead:
This code moves your character up by 8 pixels, then 7.5 pixels, then 7 pixels, and so on, until it does not
rise any higher. This makes jumping look much smoother.
when space key pressed
set jump height to 8
repeat until jump height = 0
change y by jump height
change jump height by -0.5
Change the value of the jump height variable that is set before the repeat starts. Then test your
game.
Repeat these two steps until you’re happy with how high the character jumps.
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 14/29
Challenge: better jumping
Even if the character is already in mid-air, it jumps whenever the player presses the space bar. You can see this
behaviour if you hold down the space bar.
Can you change the character sprite’s code for jumping so that your character can only jump if it touches a blue
platform?
Challenge!
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 15/29
Step 4 Dodging balls
Your character can move and jump now, so it’s time to add some balls that the character has to avoid.
Create a new ball sprite. You can choose any type of ball you like.
Resize the ball sprite so that the character can jump over it. Try making the character jump over the ball
to test whether the ball is the right size.
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 16/29
Add this code to your ball sprite:
when clicked
hide
forever
wait 3 seconds
create clone of myself
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 17/29
This code creates a new clone of the ball sprite every three seconds. Each new clone moves along the
top platform and then drops.
when I start as a clone
go to x: 160 y: 160
show
repeat 22
change y by -4
repeat 170
change x by -2
turn 6 degrees
repeat 30
change y by -4
delete this clone
Click the �ag to test the game.
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 18/29
Add more code to your ball sprite so that clones of it move across all three platforms.
The code for your ball sprite clones should look like this:
when I start as a clone
go to x: 160 y: 160
show
repeat 22
change y by -4
repeat 170
change x by -2
turn 6 degrees
repeat 30
change y by -4
repeat 180
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 19/29
change x by 2
turn 6 degrees
repeat 30
change y by -4
repeat 170
change x by -2
turn 6 degrees
delete this clone
Now add some code blocks to broadcast (send) a message if your character gets hit by a ball!
Add this code to your ball sprite:
when I start as a clone
forever
if touching Pico walking ? then
broadcast hit
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 20/29
Finally, add code blocks to your character sprite to make it move back to its starting position when it
receives the hit message:
when I receive hit
point in direction 90
go to x: -210 y: -120
Test out your code. Check whether the character moves back to the start after touching a ball.
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 21/29
Challenge: random balls
The balls that your character has to dodge all look the same, and they appear at regular three-second intervals.
Can you add code to your game so that the balls:
Don’t all look the same?
Appear after a random amount of time?
Are a random size?
Challenge!
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 22/29
Step 5 Lasers!
To your game a little harder to complete, you are going to add lasers!
Add a new sprite to your game and call it laser. It should have two costumes: one called ‘on’, and one
called ‘o�’.
Place your new laser sprite between two platforms.
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 23/29
Add code to your laser sprite to make it switch between its two costumes.
If you prefer, you can change the code shown above so that the sprite waits a random amount of time
between costume changes.
when clicked
forever
switch costume to on
wait 2 seconds
switch costume to off
wait 2 seconds
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 24/29
Finally, add code to your laser sprite so that the laser sprite broadcasts a ‘hit’ message when it touches
the character sprite.
This is the code you should add:
You don’t need to add any extra code to your characters sprite, because the character sprite already
knows what to do when it receives the broadcast 'hit'!
when clicked
forever
if touching Pico walking ? then
broadcast hit
Test out your game to see if you can move the character past the laser. If the laser is too easy or too hard
to avoid, change the wait times in the code for the laser sprite.
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 25/29
Challenge: more obstacles
If you think your game is still too easy, you can add more obstacles to it. The obstacles can be anything you like!
Here are some ideas:
A dangerous butter�y
Platforms that appear and disappear
Falling tennis balls that must be avoided
You could even design another backdrop to create the next level. Then add code so that, when your character
reaches the green door, the game switches to the new background:
if touching color ? then
switch backdrop to next backdrop
go to x: -210 y: -120
wait 1 seconds
Challenge!
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 26/29
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 27/29
Challenge: improved gravity
There’s one other small bug in your game: gravity doesn’t pull the character sprite downwards if any part of the
sprite is touching a blue platform. So even if the sprites head touches a platform, the sprite doesn’t fall! You can
test this yourself: make your character climb most of the way up a ladder, and then move the character sideways
beneath a platform:
To �x the bug, you �rst need to give your character sprite new trousers that have a di�erent colour (on allcostumes).
Then replace this code block:
with this code block:
To make sure you’ve �xed the bug, test the game after you’ve made these changes!
touching color ?
color is touching ?
Challenge!
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 28/29
Challenge: more lives
Right now, your character goes back to its starting position when it gets hit. Can you also give the character
sprite three lives, and make it lose one life when it gets hit? Here’s how your game could work:
The game starts with three lives for the character
Whenever the character gets hit, it loses one life and moves back to the start
If there are no lives left, the game ends
Challenge!
26/05/2020 Dodgeball | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/dodgeball/print 29/29
Step 6 What next?
Have a go at our Brain game (https://projects.raspberrypi.org/en/projects/brain-game?utm_source=pathway&utm_medium=whatnext&utm_campaign=projects) project, in which you can create your own maths quiz.
Published by Raspberry Pi Foundation (https://www.raspberrypi.org) under a Creative Commonslicense (https://creativecommons.org/licenses/by-sa/4.0/).
View project & license on GitHub (https://github.com/RaspberryPiLearning/dodgeball)
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 1/20
Projects
CATS!
Create a game in which you guide cats to safety and
stop them from falling into holes
Step 1 Introduction
In this project, you will create a game in which you need to guide cats to safety and not let any of them fall through
the gaps!
What you will make
What you will learn
How to use a forever loop to constantly generate moving cats
How to use a repeat until loop to ensure your cats follow a line
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 2/20
What you will need
Hardware
A computer capable of running Scratch 3
Software
Scratch 3 (either online (http://rpf.io/scratchon) or o�ine (http://rpf.io/scratcho�))
Downloads
O�ine starter project (http://rpf.io/p/en/cats-go)
Additional notes for educators
You can �nd the completed project here (http://rpf.io/p/en/cats-get).
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 3/20
Step 2 Draw lines
Open the ‘CATS!’ Scratch starter project.
Online: open the starter project at rpf.io/cats-on (http://rpf.io/cats-on).
If you have a Scratch account you can make a copy by clicking Remix.
O�ine: open the starter project (http://rpf.io/p/en/cats-go) in the o�ine editor. If you need to
download and install the Scratch o�ine editor, you can �nd it at rpf.io/scratcho� (http://rpf.io/scratcho�).
Add the Pen extension to your project.
Click on the sprite called ‘Pen’, and add code to set the pen colour to the same blue as the obstacles on
the Stage.
To select a colour, click on the colour square in the set pen color block to make your mouse cursor
turn into a pipette, and then click on the correct colour on the Stage.
when clicked
set pen color to
erase all
set pen size to 5
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 4/20
Add some more code to make the sprite follow the mouse pointer. Test your program to check that the
code works.
forever
go to mouse pointer
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 5/20
Add some code to tell the sprite to draw a line on the Stage if the mouse button is pressed down.
This is what your code should look like:
when clicked
set pen color to
erase all
set pen size to 5
forever
go to mouse pointer
if mouse down? then
pen down
else
pen up
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 6/20
You probably see that a blue dot always appears in the top right-hand corner of the Stage (it’s circled in the image
above). This is because, when you click the green �ag to start the game, you press the mouse down, and so the
pen immediately starts drawing.
Test your code. You should be able to click and drag with the mouse to draw a blue line on the Stage.
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 7/20
To stop this from happening, add a pen up block at the start of the script, and a wait one second
block above the forever block.
when clicked
pen up
set pen color to
erase all
set pen size to 5
wait 1 seconds
forever
go to mouse pointer
if mouse down? then
pen down
else
pen up
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 8/20
Step 3 Clone cats
You want a never-ending stream of cats that the player has to guide along the path to the exit.
If you run the program now, nothing happens on the Stage. To check that a new Cat sprite clone is created every
three seconds, make each clone appear and fall out of the sky.
Click on the sprite called ‘Cat’, and add some code to hide the sprite, and also to clone it every three
seconds.
when clicked
hide
forever
create clone of myself
wait 3 seconds
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 9/20
When you click the green �ag, you should see a new cat fall from the top of the Stage every three seconds. Every
cat should land in a big pile of overlapping cats on the blue �oor at the bottom.
Add code to tell the sprite that when it starts as a clone, it should show itself and fall until it
touches the blue �oor that is drawn on the Stage.
This is what your code should look like:
when I start as a clone
show
repeat until touching color ?
change y by -2
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 10/20
Step 4 Make the cats move
Once a cat reaches the �oor, it should step slowly to the right.
If you draw a bridge across the gap so that the cats can get all the way to the right side of the Stage, you can see
that they end up getting stuck walking into the right wall.
Add code to the when I start as a clone section to make the cat sprite move ten steps, and
switch between the sprite’s two costumes every 0.1 seconds to make the cat look like it’s walking.
This is what your code should look like:
when I start as a clone
show
forever
move 10 steps
repeat until touching color ?
change y by -2
next costume
wait 0.1 seconds
Press the green �ag and check that the cats now move along the blue platform at the bottom.
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 11/20
Remove the forever loop, and instead add a di�erent loop to make the cats only walk until they reach
an edge. When a cat reaches the edge of the Stage, it should disappear.
when I start as a clone
show
repeat until touching edge ?
move 10 steps
repeat until touching color ?
change y by -2
next costume
wait 0.1 seconds
delete this clone
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 12/20
You may notice that, if the cats fall into the hole, they don’t disappear but instead get stuck at the bottom. This is
because they keep trying to fall downwards.
This is the part of the code that tells the cat to keep falling until it touches blue:
However, in the hole, the cat can never reach blue, so it is stuck forever.
Press the green �ag and check that the cats disappear when they reach the edge of the Stage.
repeat until touching color ?
Add more blocks to this loop so that it repeats until the cat sprite is touching blue or touching the
edge. This way, the sprite stops trying to fall if it reaches the edge of the Stage.
repeat until touching color ? or touching edge ?
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 13/20
Step 5 Stick to the lines
You might notice that, if you draw a low bridge between the two platforms, or a line that slopes upwards, the cats
end up walking through the platform rather than on top of it!
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 14/20
In the code for the cat sprite, add another loop before the next costume block. This time, the loop
should tell the cat to move upwards by 2 until it is not touching blue.
This is what your code should look like:
when I start as a clone
show
repeat until touching edge ?
move 10 steps
repeat until touching color ?
change y by -2
repeat until not touching color ?
change y by 2
next costume
wait 0.1 seconds
delete this clone
Click the green �ag and try drawing a line that slopes upwards. Check that your cat follows this line.
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 15/20
Step 6 Get to safety
The object of the game is to guide the cats to safety by creating a path so they can reach the door. Create a score
variable to keep track of how many cats reach the door.
Create a variable called score.
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 16/20
Add code to your cat sprite to add 1 to the score each time a cat reaches the door. Also set score to 0
when the flag is clicked at the start of the game.
This is what your code should look like:
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 17/20
when I start as a clone
show
repeat until touching edge ?
move 10 steps
repeat until touching color ?
change y by -2
repeat until not touching color ?
change y by 2
next costume
wait 0.1 seconds
if touching Door ? then
change score by 1
delete this clone
when clicked
set score to 0
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 18/20
Add some more code so that, when a cat sprite reaches the door, the cat makes a ‘meow’ sound and
then disappears.
start sound meow
delete this clone
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 19/20
Challenge: more obstacles
At the moment, the game is rather easy to win. Can you think of ideas to you make your game harder?
Add more backgrounds with di�erent platform designs.
Move the location of the door depending on which background is displayed.
Add more sprites as moving obstacles. Perhaps you could have roaming dogs or rotating spikes the cats
need to avoid?
Only allow the player to use a limited amount of “ink” to draw lines in the game. You can keep track of how
much “ink” is used by creating a timer variable that records how long the mouse is held down.
Create a sprite to show the player how much ink is left.
Challenge!
26/05/2020 CATS! | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/cats/print 20/20
Step 7 What next?
Try the Flower generator (https://projects.raspberrypi.org/en/projects/�ower-generator?utm_source=pathway&utm_medium=whatnext&utm_campaign=projects) project, where you will use custom blocks to create
�ower patterns.
Published by Raspberry Pi Foundation (https://www.raspberrypi.org) under a Creative Commonslicense (https://creativecommons.org/licenses/by-sa/4.0/).
View project & license on GitHub (https://github.com/RaspberryPiLearning/cats)
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 1/20
Projects
Flappy parrot
Create a game in which you guide a parrot past
moving obstacles
Step 1 Introduction
Create a game in which you have to guide a parrot past scrolling pipes to score points.
What you will make
You will press the space bar to make the parrot �ap its wings, and score one point for every pipe that you manage to
get the parrot past.
What you will need
Hardware
A computer capable of running Scratch 3
Software
Scratch 3 (either online (https://rpf.io/scratchon) or o�ine (https://rpf.io/scratcho�))
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 2/20
What you will learn
How to create sprites using Vector mode
How to use sounds
How to detect collisions
How to control a sprite using the keyboard
Additional notes for educators
You can �nd the completed project here (https://rpf.io/p/en/�appy-parrot-get).
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 3/20
Step 2 Add the pipes
First, create the pipes.
The ‘Pipes’ sprite should be a pair of pipes with a gap in the middle. By moving the sprite up or down, you can put
the gap in a di�erent place.
This picture shows an example of how the pipes could be positioned. The parts of the sprite outside the Stage are
normally hidden, you only see then when you drag the sprite:
You can’t draw a sprite as big as the pipes need to be, but you can increase the size at which the sprite shows on
the Stage.
Open a new empty Scratch project.
Add a backdrop with an outdoor landscape. ‘Blue Sky’ is a good choice.
Create a new sprite and name it ‘Pipes’.
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 4/20
Add code to make the sprite bigger.
This makes it’s easier to see how big the pipes should be.
when clicked
set size to 200 %
Draw a rectangle for the top pipe as shown here:
Fill the pipe with a colour you like.
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 5/20
Create a duplicate of the pipe by selecting it and then clicking on Copy and Paste.
Drag the copy of the pipe to the bottom of the screen so that the copy is in line with the other pipe.
There needs to be a gap between the two pipes.
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 6/20
Challenge: make better pipes
Can you make your pipes look better?
Shade your pipes with a left-to-right gradient.
Add extra rectangles to the ends of the pipes:
Challenge!
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 7/20
Step 3 Make the pipes move
Next you’re going to make the pipes move across the screen to create an obstacle course.
First make the pipes appear by adding code to the Pipes sprite so that, when the green flag is
clicked, the sprite forever creates a clone of itself every two seconds.
Tip: clones are just copies of a sprite, and they are really useful for creating games.
when clicked
set size to 200 %
hide
forever
create clone of myself
wait 2 seconds
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 8/20
Now you should have lots of pipes, but their gaps are always in the same place.
You can add some variety by using a random number for the Pipes sprite’s y position.
Next make the pipes move by adding code so that, when a clone starts, the clone appears on the
right side of the Stage and glides across to the left.
Tip: you can stop the pipes scrolling by clicking the red stop button next to the green �ag.
when I start as a clone
show
go to x: 240 y: 0
glide 4 secs to x: -240 y: 0
delete this clone
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 9/20
Modify your sprite’s code so that each sprite clone picks a random number from -80 to 80 and
glides to that y position:
when I start as a clone
show
go to x: 240 y: pick random -80 to 80
glide 4 secs to x: -240 y: y position
delete this clone
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 10/20
Step 4 Make Flappy fall
Now add a sprite called Flappy and create code it so Flappy falls down the Stage. In the next step, you will add the
code to make Flappy �y when you press a key.
Flappy needs to be smaller.
When the game starts, Flappy needs to be just left of the centre of the Stage, at coordinates -50, 0.
Add a new sprite that has two costumes, for ‘wings up’ and ‘wings down’, and name it Flappy.
The parrot sprite is a good choice.
Add code to set Flappy's size to 25% when the green flag is clicked.
when clicked
set size to 25 %
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 11/20
Add code to make Flappy go to the x and y starting position of x: -50 and y: 0.
when clicked
set size to 25 %
go to x: -50 y: 0
Now make Flappy keep falling down the Stage by forever changing the sprite's y position
by -3.
when clicked
set size to 25 %
go to x: -50 y: 0
forever
change y by -3
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 Stage, the sprite should fall again.
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 12/20
Step 5 Make Flappy �y
Now you will make Flappy �ap upwards when you press the space bar. When you play the game, you have to time
your taps to get Flappy through the gaps in the pipes.
Make Flappy �y upwards when you tap the space bar.
Now you need to get Flappy’s wings �apping!
When the space key is pressed, Flappy should move upwards by changing its y coordinate
by a small amount, for example 6.
Flappy �ies upwards by repeating this movement 10 times.
Add this code to your Flappy sprite:
when space key pressed
repeat 10
change y by 6
Click on the Costumes tab, and name Flappy’s costumes ‘wings up’ and ‘wings down’.
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 13/20
Can you make Flappy’s costume change to wings down when you press space, and then change it back
to wings up halfway through the upward movement?
Your code should look like this:
when space key pressed
switch costume to wings down
repeat 5
change y by 6
switch costume to wings up
repeat 5
change y by 6
Test your code. As you see, at the moment nothing happens if you let Flappy hit a pipe.
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 14/20
Step 6 Detect collisions
To make the game a challenge, the player needs to guide Flappy through the gaps without letting the parrot touch
the pipes or the edges of the Stage. You need to add some blocks to detect when Flappy hits something.
This is called collision detection.
A wait until block is necessart to check whether Flappy is touching the pipes or touching the edge.
Next, update the code so that the game stops when Flappy hits a pipe.
Import a sound from the library that you want to play when Flappy collides with something. The ‘screech’
sound is a good choice.
Add a new when green flag clicked block to the ‘Flappy’ sprite, and also add the following code:
when clicked
wait until touching Pipes ? or touching edge ?
start sound screech
Test your code. If Flappy touches a pipe, the ‘screech’ sound should play.
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 15/20
Add the following code to stop the game after a collision is detected:
The broadcast block tells other sprites that the game is over.
The stop block stops other Flappy scripts that are running so that Flappy stops falling after a collision.
when clicked
wait until touching Pipes ? or touching edge ?
start sound screech
say Game Over!
broadcast Game Over
stop other scripts in sprite
Finally, add the following code to the Pipes sprite so that pipes stop appearing when the sprite
receives Game Over.
when I receive Game Over
stop other scripts in sprite
Test your game and see how long you can play before it’s ‘Game over’!
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 16/20
Step 7 Add a score
The player should score a point every time Flappy makes it through a gap between pipes.
Each ‘Pipes’ sprite clone should wait until Flappy has �own past and then increase the score.
Make a new variable for all sprites and call it score.
First, set score to 0 when the game begins:
when clicked
set score to 0
set size to 200 %
hide
forever
create clone of myself
wait 2 seconds
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 17/20
Then add the following code to the Pipes sprite:
when I start as a clone
wait until
Add more code so that, when Flappy’s x position is greater than the pipe clone’s x position, the score
increases by 1 and a sound of your choice plays.
You could use the ‘pop’ sound if you want, or add a sound from the library, for example ‘bird’.
Your code should look like this:
when I start as a clone
wait until x position of Flappy > x position
change score by 1
start sound pop
Test your code and make sure you score a point every time Flappy gets through a gap between pipes.
Check whether the score is set to 0 when you start a new game.
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 18/20
Challenge: adjust the di�culty
Is the game too hard or too easy for you? How many ways can you �nd to change the di�culty?
Adjust the game until you are happy with its di�culty!
Challenge!
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 19/20
Challenge: add a high score
Can you add a high score to the game so that, in addition to keeping track of score for the current round, it keeps
track of the highest score you’ve ever reached?
Challenge!
26/05/2020 Flappy parrot | Raspberry Pi Projects
https://projects.raspberrypi.org/en/projects/flappy-parrot/print 20/20
Step 8 What next?
Try the Binary hero (https://projects.raspberrypi.org/en/projects/binary-hero?utm_source=pathway&utm_medium=whatnext&utm_campaign=projects) project, where you will make a game in which you play the
notes of a song as they scroll down the Stage.
The notes will fall from above, and you will have to press keys to “catch” and play the notes.
Published by Raspberry Pi Foundation (https://www.raspberrypi.org) under a Creative Commonslicense (https://creativecommons.org/licenses/by-sa/4.0/).
View project & license on GitHub (https://github.com/RaspberryPiLearning/�appy-parrot)