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

Break it into parts

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

Each part has its algorithm

Computing 3: Unit 10, pp. 147–160
GoalWrite an algorithm for each sub-task, build each one in Scratch and change one without breaking the other.
New words
hat block · the block that starts a script, such as “when green flag clicked”script · a stack of blocks that runs togetheredit · to change something
Explanation

Every sub-task gets its own algorithm. The picture shows the two scripts of a rabbit game. The first line of the algorithm says what starts it: the green flag, a click or a key. The other lines are the steps. Each line becomes one block. The first block is the hat block. The scripts for different sub-tasks are separate, so we can edit one of them and the others do not change. We test each sub-task on its own: click the green flag for the first one, and click the sprite or press the key for the second one.

Sub-task 1whenclickedgo to x:-150y:-80sayReady?for1secondsSub-task 2whenspacekey pressedchange x by40next costumestart soundBoing
Worked examples
StepInstruction
1When the space key is pressed
2Change x by 40
3Next costume
4Start sound Boing
This is the algorithm for sub-task 2 of the rabbit game. Each of the four lines is one block, and the first line is the hat block.
Beforewhenspacekey pressedchange x by40next costumeAfterwhenspacekey pressedchange x by60next costume
We edit sub-task 2 so the rabbit hops further: 40 becomes 60. Sub-task 1 stays the same. The edit does not change the other script.
What I doWhat should happen
click the green flagthe rabbit goes to x: −150 and says “Ready?”
press space 1 timex is −110, next costume, a Boing sound
press space 3 timesx is −30
Test each sub-task alone. After the green flag the rabbit is at x: −150. Each press of the space key adds 40, so after 3 presses it is at −150 + 40 + 40 + 40 = −30.
Class activity

Paper rabbit (in pairs): draw a long paper strip and mark these places: −150, −110, −70, −30, 10, 50. A coin is the rabbit. Sub-task 1: put the coin on −150. Sub-task 2: each time your partner says “space”, move the coin to the next mark. Say the new x number aloud each time. Then change the hop to 60 and mark −150, −90, −30, 30. What changes? If you have a computer or tablet, build both scripts in Scratch and check your numbers.

Practice
1
Write the algorithm for this sub-task: when the up arrow key is pressed, the sprite moves up by 20 and says “Up!” for 1 second.
2
Turn this algorithm into blocks.
StepInstruction
1When the green flag is clicked
2Go to x: 0, y: 0
3Switch costume to costume1
3
A friend has just changed the number in script B from 40 to 60. Does script A change? Why?
Awhenclickedgo to x:0y:0Bwhenspacekey pressedchange x by60
4
A turtle starts at x: −100. Each press of the space key changes x by 25. Where is it after 3 presses?
Startwhenclickedgo to x:-100y:-60Presswhenspacekey pressedchange x by25