Scratch Programming
Scratch Programming
In this module you are going to develop skills to help you work towards your final project,
which will be using Scratch to create a game where a player can look after a virtual pet.
The player of your game will need to feed and play with the pet to make sure it doesn’t
get too hungry or bored!
You will learn how to plan, design, create and test a program before you start to make
your game. Before you can start planning your game, you need to learn some new skills
in Scratch. These skills will be used as part of the final game.
6
6
Introduction
Key terms
Computer programs need to be planned and designed before they are created. This
is usually done following something called the Software Development Cycle. This is Software
a structured sequence of actions that allow you to plan, design, create, test and then Development
improve a computer program. Cycle: a formal
set of processes
It is important that programs are planned first for many reasons, such as:
followed to plan,
• to make it clear what the program has to do design, create and
• to make sure everyone on the team working on it fully understands the requirements test a system.
• to make sure the person (or group of people) who want the game are happy with what Test: to make sure
the game will do. a section of code
From this plan, you can design how the program will work, for example using a flowchart. runs correctly.
This will let you find any problems before you start, and it means you’re not making it up
as you go along!
Once you have created your program you need to test it to make sure it works fully and
that there aren’t any problems. If you have been asked to make a particular program for a
client, they will have a clear idea of what they want. If you cannot deliver the program they
want, you may not get paid for the work you have done – if it doesn’t work, for example.
Programs usually require user interaction using an interface. The interface is the part
Key terms
of the program that allows the user to interact with it. It includes the on-screen buttons,
Interactive: a text, images and so on, that the user can then click, type into and look at.
program that has
both input and
output for the user.
Interface: the
part of a program
that lets the user
input data and that
produces output for
the user.
Input: putting data
into a computer,
for example typing,
clicking buttons.
Output: data being
given from the
computer to the
user, for example An interactive program means that the user is involved in the program and they are able to:
on screen, from • put data into the computer. This is input, for example clicking buttons, typing text and
speakers. numbers. In a computer game, this might be by using a hand-held controller.
Analogue: data • get data from the computer. This is output, for example you can see images and text,
in the real world and hear sound.
(that is not in a
computer).
Stay safe!
You might be
using the ‘Scratch
Internet’ version.
Make sure you stay
safe while online,
and only use the
website you have
been given. Do not
talk to other people
online, or visit other
websites without
Most data that is in the real world (that is not in a computer) is analogue data. This can
the permission of
be any value, represented in any form, for example sound or images. This data must be
your teacher.
converted for a computer to understand it.
Skill 1 P
Detecting user interaction 1: detecting click buttons
A computer game might need the user to press buttons, for example a keypress. In a car
driving game, the car is going to move forward when the up arrow is clicked. The game needs
to know when the up arrow has been clicked by the user so it knows when to move the car.
To do this in Scratch, you will need to click on Events and then drag
.
9
Activity 1.1
Open a new Scratch window.
Right-click on the cat Sprite.
Select ‘Delete’.
Click on the ‘New Sprite’ button.
10
Activity 1.4
Add new blocks so when the down arrow key is pressed the car rotates right 90 degrees.
Test your code works.
Skill 2 P
Detecting user interaction 2: user clicking objects
You can get your user to interact with your game by clicking on objects in the actual
game, for example when the user clicks on the car, the car moves forward.
Start by clicking on the Sprite.
Finally, you can add your instructions for when this Sprite is clicked below this block.
11
Activity 2.1
Add a Sprite to a new Scratch program.
When the Sprite is clicked make the Sprite move forward.
Test your code works.
Tip
Activity 2.2
Change the program from Activity 2.1. When the Sprite is clicked, make the Sprite:
To slow your Sprite
down so you can 1 Move forward 20 steps
see it move, add a 2 Turn left 90 degrees
‘Wait’ block after 3 Move forward 20 steps
each instruction. 4 Turn right 90 degrees
5 Move forward 20 steps
Test your code works.
Skill 3 P
Broadcasting: make a car move when you click on a Sprite
Key term When you add code to a Sprite, you can affect only that Sprite.
Broadcast: sending Broadcasting lets you send out a message to tell another Sprite to do something, for
a message in example move.
Scratch that other
This is how to make a car move ten steps when the ball is clicked.
Sprites can see, and
then react to. First, you need to add a car Sprite and a ball Sprite to your Scratch stage.
12
.
You would then click on the drop-down menu and choose ‘New Message’.
You will need to change the message to make it meaningful. It should describe its
purpose, for example Car Move.
13
Next, you need to choose the correct broadcast message from the drop-down menu.
You can then add your action blocks below it.
Activity 3.1
Open a new Scratch window.
Add two car Sprites.
When the first car is clicked, make the second car move forward.
When the second car is clicked, make the first car move forward.
Test your code works.
Activity 3.2
Open a new Scratch window.
Add a dinosaur Sprite.
Add four other Sprites, one to move the dinosaur forward, one for moving back, one
for turning left, one for turning right.
Add blocks so that when moving forward is clicked it broadcasts a message. When
the dinosaur receives this message it moves forward. Repeat for moving back, and
turning left and right.
Test your code works.
Key term
Skill 4 P
Variable: a space
in memory where Variables
you can store data
temporarily. A variable allows you to store data in a program, for example a number. This data is
stored in the computer’s memory, a bit like putting something in a box. You give the
variable a name so you can remember what it is called, and use it later. You might have
Did you know? lots of variables, so they all need to have names that describe what they are storing.
Variables are a In a game where you are catching stars, you might want to count how many stars have
fundamental part been caught. This would be stored in a variable; it could be named Stars.
of programming, In a game where your spaceship is flying through space, you might want to store the
without them you number of planets it has visited. This would be stored in a variable; it could be named
can’t store any Planets.
data! They are
only temporary
though. To store
data permanently, it
needs saving to a file.
14
Creating a variable
1 To create a variable, first you need to click on Variables.
2 Then you would click on ‘Make a Variable’.
15