- Learnt27 min · speed, a state, and a message
- Basic25 min · finish your game
- Challenge 1–327 min · harder, ended, restarted
- Extrabonus · a best score worth beating
Review — where we got to 5 min
Your stall counts, ends, has sounds, and holds things worth different amounts.
- Falling clones, caught or landed.
scoreup on one path,livesdown on the other.- A beetle that costs you, and a sound for every moment.
Quick-fire
Play your game for two minutes without missing. Is minute two any harder than minute one?
Reveal the answer
No. It is exactly the same, for ever. A good game gets harder as you get better at it, and that is the first of today’s three jobs.
Today’s Topic 3 min
- A variable inside a block:
wait (speed) seconds - Keeping a changing number inside sensible limits
switch backdrop to [Stars v]as the two states of a gamebroadcast [start v]from two different places
Learning outcome
By the end of this lesson you will be able to:
- Make a game speed up as the score rises, without it becoming impossible.
- Show a game-over screen that is clearly not the game.
- Start a fresh game from a button, with everything reset.
Learnt — speed, state, and a message 27 min
1 · A number can go inside a block
Your maker stack says wait (1) seconds. That 1 is the reason minute two is no harder than minute one.
Drag the variable (speed) into that white circle instead. The block now waits for whatever the box says, and you can change the box mid-game.
forever
wait (1) seconds
create clone of [myself v]
end
forever
wait (speed) seconds
create clone of [myself v]
end
Making it creep
Every catch takes a little off the wait. Put this on the caught path, next to the score block.
if <touching [Bowl v]?> then
play sound [Pop v]
change [score v] by (1)
if <(speed) > (0.35)> then
change [speed v] by (-0.05)
end
delete this clone
end
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
2 · The backdrop says which state the game is in
Right now your game just stops. The stall looks exactly as it did a second earlier, only nothing is falling. That is a game that has crashed, as far as the player can tell.
Give the ending its own backdrop. In this game the stall closes for the night, so Stars does the job.
when I receive [start v]
wait until <(lives) = (0)>
broadcast [game over v]
switch backdrop to [Stars v]
say (join [Game over! You caught ] (score))
Every muffin listens for that message and clears itself away, clones and all.
when I receive [game over v]
delete this clone
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
3 · One message, two senders
The last piece is a button that starts a new game. It works because of a change you have already half made: nothing starts on the green flag any more. Everything starts on a message.
- On every sprite, swap
when flag clickedforwhen I receive [start v]. - Leave one
when flag clickedin the whole project, on the Bowl. - That one resets the numbers, sets the backdrop, and then
broadcast [start v]. - Play. Nothing should look any different yet.
when flag clicked
set [score v] to (0)
set [lives v] to (3)
set [speed v] to (1)
switch backdrop to [Colorful City v]
broadcast [start v]
Now the button can send the same message, and the whole game starts again with no flag involved.
when I receive [start v]
hide
when I receive [game over v]
go to x: (0) y: (0)
show
when this sprite clicked
hide
set [score v] to (0)
set [lives v] to (3)
set [speed v] to (1)
switch backdrop to [Colorful City v]
broadcast [start v]
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl. Click the bell on the stage to start the next game.
Basic — finish the game 25 min
Open your stall. This is the last time you build on it, so test after every step and save when it works.
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl. Click the bell on the stage to start the next game.
Step 1 — a speed to change
- Make a variable called
speed. Untick it: nobody needs to see it. - Set it to 1 under the flag hat, with the other two.
- Drag
(speed)into the wait in every maker stack. - Play. It should feel exactly as it did before.
Step 2 — make it creep
- Add the limit-and-change pair to the caught path of your everyday muffin.
- Catch fifteen on purpose. It should be noticeably busier.
- Catch fifty. It should be hard, not impossible.
Step 3 — the ending screen
- Add the Stars backdrop to your project.
- Build the referee stack on the Bowl, with the switch and the broadcast.
- Add
when I receive [game over v]anddelete this cloneto every falling sprite. - Lose on purpose. The sky should change and the stall should empty.
Step 4 — start on a message
- Change every
when flag clickedtowhen I receive [start v], except the one on the Bowl. - Make the Bowl’s flag stack the five-block one from the Learnt section.
- Play. Everything should work exactly as before.
Step 5 — the button
- Add a sprite for the button. A Bell, a Button, or your own drawing.
- Build its three stacks.
- Lose, click the button, and play a second game without touching the flag.
Step 6 — save it
- Give the project a real name.
- File → Save to your computer.
- Close the tab, reopen Scratch, load the file and play it once.
After a while everything goes mad and the game freezes.
speed has gone below zero, so a clone is being made every frame. The if <(speed) > (0.35)> then is missing or it is around the wrong block.
Clicking the button starts a game where I have no lives.
The resets are below the broadcast [start v]. The message goes out first, the game starts with the old numbers, and the resets land a moment later.
The button is on screen during the game.
It needs when I receive [start v] and hide. The click stack should hide it too, so it goes the instant it is pressed.
Harder as you win
Make your game speed up as the player does well — and stay playable when they do.
- The first thirty seconds are gentle.
- After twenty catches it is clearly busier.
- However well somebody plays, it never becomes impossible or freezes.
An ending that looks like an ending
When the last life goes, the game should change into something a player can see is over.
- A different backdrop.
- Nothing left falling, and no leftover clones.
- The final score, said or shown.
Teacher note — the leftover clone
The clone still half way down at the moment of the game over is the detail everybody forgets. It carries on falling across the ending screen, and it takes a life after the game is finished. The when I receive [game over v] and delete this clone pair is what fixes it, and it is worth letting them see the bug first.
Play again
Put a button on the ending screen. Clicking it should give a completely fresh game, with no green flag anywhere near it.
- The button only exists on the ending screen.
- A new game starts with a full three lives, a score of zero, and the gentle speed.
- You can play five games in a row without touching the flag.
Teacher reveal — why the flag stack and the button stack are twins
Both do the same five blocks and then broadcast. That duplication is correct at Level 1 and it is worth saying so out loud: there is a way to write those five blocks once and call them from both places, and it is called a My Block. It arrives in Level 2.
A best score worth beating
Add one more number: best. It is the only thing in your project that does not go back to zero.
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl. Click the bell on the stage to start the next game.
bestshows on the Stage all the time.- It only changes when somebody beats it.
- A new record gets a different message from an ordinary game over.
- Starting a new game never resets it.
Teacher notes — the one block that must not be reset
when I receive [start v]
wait until <(lives) = (0)>
broadcast [game over v]
switch backdrop to [Stars v]
if <(score) > (best)> then
set [best v] to (score)
say (join [Rekod baru! ] (score))
else
say (join [Game over! You caught ] (score))
end
The trap is putting set [best v] to (0) in with the other two resets, out of habit. Then the record is whatever the last game scored, which is not a record at all.
Going further: a best score still forgets everything when the project is closed. Scratch has one thing that does not — a cloud variable, which lives on the website and is shared by everyone who plays. It needs a shared project and an account old enough to have earned it.
Summary 4 min
Four lessons, one game, and today it got a shape.
- A variable can sit inside a block.
wait (speed) secondsis what lets a game get harder while you play it. - Any number that keeps changing needs a limit, or it will run away.
- The backdrop is a state. Open stall, closed stall, and the player can see which.
- Starting on a message rather than the flag is what makes a second game possible.
- Difficulty curve
- A game that gets harder as the player gets better. Here it is one shrinking wait.
- Game state
- Which part of the game you are in — playing, or over. The backdrop shows it.
- broadcast
- A message every sprite can hear. Two different senders can send the same one.
- Best score
- A number that survives the reset, because it belongs to the player and not the game.
Next lesson: a new arc, and a project with no score in it at all. You make a music video.