- Learnt27 min · levels, the timer, and a win screen
- Basic25 min · finish the game
- Challenge 1–327 min · level two, the clock, the ending
- Extrabonus · the class record
Review — where we got to 5 min
The maze has walls, crystals, a locked door, a guard and three lives.
- Move, check, step back. That is a wall.
- A hidden sprite touches nothing. That is a door.
- A wait after being caught. That makes one touch cost one life.
Quick-fire
You solve your own maze. What is there to do the second time?
Reveal the answer
Do the same thing, faster. That is a real answer. It is what a clock is for. Today you also get a second maze you have never seen.
Today’s Topic 3 min
- A level is a costume:
switch costume to [maze-2 v] - Scratch’s own clock:
reset timerand(timer) - A win screen that is not the same as a game over
- A best time that never resets
Learning outcome
By the end of this lesson you will be able to:
- Change every wall in the game with one block.
- Time a run and show the player how long they took.
- Keep a record that stays from one game to the next.
Learnt — levels, the clock, the ending 27 min
1 · A level is a costume
A level is one stage of a game. Your maze is a sprite. A sprite can have as many costumes as you like. So a second maze is a second costume. Changing level takes one block.
- Click the Maze sprite, then the Costumes tab.
- Right-click your maze costume and choose duplicate.
- On the copy, move some walls. Add a dead end or two.
- Name them
maze-1andmaze-2.
touching [Maze v]? does not change. It checks the costume that is showing. So every wall in the game changes at once.
when I receive [next level v]
change [level v] by (1)
switch costume to [maze-2 v]
How to use this: Click the green flag, then click the stage once and use the arrow keys to move the Beetle.
2 · Scratch already has a clock
You do not need a variable to count seconds. Scratch has timed you since it opened. You only need two blocks in Sensing.
| Block | Category | What it does |
|---|---|---|
reset timer | Sensing | Puts the clock back to zero. Use it at the start of a run. |
(timer) | Sensing | How many seconds since the last reset. You can say it or compare it. |
Tick the box next to (timer) in the palette. It shows on the Stage and counts up. You need no code at all.
How to use this: Click the green flag, then click the stage once and use the arrow keys to move the Beetle.
3 · A win screen
Running out of lives and finishing the game are not the same. They should not look the same. Give the win its own backdrop, its own message, and the time.
when I receive [win v]
switch backdrop to [Theater v]
say (join [You win! ] (join (timer) [ seconds.]))
stop [all v]
How to use this: Click the green flag, then click the stage once and use the arrow keys to move the Beetle.
Basic — finish the game 25 min
Open your maze. This is the last thing you build in Level 1. Save it properly at the end.
How to use this: Click the green flag, then click the stage once and use the arrow keys to move the Beetle.
Step 1 — the second maze
- Duplicate your maze costume. Change the copy.
- Check that you can finish your new maze. Walk it yourself.
Step 2 — the level
- Make a variable
level. Set it to 1 under the flag. - When the player reaches the star, broadcast
next level. Do not stop. - On the maze, receive it. Add one to level and switch costume.
- On the player, receive it. Go back to the start.
Step 3 — everything else goes home
- Crystals: receive
next level, go to a new spot, show. - The door: receive it, go to its new spot, show.
- The guard: receive it, go back to the start of its patrol.
- Play it. Finish level one. Check that nothing is left over.
Step 4 — the clock
- Add
reset timerunder the player’s flag hat. - Tick the timer box in the Sensing palette so it shows.
- Play. It should start at 0 on every green flag.
Step 5 — the win
- On the star, check the level. If it is 2, broadcast
win, notnext level. - Build the win stack with the backdrop, the message and the stop.
- Finish both mazes and read your time.
Step 6 — save it
- Name the project and save it to your computer.
- Open it again from the file. Play it once, all the way through.
- This is the last project of Level 1. Keep it somewhere safe.
Level 2 starts with the crystals already collected.
They hid in level 1. Nothing showed them again. Every collectible needs a when I receive [next level v] with a show.
The game goes to level 3, 4, 5…
The star always broadcasts next level, whatever the level is. It must check level first. When there are no more mazes, it broadcasts win.
My time is a huge number.
reset timer is missing. The clock has been running since Scratch opened.
A second maze
Draw a harder maze and make it the second level.
- It comes when the first one is finished, not before.
- It is harder. It is longer, or it has dead ends.
- You can finish it. Prove it by finishing it.
Against the clock
Put a clock on your game. Then a player can race against their own time.
- It starts at zero on every green flag.
- You can see it while you play.
- The ending shows your finishing time.
Teacher note — the timer nobody has to build
Some pupils will start building a counter out of a variable and a wait (1) seconds loop. It works, it drifts, and it is a good moment: Scratch has a clock already, and knowing what the environment gives you is part of programming.
An ending worth reaching
Finishing both mazes should look nothing like running out of lives. Give the win its own screen.
- A different backdrop from the game and from the game over.
- The time on the screen, in a sentence.
- A way to play again without pressing the flag.
Teacher reveal — two endings, told apart
This is the Muffin Catcher’s ending screen again, and pupils should be told so: a backdrop for the state, a message with the number in it, a button that resets and broadcasts. The only new part is that there are now two different endings, and each one needs its own message.
The class record
Add a best time. It is the only number in your project that does not go back to its start.
How to use this: Click the green flag, then click the stage once and use the arrow keys to move the Beetle.
bestshows on the screen all the time.- It only changes when someone is faster.
- A new record gets a different message.
- Nothing resets it. Not the flag, and not the play-again button.
Teacher notes — the first game problem
when I receive [win v]
if <<(best) = (0)> or <(timer) < (best)>> then
set [best v] to (timer)
say (join [New record! ] (join (timer) [ seconds.]))
else
say (join [You win! ] (join (timer) [ seconds.]))
end
stop [all v]
The first game is the trap. best starts at 0, and nobody is ever faster than 0, so without the first half of that question the record can never be set at all. Pupils who instead start best at 9999 have solved it another way, and theirs is shorter.
Going further: a best time that survives closing the project needs a cloud variable, which lives on the Scratch website and is shared by everybody who plays. That is a real class leaderboard, and it needs a shared project.
Summary 4 min
That is Level 1 finished. The last four lessons made a whole game.
- A level is a costume on the maze sprite. One block changes every wall.
- Everything else has to go home too. One broadcast does that.
- Scratch has a clock.
reset timerstarts it.(timer)reads it. - Winning and losing are not the same. They should look different.
- Level
- A costume on the maze sprite. Everything else goes back to its start.
- timer
- Scratch’s own clock, in Sensing. Reset it, then read it.
- Win screen
- The ending you reach by winning. Not the same as a game over.
- Best time
- The record. The only number that does not reset. It is the smallest, not the biggest.
Next: Quiz Show. It is the first project that stops and waits for the player to type an answer.