Week 24 · Unit 10: Be a game developer · 3 lessons
1
Break a game into parts
Computing 3: Unit 10, pp. 147–160
GoalBreak a big job, such as making a game, into smaller sub-tasks.
New words
sub-task · a smaller job that is part of a bigger jobdecomposition · breaking a big problem into smaller partsgame developer · a person who designs and builds games
Explanation
A big job is easier when we break it into smaller jobs. A smaller job that is part of a big job is called a sub-task. Breaking a problem into parts is called decomposition. A game developer does this all the time. A game can be split into the part that happens when the game starts and the part that happens when a player clicks a sprite. Each sub-task is easier to follow, to test and to change. Different people can even build different sub-tasks and put them together.
Worked examples
Here is a small kite game. When the green flag is clicked, the kite goes to the bottom of the stage and says “Ready!”. When the kite is clicked, it glides to the top and says “Wheee!”. We split the game into two sub-tasks.
Sub-task 1: the game starts
Sub-task 2: the kite is clicked
1 When the green flag is clicked
1 When this sprite is clicked
2 Go to x: 0, y: −120
2 Glide 2 seconds to x: 0, y: 100
3 Say “Ready!” for 2 seconds
3 Say “Wheee!” for 2 seconds
Each sub-task gets its own algorithm. Sub-task 1 starts with the green flag and sub-task 2 starts when the kite is clicked.
Each algorithm becomes its own script. We can change the words in script 1 and the kite still glides in script 2, because the sub-tasks do not depend on each other.
Class activity
Plan a picnic (in a group): write six jobs on slips of paper: pack the sandwiches, pack the drinks, walk to the park, choose a place to sit, put the blanket down, play a game. Sort the slips into three sub-tasks and give each group a title. Compare with another group: did you sort them the same way? Then act out the kite game. One person is the kite, another says “Green flag!” and the kite goes low and says “Ready!”. Another says “Click!” and the kite rises and says “Wheee!”.
Practice
1
Why is it useful to break a big job into sub-tasks?
Each sub-task is easier to follow, to test and to change, and different people can work on different parts.
2
A game has a snail and a bird. At the start the snail goes to x: −150 and the bird goes to x: 100, y: 80. When the space key is pressed, the snail moves 30 steps and the bird says “Tweet!” for 1 second. Break the game into two sub-tasks.
Sub-task 1: when the game starts (the snail and the bird go to their start places). Sub-task 2: when the space key is pressed (the snail moves 30 steps and the bird says “Tweet!”).
3
Which sub-task does this script belong to: “when the game starts” or “when the sprite is clicked”?
It belongs to “when the sprite is clicked”, because its first block is “when this sprite clicked”.
4
Write the sub-tasks for “getting ready for a swimming lesson” in your own words.
Answers vary. For example: pack the bag (towel, goggles, swimsuit), go to the pool, and get changed. Check that each sub-task is a smaller job.