Using Scratch to create a game

Using Scratch to create Games
Scratch1, the free programming language from MIT is a good environment to allow
learners to create games. There are good resources that allow you to learn how to
use Scratch2 in Education.
This paper explores how a game can be created in Scratch, giving instructions and
guidance throughout. In practice much of the game development that will go on will
be by playing with the game as it develops. There is nothing wrong with this but
there needs to be an idea about the game itself before we progress.
Create the idea
The first step is to draft out an idea about the game.
In this game the player will move a character around the screen to collect other characters.
This statement needs unpacking as it is too limited. Most of the learners will have
played games and should be able to describe in more detail about the game.
Questions could be asked such as – Will there be a time limit? How will the character
be controlled? How many of the characters will be on the screen? The statement can
be rewritten.
In this game the player will move a character around the screen to collect other characters. There will be
one main character and one other character on the screen at any one time. The main character will be
controlled by using the arrow keys on the keyboard and the speed at which he moves will be controlled
using the A and Z keys. A score will be kept of how many characters are collected. There will be a time
limit on the game.
This statement could be then expanded into an algorithm
Start the game and timer
Move main Character moves with the arrow keys
If the main character ‘hits’ the other character then:
Move the other character to another position
Add one to the score
If the time is up then stop the game
Prepare the background and
environment
After opening up Scratch you should see
the Fox sprite which is the main default
character. We are going to add two more
sprites – a BYTE hero and a BYTE
character.
Remove the Fox sprite by RIGHT clicking
the mouse and then selecting delete.
1
2
http://scratch.mit.edu/
http://info.scratch.mit.edu/Educators
lead ▪ learn ▪ protect ▪ engage
www.somersetelim.org
Using Scratch to create Games
Adding Sprites
Click on
and navigate to the BYTE hero image. Change the size of this
character by first clicking on
and then on the sprite itself. Make him quite small.
The next sprite is going to have many different appearances or costumes. Again click
on
and select the Exa_plain image. Change his size to be the same as the
BYTE hero.
To add more costumes to this sprite click on the costumes tab and import as many
different costume sprites as you want.
Can you change the names to Hero and BYTE?
Can you move the sprites further apart?
Adding a background
Clicking on Stage and then the Background tab allows you to import different
backdrops. I have chosen brick-wall1 from the outdoor folder.
Making the Hero move
The Scripts tab is where we are going to build the instructions to control the sprites.
Make sure the Hero character is selected.
The command will be selected from these eight colour
coded areas.
Sprites can have several actions happening to them at
once.
would move the Hero 10 spaces. Click on the Green Flag to
run this run.
would move the Hero 10 spaces forward forever
If you think he is travelling too fast change the number.
It would be nice if the Hero would bounce off the walls. His
can be completed by adding this command.
lead ▪ learn ▪ protect ▪ engage
www.somersetelim.org
Using Scratch to create Games
Adding the following group will allow the Hero to
change direction upwards.
Repeat to allow the Hero to change in all 4
directions.
The BYTE Sprite – detect and move
We are now going to program the BYTE character to detect if is touched by the Hero,
change its costume and then move to a new position.
Click on the BYTE sprite and make sure that the Scripts tab is selected.
Construct this block.
Does it make sense to
you?
Click on the Green Flag
– run it and see what
happens.
Scroring
We are going to add a score. In Scratch this can be created by using a variable. Click
on the variable box and then Make a variable and call it Score.
It should appear in the top left hand of the screen – you can move it to wherever you
want.
Change the BYTE block
to look like this.
Check that it works.
lead ▪ learn ▪ protect ▪ engage
www.somersetelim.org
Using Scratch to create Games
Changing Speed
For the Hero sprite add another variable called speed and then change and add these
blocks.
Adding a timer
Add this block to the Hero sprite to time the game.
The full program has been loaded onto the Scratch website and can found at as BYTE
contact:
http://scratch.mit.edu/galleries/view/159292
lead ▪ learn ▪ protect ▪ engage
www.somersetelim.org