- 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 is one touch costing one life.
Quick-fire
You solve your own maze. What is there to do the second time?
Reveal the answer
The same thing, faster. That is a real answer, and it is what a clock is for. Today they also get a second maze they 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 survives from one game to the next.
Learnt — levels, the clock, the ending 27 min
1 · A level is a costume
Your maze is a sprite, and a sprite can have as many costumes as you like. So a second maze is a second costume, and changing level is one block.
- Click the Maze sprite, then the Costumes tab.
- Right-click your maze costume and choose duplicate.
- On the copy, move some walls about. Add a dead end or two.
- Name them
maze-1andmaze-2.
Nothing about touching [Maze v]? changes. It asks about whatever costume 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 counting seconds. Scratch has been timing since the moment it opened, and two blocks in Sensing are all you need.
| 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. A number you can say or compare. |
Tick the box beside (timer) in the palette and it appears on the Stage, counting up, with 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 completely different, and 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 [Menang! ] (join (timer) [ saat.]))
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, so 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 and change the copy.
- Make sure your new maze can actually be finished. Walk it yourself.
Step 2 — the level
- Make a variable
level, set to 1 under the flag. - When the player reaches the star, broadcast
next levelinstead of stopping. - 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 and check 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 every green flag.
Step 5 — the win
- On the star, check the level: if it is 2, broadcast
wininstead ofnext 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.
- Reopen it from the file and 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 and 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 still broadcasts next level whatever the level is. It has to check level first, and broadcast win when there are no more mazes.
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 arrives when the first one is finished, not before.
- It is harder: longer, or with dead ends.
- It can be finished. Prove it by finishing it.
Against the clock
Put a clock on your game so a player can race themselves.
- It starts at zero on every green flag.
- It is visible while you play.
- The time you finished in is part of the ending.
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 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 where it started.
How to use this: Click the green flag, then click the stage once and use the arrow keys to move the Beetle.
bestshows on screen all the time.- It only changes when somebody is faster.
- A new record gets a different message.
- Nothing resets it — not the flag, 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 [Rekod baru! ] (join (timer) [ saat.]))
else
say (join [Menang! ] (join (timer) [ saat.]))
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, and 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 with it, which is what one broadcast is for.
- Scratch has a clock.
reset timerstarts it,(timer)reads it. - Winning and losing are different states, and they should look different.
- Level
- A costume on the maze sprite, plus everything else moving back to a 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 — and the smallest, not the biggest.
Next: Quiz Show — the first project in the course that stops and waits for the player to type an answer.