- 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 and has sounds. Some things in it are worth more than others.
- Falling clones, caught or landed.
scoregoes up on one path.livesgoes down on the other.- A beetle that costs a life, and a sound for every moment.
Quick-fire
Play your game for two minutes without missing. Is minute two harder than minute one?
Reveal the answer
No. It stays the same for ever. A good game gets harder as you get better at it. That is the first of today’s three jobs.
Today’s Topic 3 min
- A variable inside a block:
wait (speed) seconds - Stopping a number from going too far
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 goes up, but never get too hard to play.
- Show a game-over screen that looks nothing like the game.
- Start a new 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. Because of that 1, minute two is no harder than minute one.
Put the variable (speed) in that white hole instead. Now the block waits for the number in the box. You can change the box while you play.
forever
wait (1) seconds
create clone of [myself v]
end
forever
wait (speed) seconds
create clone of [myself v]
end
Making it speed up
Every catch makes the wait a little shorter. 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 the same, but nothing falls. To the player, it looks like the game has crashed.
Give the ending its own backdrop. In this game the stall closes for the night. So use Stars.
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. Then all the clones delete themselves.
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 part is a button that starts a new game. To make it work, nothing starts on the green flag any more. Everything starts on a message.
- On every sprite, change
when flag clickedtowhen I receive [start v]. - Leave one
when flag clickedin the whole project, on the Bowl. - That one resets the numbers and sets the backdrop. Then it does
broadcast [start v]. - Play. Nothing should look 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. The whole game starts again, with no flag.
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. 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 just as it did before.
Step 2 — make it speed up
- Add the if and the change block to the caught path of your plain muffin.
- Catch fifteen on purpose. It should be much 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. The stall should be 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 just as before.
Step 5 — the button
- Add a sprite for the button. It can be a Bell, a Button, or a drawing of your own.
- Build its three stacks.
- Lose and click the button. 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 and open Scratch again. Load the file and play it once.
After a while everything goes wrong and the game freezes.
speed has gone below zero, so a clone is made all the time. 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. The resets come just after.
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 as soon as you press it.
Harder as you win
Make your game speed up as the player does well. It must not get too hard to play.
- The first thirty seconds are slow and easy.
- After twenty catches it is much busier.
- Even a very good player can still play it. It never freezes.
An ending that looks like an ending
When the last life goes, the player should see that the game is over.
- A different backdrop.
- Nothing is still falling, and no clones are left.
- The final score is 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 whole new game, without the green flag.
- The button only shows on the ending screen.
- A new game starts with three lives, a score of zero, and the slow 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 called 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 someone beats it.
- A new best score gets its own message, not the normal 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 [New record! ] (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. Today it got a start, a middle and an end.
- A variable can go inside a block.
wait (speed) secondslets a game get harder while you play it. - A number that keeps changing needs a limit. If not, it goes too far.
- The backdrop shows the state. Is the stall open or closed? The player can see which.
- Start on a message, not the flag. Then you can play a second game.
- Difficulty curve
- A game that gets harder as the player gets better. Here it is one wait that gets shorter.
- 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 is not reset. It is the player’s, not the game’s.
Next lesson: something new, with no score in it at all. You make a music video.