Scratch Programming PDF Tutorial.285
Scratch Programming PDF Tutorial.285
Programming
with Scratch
A step-by-step guide, linked to the English
National Curriculum, for primary school teachers
http://computingchampions.co.uk
@computingchamps
License
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
(CC BY-NC-SA 4.0) license. The license can be viewed at: http://creativecommons.org/licenses/by-nc-
sa/4.0/
Acknowledgements
Parts of this work build on the Scratch Planning examples provided by Phil Bagge at http://code-it.co.uk/ in
accordance with the Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0) license.
The license can be viewed at: http://creativecommons.org/licenses/by-nc/3.0/
• design, write and debug programs that accomplish specific goals, including controlling or simulating
physical systems; solve problems by decomposing them into smaller parts
• use sequence, selection, and repetition in programs; work with variables and various forms of input
and output
• use logical reasoning to explain how some simple algorithms work and to detect and correct errors
in algorithms and programs
Task overview:
• Literacy – speaking and listening; drama; speech punctuation; feelings and emotions of characters
• History – interviewing historical figures
• Geography – conversation between two people from contrasting environments
• PSHCE – discussing feelings towards an issue, such as bullying
• Science – highlighting misconceptions about a particular topic
The Scratch website can be accessed at: http://scratch.mit.edu/ Click on Create to load the coding
environment.
Firstly, delete the cat sprite so Click with the right mouse
we can use something more button on the cat in the Sprites
interesting Area and select Delete
Next, we’re going to choose our Click on the Choose new sprite
characters from library button at the top of
the Sprites Area
You can move the characters
around the screen so they’re Select a sprite from either the
where you want them Animals, Fantasy or People
sections and press OK
It’s now time for our sprites to Click on your first Sprite in the
have a conversation. To do this, Sprites Area. Click on Scripts at
we need a Green flag to start the top of the Block Pallet if the
the program (Script) and a Script Area is not visible
number of instructions in order
At the top of the Block Pallet, Sprite 1
click on Events and drag a
when Green Flag clicked block
into the Script Area (on the right
of the screen)
You will have noticed the Click on your first Sprite and Sprite 1
Sprites talk over each other! To drag two Wait blocks from
rectify this problem, we need to Control into your existing Script
use a Wait instruction
Change the Wait time to two
seconds for each block
Sprite 2
Click on your other Sprite and
repeat the process (note the
location of the Wait blocks
within the script is different for
the two Sprites)
Congratulations! You’ve created your first program in Scratch. You’ve written a program to achieve a
specific goal, sequenced instructions and worked with outputs (the speech displayed on the screen).
You’ve also probably corrected errors in your program, which is known as debugging.
Extension activities
For each of the activities below, feel free to experiment with a range of features to make your program as
engaging as possible.
• Get the Sprite to move towards the character (Hint: have a look in Motion)
• Play a sound instead of using a Say block (Hint: try looking in Sound)
• Change the appearance of the Sprite after they’ve spoken (Hint: use a Next Costume block in Looks)
• Alter the background after one of the characters has spoken (Hint: the required block is in Looks)
• Add a third character (Sprite) to the conversation
In Activity 1, Wait blocks were used to ensure the characters spoke in turn. Using Wait blocks in this way is
quite inefficient and creates lots of extra work if we want to add additional events, such as movement,
sound or further speech. We’re now going to alter each Sprite’s script to use Broadcast messages, which
pass a message to a Sprite to ensure it only undertakes an action when it receives a specified command
(rather than relying on a certain period of time).
When working with children, this can be effectively demonstrated by whispering to a few pupils that when
they hear a specified code word, such as “Dave”, they have to get up and do five star jumps. “Dave” is then
shouted out (i.e. Broadcast) to the class, but only the children given the code word know to act upon it.
• design, write and debug programs that accomplish specific goals, including controlling or simulating
physical systems; solve problems by decomposing them into smaller parts
• use sequence, selection, and repetition in programs; work with variables and various forms of input
and output
• use logical reasoning to explain how some simple algorithms work and to detect and correct errors
in algorithms and programs
Task overview:
Initially, we need to ask the user a question and allow them to Input the answer. Although quizzes can be
produced for any topic, it’s best to initially only ask questions with numerical answers, which minimises
errors relating to spelling or typing.
As with the first task, delete the Click with the right mouse
cat Sprite so we can use button on the cat in the Sprites
something else Area and select Delete
Next, we’re going to choose our Click on the Choose new sprite
character (you only need one!) from library button at the top of
the Sprites Area
The program has to display a Drag an if, then, else block from
different message depending on Control and attach it to your
whether the answer is correct or Script
incorrect. We do this using
Selection
Add some additional questions Add further Ask and if, then,
using the same process else blocks to your Script
containing different questions
and answers
Well done! You’ve made another program in Scratch. This time you’ve also used selection and worked with
both inputs and outputs. We’re now going to add a score to our game using a variable.
A variable is similar to a box. It can contain anything the computer can store, such as numbers or text. Its
contents can be changed, or varied (hence the name variable), and we can find out the contents of the box
at any time.
When the quiz starts, we have Drag the Set, to block from Data
to ensure the score starts at to immediately below the when
zero, rather than continuing from Green Flag clicked block in your
the previous game script (this ensures it’s the first
instruction run)
Good work! You’ve now used a variable to record the score. You have also output the variable to the
screen for the user to see.
Extension activities
For each of the activities below, feel free to experiment with a range of features to make your program as
engaging as possible.
• Adjust the score to decrease when the user gets a question wrong (Hint: change the score by -1)
• Make the character move or dance when an answer is correct (Hint: look in Motion)
• Get the character to include the user’s answer when they speak – e.g. “Well done. The answer was
10” (Hint: you’ll need to use a Join block from Operators)
• Change the background when the score reaches ten (Hint: add an if, then block to check the score
and perform an action if Score = 10)
• design, write and debug programs that accomplish specific goals, including controlling or simulating
physical systems; solve problems by decomposing them into smaller parts
• use sequence, selection, and repetition in programs; work with variables and various forms of input
and output
• use logical reasoning to explain how some simple algorithms work and to detect and correct errors
in algorithms and programs
Task overview:
Our first task is to make our character look like they’re moving as they travel around the maze. We also
need to control the character using the keyboard.
You’ve produced yet another program in Scratch. Within the program, you’ve used repetition to make the
character move across the screen. Repetition has been combined with selection to enable keyboard input,
which alters the location of the sprite output to the screen.
The next stage in producing our game is to create the maze. We also need to program our sprite to perform
a sequence of instructions if it touches the maze wall.
Firstly, we need to draw our maze Click on the Stage icon to the left
of the Sprites Area
Your Sprite is probably too large Click on the Shrink icon above the
to move around the maze, so we Block Palette
need to make it smaller
Click on your Sprite a number of
times until it can comfortably
navigate around your maze
We now need to modify the game Once again, drag a when Green
so the Sprite cannot go through Flag clicked block
the maze’s walls. We can again
use repetition and selection to Place a forever loop after the
check whether the Sprite is when Green Flag clicked block,
touching the wall: followed by an if, then block inside
the loop
If the Sprite is touching the wall,
then we want it to say “Ahhh” for a
period of time, followed by ending
the game Drag a touching color block from
Sensing into the top of the if, then
block
Brilliant! You’ve created a game involving a Sprite interacting with the background, that responds to a
number of inputs (the keyboard and touching a colour). Repetition and selection have again been used,
along with instructions in sequence. You’ll be beginning to see how programs can be built by decomposing
them into smaller parts.
Extension activities
For each of the activities below, feel free to experiment with a range of features to make your program as
engaging as possible.
• Include sound effects when the character moves / hits the wall (Hint: look in Sound)
• Change the Sprite to a ghost if it touches the wall (Hint: you’ll need to add a new Costume)
• Add a score that increases for every second the character avoids touching the side (Hint: combine a
variable for the score with a Wait block)
• Instead of ending the game when the character touches the wall, get it to automatically change
direction (Hint: remove the Stop block and look in Motion)
• Add objects, such as coins, for the character to collect (Hint: add some extra Sprites and Hide them
when touched)
• Include a second level (Hint: you’ll need an end point, of a different colour, in your first maze, which,
when touched, should change to your second maze background)
• design, write and debug programs that accomplish specific goals, including controlling or simulating
physical systems; solve problems by decomposing them into smaller parts
• use sequence, selection, and repetition in programs; work with variables and various forms of input
and output
• use logical reasoning to explain how some simple algorithms work and to detect and correct errors
in algorithms and programs
Task overview:
A leading game manufacturer wants to see how well you can program.
They have asked you to design a game that involves moving a character around obstacles or away from
enemies.
If you wish, you can plan your moving sprite game and start programming immediately. Alternatively, you
can use the example game specification below, or the more detailed instructions overleaf, which break
down the necessary steps for each requirement.
Within school, pupils should be given a planning template and asked to solve the programming challenge
by splitting it into smaller parts. This is known as decomposing. This would typically involve specifying the
required steps, or script, to complete each section of the program.
Basic: A frog has to move across the road from his pond. The frog is controlled using the keyboard.
Butterflies automatically move along the road. If the frog collides with a butterfly, he becomes injured and
the game ends. The frog should always start from his pond at the bottom of the screen.
Intermediate: The frog starts with a score of 100, which should decrease by 5 for every second it takes to
cross the road. The frog starts with three lives. Every time the frog collides with a butterfly, he loses a life.
Once the frog has lost all his lives, the game ends. A "game over" message or screen should be displayed,
along with an appropriate sound.
Advanced: Each butterfly’s speed should increase as the game progresses. Once the frog crosses the road
and reaches a certain point on the other side, he should progress to the next level. He should also get an
extra 100 points.
For each sentence of the Basic example game specification, the required steps are outlined below,
although a similar result can often be achieved using other blocks or scripts
If the frog sprite is touching the Place a forever loop after the
butterfly sprite, then we want when Green Flag clicked block,
the frog to say “Owwww” for a followed by an if, then block
period of time, followed by inside the loop
ending the game
Text: The frog should always Drag your frog Sprite to your
start from his pond at the preferred starting position on
bottom of the screen the Stage (in the pond)
For the Intermediate and Advanced example game specification, step-by-step instructions are not provided.
However, guidance for how to complete each part of the specification is outlined below. As with the Basic
guidance, similar results can often be achieved in a number of ways.
The frog starts with three lives. Every time the frog • Create a variable for the lives
collides with a butterfly, he loses a life • Set the variable to 3 when the game starts
• When the frog touches a butterfly, change the
score by -1
Once the frog has lost all his lives, the game ends • If the lives variable is zero, stop the game
A "game over" message or screen should be When the lives variable reaches zero, either:
displayed
• Say a specific message
• Change the backdrop to a special “game over”
screen
Along with an appropriate sound • Play a sound when the lives variable reaches
zero
Once the frog crosses the road and reaches a • Create a sprite or coloured area at the top of the
certain point on the other side, he should progress screen
to the next level • When the frog touches the area or sprite, the
backdrop should change
• The starting position of both the frog and
butterflies may also need to be altered
He should also get an extra 100 points • When changing the backdrop, change the score
variable by 100
For each of the activities below, feel free to experiment with a range of features to make your program as
engaging as possible.
• Include sound effects when the character moves / hits the enemies (Hint: look in Sound)
• Change the Sprite to something different if it touches a butterfly (Hint: you’ll need to add a new
Costume)
• Get the butterflies to change direction (Hint: use a turn block)
• Make the frog bounce across the stage if he touches the side (Hint: look in Motion)
• Add objects, such as food, for the character to collect (Hint: add some extra Sprites and Hide them
when touched)
• Have different enemies, such as dogs or dinosaurs, on each level (Hint: only show certain sprites
when a certain backdrop is selected)
• Rather than your frog automatically moving forward, program the up and down arrows to move the
sprite forwards and backwards respectively
• Include additional levels
• use two or more programming languages, at least one of which is textual, to solve a variety of
computational problems
• design and develop modular programs that use procedures or functions
• understand simple Boolean logic [for example, AND, OR and NOT] and some of its uses in circuits
and programming
Task overview:
A leading game manufacturer was impressed with your moving sprite game. They now want you to produce
a platform game.
They have asked you to make a one-player game, which involves moving a sprite along various platforms.
The sprite is likely to have to jump over gaps between platforms, in addition to avoiding obstacles and
enemies.
If you wish, you can plan your platform game and start programming immediately. Alternatively, you can
use the example game specification below, or the more detailed instructions overleaf, which break down
the necessary steps for each requirement.
Within school, pupils should be given a planning template and asked to solve the programming challenge
by splitting it into smaller parts. This is known as decomposing. This would typically involve specifying the
required steps, or script, to complete each section of the program. They should also identify sections of
code that can be reused and included within a procedure.
Basic: A sprite has to move along the ground or on platforms. The sprite is controlled using the keyboard.
The sprite should fall to the ground if not on a platform. The sprite should be able to jump onto platforms
and be able to jump a range of different heights. The sprite should start on the left hand side of the screen
and move right along the ground / platforms. The code should be implemented using procedures where
possible.
Intermediate: The sprite should move realistically, including when jumping or falling. The sprite starts with
three lives. The sprite should have to avoid enemies and lose a life if he collides with an enemy. Once the
sprite has lost all his lives, the game ends. A "game over" message or screen should be displayed, along
with an appropriate sound.
Advanced: Once the sprite reaches a certain point on the right hand side of the screen, a "congratulations"
message must appear and he should progress to the next level. The sprite has a set amount of time to
complete the level. Levels should scroll over more than one screen where possible.
For each sentence of the Basic example game specification, the required steps / blocks are outlined below,
although a similar result can often be achieved using other blocks or scripts
Well done! You now have a platform game, which includes the use of procedures and Boolean operators. A
child undertaking a task such as this independently has met some of the coding requirements of the Key
Stage Three Computing National Curriculum.
For the Intermediate and Advanced example game specification, blocks of code are not provided. However,
guidance for how to complete each part of the specification is outlined below. As with the Basic guidance,
similar results can often be achieved in a number of ways.
The sprite starts with three lives. The sprite should • Create a variable for the lives
have to avoid enemies and lose a life if he collides • Set the variable to 3 when the game starts
with an enemy. Once the sprite has lost all his lives, • When the sprite touches an enemy, change the
the game ends score by -1
Once the sprite has lost all his lives, the game ends • If the lives variable is zero, stop the game
A "game over" message or screen should be When the lives variable reaches zero, either:
displayed
• Say a specific message
• Change the backdrop to a special “game over”
screen
Along with an appropriate sound • Play a sound when the lives variable reaches
zero
The sprite has a set amount of time to complete the • Create a variable for the time and reduce it by
level one every second
• When the variable reaches zero, display the
"game over" message / screen
Levels should scroll over more than one screen • Create the adjoining part of the level sprite and
where possible hide it when the game starts
• As the sprite moves right, move both the
background sprite left at the same rate as the
sprite
For each of the activities below, feel free to experiment with a range of features to make your program as
engaging as possible.
• Include sound effects when the character moves / hits the enemies (Hint: look in Sound)
• Change the Sprite to something different if it touches an enemy (Hint: you’ll need to add a new
Costume)
• Allow the player to select their Sprite at the start of the game (Hint: you could use a range of
Costumes or independent sprites)
• Get the enemies to move at random (Hint: look in Operators)
• Add objects, such as food, for the character to collect (Hint: add some extra Sprites and Hide them
when touched)
• Have an end of level boss to get past (Hint: only show certain sprites when certain co-ordinates are
reached)
• Give the sprite ability to fire custard pies or a similar, non-threatening, weapon at enemies (Hint:
add an additional sprite, which moves from the main sprite when a certain key is pressed)
• Include additional levels