AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Debug and build games

Week 25 · Unit 10: Be a game developer · 3 lessons
2

Build a game step by step

Computing 4: Unit 10, pp. 138–151
GoalPlan a game with several sprites, build it one sprite at a time and trace the algorithms for each sprite.
New words
sprite · a character or an object in a Scratch projecthat block · the first block of a script, which says what starts itplan table · a table that says what each sprite does and when
Explanation

A game with several sprites is easier to build in small steps. First, make a plan table. For each sprite, write what starts it, what it does, whether it needs a sub-routine and whether it needs a loop. Then build the first sprite, run the program and test it. Only then add the next sprite and its blocks, and test again. A sprite can start in different ways: the green flag, a key or a click. Each way has its own hat block. If a bug appears, you know it is in the part you added last.

Worked examples
SpriteStarts whenWhat it doesSub-routineLoop
crabclickedsteps sideways, then says “Missed me!”sidestepnone
starfishgreen flaggoes to its place, then twirls and waitstwirlrepeat (5)
A beach game has two sprites. The plan table says what each one does. The crab is clicked by the player. The starfish works by itself after the green flag.
Startwhenclickedgo to x:100y:-100twirlwait1secondsrepeat5Sub-routinedefinetwirlturn ↻90degreeschangecoloreffect by30start soundpop
The starfish. It starts facing 90 (right). Each twirl turns it 90 degrees clockwise, makes its colour change by 30 and plays a pop. There are 5 twirls, so it turns 5 × 90 = 450 degrees. 90 + 450 = 540, and 540 − 360 = 180, so it ends facing 180 (down). The colour effect is 5 × 30 = 150. The program takes 5 × 1 = 5 seconds.
x 240−240y 180−180start123
The crab. The sub-routine sidestep points the crab left, moves it 60 steps and points it right again. The crab starts at x = 120. Each click moves it 60 to the left, so the three clicks in the picture (labelled 1, 2 and 3) take it to 60, 0 and −60.
Class activity

Plan a game (with family): choose a theme, such as a pond, a street or a jungle. Choose three sprites. Draw a plan table with the columns sprite, starts when, what it does, sub-routine and loop. Fill in one row for each sprite. Then act the game out with paper cut-outs on a table: one person is the player, and the other moves the paper sprites as the plan says. Does the plan make a game that is fun to play?

Practice
1
A turtle starts when the green flag is clicked. It goes to x: −150, y: −80. Then it plays a sound, moves 20 steps and waits 0.5 seconds, 4 times in all. Fill in the plan table row.
SpriteStarts whenWhat it doesSub-routineLoop
turtle????
2
A snowflake program: when the green flag is clicked, set size to 100 %, then repeat (4): run spin. The sub-routine spin turns ↻ 45 degrees, changes the size by −10 and waits 0.5 seconds. The sprite starts facing 90. Work out its final direction, size and the time taken.
Startwhenclickedset size to100%spinrepeat4Sub-routinedefinespinturn ↻45degreeschange size by-10wait0.5seconds
3
Name the three ways a script can be started in the lesson’s games. Give an example block for each.
4
Why should you test after adding each new sprite, and not only at the very end?