- 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, which is how a door opens.
- The key broadcasts; the door opens itself.
Quick-fire
Somebody plays your maze very slowly and very carefully. How likely are they to fail?
Reveal the answer
Not at all. Nothing in the maze can go wrong for them. A game needs something that does not wait for you, and 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 route you chose.
- Take a life and send the player home when they are caught.
- Stop one touch counting many times over.
Learnt — patrol, cost, and the double hit 27 min
1 · A patrol is two glides
The guard does not need to be clever. It walks from one end of a corridor 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, and both matter.
- A life goes.
- The player goes back to the start.
Only taking a life is annoying rather than frightening: you carry on from where you were. Only going home is confusing: nothing seems to have happened. Both together is a maze game.
3 · Why one touch costs three lives
Here is the trap, and everybody falls into it. This looks right and 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. If the guard is still touching you on the next pass, you lose another life, and another. The wait (1) seconds is what makes one touch mean 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, and 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 is what leaves the message on screen.Basic — put a guard in it 25 min
Open your maze. Add the guard first and the cost afterwards.
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.
set size to (60) %so it fits a corridor.- Give it the two-glide patrol along a corridor 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: 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. This is worth seeing rather than being told.
Step 5 — game over
- Add the waiting stack that ends the game at zero.
- Lose three lives on purpose and check the message stays on screen.
Step 6 — make it fair
- Play your maze properly, three times.
- Never caught? The guard is too slow, or its corridor is avoidable.
- Always caught? Its corridor 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 instead of inside it.
The guard walks through the walls.
It is meant to — it never checks. Move its two glide points so the whole route 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 belong inside.
A guard worth watching
Put a guard on a route that makes the player stop and think about when to move.
- Its route stays inside one corridor.
- It crosses somewhere the player must pass.
- There is a gap in its round that a patient player can use.
Three lives and a long walk home
Make being caught cost something real.
- Three lives, on screen.
- One touch is one life, however long the guard sits 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, on different routes, is a maze you have to plan.
- Two guards on two different corridors.
- They move at different speeds, so the gaps do not line up.
- Both cost a life, and both send you home.
- The maze is still winnable — you can 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
A patrol can be learned. Add a guard that does not patrol at all: it turns towards you and comes, 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 route.
- It is clearly slower than the player, so it can be escaped.
- Being caught by it costs the same as being caught by anything else.
- It goes back to its own starting spot 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, and 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 is what makes one touch cost one life. - At zero lives the game says so and stops.
- Patrol
- A fixed route a sprite walks for ever. Learnable, and that is the point.
- 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 instead of walking a route.
Next lesson: the finale. A second maze, a clock, and the best time in the class.