Week 25 · Unit 10: Be a game developer · 3 lessons
3
Plan a boat race
Computing 3: Unit 10, pp. 147–160
GoalPlan a two-sprite game with algorithms for each sub-task, then check that the program matches the plan.
New words
plan · to decide what you will do before you startevaluate · to check how well something works, compared with the plancollision bug · a bug where a sprite goes through something it should not
Explanation
Before we make a game, we plan it. We choose a backdrop and the sprites. We decide what each sprite does when the game starts, when a key is pressed and when it is clicked. Then we write an algorithm for each sub-task. Only then do we build the program in Scratch. We test it and debug it. At the end we evaluate it: does the program match the algorithms? Were the algorithms good? In real games, testers also look for collision bugs, where a sprite goes through a wall that it should not.
Worked examples
Sprite
Starts when
What it does
Blue boat
green flag
go to x: −200, y: 50
Blue boat
right arrow key
change x by 30
Red boat
green flag
go to x: −200, y: −50
Red boat
D key
change x by 30
This is the plan for a two-player boat race. Each boat has two sub-tasks. Both boats move 30 steps for each key press, so the race is fair.
Presses
Blue boat x
0
−200
5
−50
10
100
13
190
Test the plan with numbers. The finish line is at x: 190. A boat needs 13 presses, because −200 + 13 × 30 = 190. After 5 presses of the right arrow, the blue boat is at −200 + 150 = −50, and the red boat is still at x: −200.
The plan says
The program does
Match?
blue boat: change x by 30
change x by (30)
yes
red boat: change x by 30
change x by (20)
no
Now evaluate. We compare the program with the plan, one line at a time. One line does not match, so we debug it. We also ask: is the game fair, and is it fun?
Class activity
Design your game (in a group): choose a backdrop and two sprites and draw them on paper. Write a plan table like the one in the examples: sprite, starts when, what it does. Give each sprite at least two sub-tasks. Trade plans with another group. They act out your game on the floor: do they get the same result that you planned? Then evaluate: what would make the game fairer or more fun?
Practice
1
Name three events that can start a sub-task in a Scratch game.
The green flag is clicked, a key is pressed, and the sprite is clicked.
2
The blue boat starts at x: −200 and moves 30 steps for each press. Where is it after 6 presses?
−200 + 6 × 30 = −200 + 180 = −20.
3
The plan says both boats move 30 for each press. What is the bug in the red boat’s program, and why is the race unfair?
The red boat changes x by 3, not 30. It moves much less than the blue boat, so the race is not fair.
4
After you build your game, which two things do you compare to evaluate it?
The finished program and the algorithms, to see if they match.