- Learnt27 min · a patrol, a cost, and the double-hit trap
- Basic25 min · put a guard in your maze
- Challenge 1–327 min · one guard, three lives, two rounds
- Extrabonus · one that follows you
Review — where we got to 5 min
Last lesson the maze got things in it.
- A collectible hides when touched and adds to a number.
- A hidden sprite touches nothing. That is how a door opens.
- The key broadcasts. The door opens itself.
Quick-fire
Someone plays your maze very slowly and carefully. Will they ever fail?
Reveal the answer
No. Nothing in the maze can go wrong for them. A game needs something that does not wait for you. That is what a guard is.
Today’s Topic 3 min
- A patrol: two glides inside a forever
- Being caught:
change [lives v] by (-1)andgo to x: () y: () - Why one touch can cost three lives, and the wait that stops it
- Game over when the lives run out
Learning outcome
By the end of this lesson you will be able to:
- Send a sprite back and forth along a path you chose.
- Take a life and send the player home when they are caught.
- Stop one touch from counting many times.
Learnt — patrol, cost, and the double hit 27 min
1 · A patrol is two glides
A patrol is a walk on the same path, again and again. The guard does not need to be clever. It walks from one end of a path to the other and back, for ever.
when flag clicked
go to x: (150) y: (10)
forever
glide (2) secs to x: (-150) y: (10)
glide (2) secs to x: (150) y: (10)
end
How to use this: Click the green flag, then click the stage once and use the arrow keys to move the Beetle.
2 · What being caught costs
Two things happen. Both matter.
- A life goes.
- The player goes back to the start.
What if you only lose a life? That is not scary. You just carry on from where you were. What if you only go home? That is confusing. Nothing seems to happen. You need both for a maze game.
3 · Why one touch costs three lives
Here is the trap. Everyone falls into it. This looks right, but it is not.
forever
if <touching [Bat v]?> then
change [lives v] by (-1)
go to x: (180) y: (-120)
end
end
forever
if <touching [Bat v]?> then
change [lives v] by (-1)
go to x: (180) y: (-120)
wait (1) seconds
end
end
The loop asks its question about thirty times a second. Is the guard still touching you next time? Then you lose another life, and another. The wait (1) seconds makes one touch cost one life.
How to use this: Click the green flag, then click the stage once and use the arrow keys to move the Beetle.
4 · The ending
You built this in the Muffin Catcher. It is the same three blocks.
when flag clicked
set [lives v] to (3)
wait until <(lives) = (0)>
say [Game over!]
stop [all v]
say [Hello!], not the timed one. The stop leaves the message on the screen.Basic — put a guard in it 25 min
Open your maze. Add the guard first. Add the lives after.
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 guard
- Add a sprite for it. A Bat, a Ladybug, anything.
- Use
set size to (60) %so it fits a path. - Give it the two-glide patrol along a path you pick.
- Play and watch it. It should never go through a wall.
Step 2 — three lives
- Make a variable
livesand show it. set [lives v] to (3)under the player’s flag hat.
Step 3 — being caught
- On the player, add a second stack. It is a forever with a touching if inside.
- Inside the if: take a life, go home, and wait one second.
- Play. Get caught on purpose. Lives should go down by exactly one.
Step 4 — take the wait out, then put it back
- Delete the
wait (1) secondsand play again. - Get caught. Watch all three lives vanish at once.
- Put it back. It is better to see this than to be told.
Step 5 — game over
- Add the waiting stack that ends the game at zero.
- Lose three lives on purpose. Check that the message stays on the screen.
Step 6 — make it fair
- Play your maze properly, three times.
- Never caught? The guard is too slow, or you can go round its path.
- Always caught? Its path is too long, or it is too fast to time.
One touch takes all my lives.
The wait (1) seconds is missing. Or it is outside the if, not inside it.
The guard walks through the walls.
It is meant to. It never checks. Move its two glide points so its whole path is inside one corridor.
I get sent home but the number does not change.
The change [lives v] by (-1) is below the go to x: () y: () and outside the if. Both go inside.
A guard worth watching
Put a guard on a path. The player must stop and think about when to move.
- Its path stays inside one corridor.
- It crosses a place the player must pass.
- There is a gap in its walk that a patient player can use.
Three lives and a long walk home
Make being caught cost something real.
- Three lives, on the screen.
- One touch is one life, however long the guard stays on you.
- Being caught sends you back to the very start.
- At zero, the game says so and stops.
Teacher note — the crystals question
Someone will ask whether being caught should also take your crystals back. Both answers are good games — losing them is harsher, keeping them is kinder — and it is worth ten seconds of class discussion. The code is the same either way: a set [gems v] to (0) in the caught-if, or not.
Two guards, two rounds
One guard is a timing puzzle. Two guards on different paths make a maze you must plan.
- Two guards on two different paths.
- They move at different speeds, so the gaps do not line up.
- Both cost a life. Both send you home.
- You can still win the maze. Prove it by winning.
How to use this: Click the green flag, then click the stage once and use the arrow keys to move the Beetle.
Teacher reveal — one stack per guard, on the player
Each guard needs its own touching-if on the player. Pupils often try to add the second guard to the first if and end up with a maze where only one of them works. Two separate stacks, each with its own wait, is the answer at Level 1 — and the moment somebody asks whether they could say touching bat OR touching ladybug, they have found the Operators block that makes it one stack.
The one that follows you
You can learn a patrol. So add a guard that does not patrol at all. It turns towards you and comes after you, wherever you go.
How to use this: Click the green flag, then click the stage once and use the arrow keys to move the Beetle.
- It always moves towards the player, not along a fixed path.
- It is slower than the player, so you can get away.
- Being caught by it costs the same as being caught by anything else.
- It goes back to its own start when a life is lost.
Teacher notes — two new blocks, one old shape
when flag clicked
go to x: (-150) y: (10)
forever
point towards [Beetle v]
move (1) steps
wait (0.05) seconds
end
point towards [Beetle v] from Motion is the only new block, and it does the whole job. One step at a time with a small wait keeps it slower than the player.
It walks through walls, of course, which makes it frightening. A chaser that respects walls needs it to check touching [Maze v]? and step back like the player does — and then it gets stuck in corners, which is a real problem that real games have. Worth mentioning; not worth solving today.
Going further: (distance to [Beetle v]) from Sensing would let it only wake up when you come close. Nobody has met it yet.
Summary 4 min
The maze can now beat you. It took three small things.
- A patrol is two glides in a forever. The guard never checks a wall.
- Being caught takes a life and sends you home. Both, every time.
- A
wait (1) secondsafter being caught makes one touch cost one life. - At zero lives the game says so and stops.
- Patrol
- A fixed path a sprite walks for ever. You can learn it, and that is the fun.
- Respawn
- Being sent back to the start after being caught.
- Double hit
- One touch counted many times, because the loop keeps asking. A wait fixes it.
- Chaser
- A guard that points towards the player. It does not walk a fixed path.
Next lesson: the finale. A second maze, a clock, and the best time in the class.