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

A complete game

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

Levels that get harder

Computing 6: Unit 10, pp. 134–149
GoalUse a variable and a condition to move a game up a level, and explain why ‘more than’ is safer than ‘equals’.
New words
level · a stage of a game that has its own rules, speed or difficultythreshold · the value, such as a score, at which something changescompound condition · a condition made from two conditions joined by and or orbackdrop · the picture behind the sprites on the stage
Explanation

Many games get harder as the player scores. We keep the level in a variable. When the score reaches a threshold, an if block sets the level to 2, makes the game harder and broadcasts a message. Other objects receive the message. For example, the backdrop can change to a new picture. Scratch has no ‘5 or more’ block, so we write score > 4 rather than score = 5. A score can jump past a value, for example from 4 to 6, and then a test for exactly 5 would never be true. We also check that the level is still 1. Otherwise the level-up blocks would run again after every question.

Quizzersetlevelto2setbiggestto20broadcastlevel 2ifscore>4andlevel=1thenBackdropwhen I receivelevel 2switch backdrop tonight
Worked examples
ScoreLevelBiggest numberBackdrop
0 to 419day
5 or more220night
The game has two levels. The level changes the biggest number that can be asked. The score is the threshold.
Right answersScorescore = 5?score > 4?
12falsefalse
24falsefalse
36falsetrue
48falsetrue
Here the score goes up by 2 for each right answer after starting at 0. A condition that tests exactly 5 never becomes true, but score > 4 does.
Startright answer: add to scorescore > 4 and level = 1?yesnoset level to 2broadcast level 2carry onEnd
This flowchart shows the level check that runs after every right answer. The second part of the condition stops the level-up from running twice.
Class activity

Race to 20 (no computer): you need one die, or number cards 1 to 6, and paper. Each turn a player rolls and adds the number to a running total. Level 1: total below 10, roll one die. Level 2: total 10 or more, roll the die twice and add both numbers. Play with a friend and write the totals in a table. Did a total ever jump over exactly 10? What would happen if the rule said ‘if total = 10’? If you have a computer or tablet, build the level check in Scratch.

Practice
1
In this game the score goes up by 3 for each right answer, starting at 0. What goes wrong with the level check? Write a better condition.
setlevelto2ifscore=10then
2
In level 2 the numbers go up to 20. Write the block that picks the number n for level 2.
3
The designer wants level 3 to begin at 12 points. Write the condition so that level 3 starts only once.
LevelStarts atTime
10 points20 seconds
25 points15 seconds
3?10 seconds
4
Why must the level-up blocks run only once?