Module 4 - Build A Game
Module 4 - Build A Game
Build a Game
Game On 2
Game Instructions 3
Exercises 12
Look at Me 13
Exercises 15
I Can’t Hear You! 17
Exercise 20
End of Module Quiz 20
© 2013 Lero
Game On
Design a Game
When you start a programming project it is a good idea to brainstorm away from the computer. Lets start
with a simple computer game. It has 2 characters and a backdrop. Fill in the worksheet to get inspiration
and ideas for your game. Read through the design features carefully to understand how to play the
game before you get it working in Scratch.
1. Description of your Good Guy Character 2. Description of your Bad Guy Character
3. Description of the Backdrop you would like to use for your game
4. Game controls. Describe a special action that you can program for the spacebar key
(E.g. jump, make Sprite disappear).
2 | Scratch Workbook
Game Instructions
1. Start by introducing the 2 characters to the game. It is useful to give your sprites meaningful names.
2. Add a backdrop to the game. Don’t forget to use the ideas from your design on the previous page
Module 4 | 3
3. Select the Good Guy in the sprite selection area.
4 | Scratch Workbook
6. We want something to happen in our game when the Good Guy touches the Bad Guy. To trigger this
we need to use a conditional statement called an “if statement”. As the Good Guy will be impacted
when the collision occurs we will select the Good Guy and add a script for him.
7. Add a conditional statement that causes a reaction when the Good Guy senses the Bad Guy touching
him.
Module 4 | 5
8. Program the behaviour that occurs when the 2 characters touch. See a possible set of behaviours
below.
9. We are going to create a variable to store a value that changes during the game. This variable tracks
the number of lives remaining for the Good Guy.
6 | Scratch Workbook
10. It is time to include the variable in the Good Guy script. When the game is started the number of
lives will be set (initialised) to 5. A conditional statement was used to track every time the Bad Guy
touches the Good Guy. Include a line in this script to decrease the number of lives by one when the
sprites collide.
11. Next program the Good Guy to broadcast a message saying “Game Over” if the number of lives is
equal to zero.
Module 4 | 7
12. Program both sprites to disappear when the Game Over broadcast message is received.
13. Program the backdrop of the stage to change when the Game Over broadcast message is
received.
8 | Scratch Workbook
14. Test out the game by running it until the game is over. Does anything strange happen when the
green flag is clicked again to restart the game? We need to program the Good Guy and Bad Guy to
reappear when the green flag is clicked using the show command. The backdrop needs to be reset
too.
Module 4 | 9
15. You will now change what the Good Guy says when he touches the Bad Guy. He will say something
different or random each time. To do this we will use Lists, which can be found under the Data blocks
category in Scratch.
16. To add to the list, click on the + button at the bottom left of the list. The length will increase by one
each time you add to the list, as shown. Add 4 things the Good Guy will say when touched by the Bad
Guy.
10 | Scratch Workbook
17. Next program the Good Guy sprite to say any of the items on the ‘Things to say’ list, if he is touching
the Bad Guy sprite.
18. If you do not wish the list monitor to be visible on stage you can uncheck the box next to ‘Things to
say’ as shown in the following image.
Module 4 | 11
Exercises
Testing is very important to ensure the game is working correctly. Run the tests outlined below to
test the functionality of your game.
Create version 2 of the game that has the new features below included.
• Enhance the Good Guy functionality by including a costume change when moving in
different directions.
• When the spacebar key is hit make the Good Guy character jump up in the air.
• Alter the random movement of the Bad Guy to make the speed and motion appear as
realistic as possible.
• Develop a scoring system for the game and a way of winning or losing at the end of
the game.
• Introduce levels to the game. The speed and movement of the Bad Guy increases as
the levels progress.
• Add a list of things for the Bad Guy to say if touching the Good Guy.
12 | Scratch Workbook
Look at Me 1
Computer screens are divided up into a grid of small dots called pixels. The word pixel is a derived from
“picture element”. On a black and white screen, each pixel is either black or white.
As computers can only really store numbers there needs to be a way that a computer can understand
how to use a set of numbers stored in a file in a way to display them as an image on the screen.
This shows a picture of a letter “a” that has been magnified so that the dots are visible. When a computer
stores the picture, all that it needs to store is which dots are black and which are white.
The first line consists of one white pixel, then three black, then one white. Thus the first line is
represented as 1, 3, 1.
Note: The first number always relates to the number of white pixels. If the first pixel is black the line will
begin with a zero.
Now that you understand how a basic black and white image is stored think about the amount of data
required to store an image with thousands of different colour combinations.
Module 4 | 13
We are going to examine compression, which decreases the file size of images so they can be stored
and transmitted more efficiently. Compression involves minimizing the size in bytes of a graphics file or
image file. Three common file compression formats used for images are JPEG, GIF and PNG.
JPEG
The Joint Photographic Experts Group works best for:
• Compressing high-quality images such as photographs and detailed artwork,
without sacrificing quality.
• Handling subtle shading and colour blends more efficiently.
GIF
The Graphics Interchange Format works best for…
• Images with solid areas of colour
• Line drawings or logos
• Transparency effect
• Animation
PNG
The Portable Network Graphics works best for…
• Open Source, no licence required by developers, unlike GIFs.
• Widely supported by the Web.
• Will never completely replace GIF, as it does not support animation.
14 | Scratch Workbook
Exercises
Use the instructions below to draw three pictures in the boxes below.
Module 4 | 15
Now that you know how numbers can represent pictures, why not make your own coded
picture for a friend.
• Draw your pictures in the grids and when you have finished, write the code numbers
beside the grids.
• You do not have to use the whole grid. Just leave some blank lines at the bottom if your
picture does not take up the whole grid.
16 | Scratch Workbook
I Can’t Hear You!
• Scratch can read MP3 files and uncompressed WAV, AIF, and AU files.
• Just like images, sounds can also be compressed to make them smaller in size.
MP3 files are an example of this.
• AIF files
• Gold standard of audio files,
• Highest-of-high-quality uncompressed audio that you can save on a disc.
• AIF files sound great, but files are huge.
• AU file
• An audio file typically created on a Sun Microsystems or Unix-based machine.
• Not that common and quite large.
Module 4 | 17
Using Scratch with a sound that you have downloaded to your computer
Here is a sample script that you could use for this sound
18 | Scratch Workbook
Using Scratch to record your own sounds
Module 4 | 19