- Learnt28 min · remember where you were, and sliding
- Basic24 min · movement worth keeping
- Challenge 1–327 min · diagonals, sizes, and tunnelling
- Extrabonus · facing the right way
Review — last lesson 5 min
touching color [ ]?asks whether the sprite stands on a colour.- Move, ask, undo — and undo exactly what you moved.
- Walls must be one flat colour; the sprite must fit the corridor.
Quick-fire
Your mouse has four if blocks, each with its own undo. That is eight blocks doing one job. What would you rather write?
Reveal the answer
Write down where you were before the move, and go back there if it was a wall. One shape, any direction — including directions you have not thought of yet.
Today’s Topic 3 min
old xandold y— remembering the last safe place- Checking x and y separately, so you slide instead of sticking
- Why diagonal movement is faster, with the measurement
- Tunnelling: when a step is bigger than a wall is thick
Learning outcome
By the end of this lesson you will be able to:
- Write one wall check that works for every direction.
- Make a sprite slide along a wall rather than stop against it.
- Predict, and then measure, three ways collision goes wrong.
Learnt — a better shape 28 min
1 · Remember where you were
Rather than a matching undo for every direction, record the position before moving and restore it if the move was illegal:
set [old x v] to (x position)
set [old y v] to (y position)
change x by (4)
if <touching color [#1F7A8C]?> then
go to x: (old x) y: (old y)
end
How to use this: Click the green flag. Watch the old x and old y boxes hold the last safe position.
2 · Sliding along a wall
Press up and right together in a corridor that only goes up, and a single combined check stops you dead — both moves are undone because one of them failed. Judge x and y separately and the successful one still happens:
if <key (right arrow v) pressed?> then
change x by (4)
if <touching color [#1F7A8C]?> then
change x by (-4)
end
end
if <key (up arrow v) pressed?> then
change y by (4)
if <touching color [#1F7A8C]?> then
change y by (-4)
end
end
How to use this: Click the green flag and hold two arrow keys at once against a wall.
3 · What the corridor is made of
Three numbers decide whether a maze is playable at all, and they have to agree:
- the corridor width — about 40 pixels here
- the sprite’s width — which is its size as a percentage of its costume
- the step size — how far it moves each time round the loop
Too wide a sprite and it cannot move. Too big a step and it goes straight through. Challenges 2 and 3 measure both.
Basic — movement worth keeping 24 min
Open last lesson’s maze. You are rebuilding the driving properly.
Step 1 — rotation style
- Add
set rotation style [left-right v]under the green flag. - Now
point in direction (-90)turns the mouse round without turning it over.
Step 2 — face where you go
- In the right-arrow branch, add
point in direction (90)before the move. - In the left-arrow branch,
point in direction (-90). - Leave up and down alone — a mouse that points upwards looks odd.
Step 3 — separate checks
- Make sure each direction has its own
ifwith its own check and undo, rather than one check at the end. - Test by holding two keys into a corner. You should slide, not stick.
Step 4 — animate the walk
- Add
next costumeat the top of the forever loop. - If it flickers too fast, put the costume change inside the movement branches instead.
Step 5 — the cheese
- Add the cheese to the far corner. It does nothing yet — that is next lesson.
How to use this: Click the green flag and drive. The mouse faces its direction and slides along walls.
The mouse is upside down when it goes left.
The rotation style is “all around”. Set it to left-right under the green flag.
It sticks in corners instead of sliding.
You have one wall check after all four moves rather than one inside each. Separate them.
It vibrates when I hold a key against a wall.
That is normal and invisible at this speed — it moves in and is pushed back out every frame. If it bothers you, move the costume change out of the loop.
Holding two keys moves it diagonally and it feels too fast.
It is too fast, by about 41%. That is Challenge 1, and there is a real fix.
Diagonals are cheating
Measure it rather than arguing about it.
- Forty steps to the right, in the open, and record the distance.
- Forty steps right-and-up, and record that distance.
- Compare the two numbers.
How to use this: Click the green flag and watch the two distance boxes fill in.
Teacher reveal — where 226 comes from, and how to fix it
Each diagonal step moves 4 across and 4 up, so the actual distance travelled is the long side of a square with sides of 4 — about 5.66. Forty of those is 226.
if <<key (up arrow v) pressed?> and <key (right arrow v) pressed?>> then
set [step v] to (3)
else
set [step v] to (4)
end
The usual fix is to shrink the step when two keys are down. 4 ÷ 1.41 is about 2.8, so 3 is close enough for a game — and noticing that “close enough” is allowed is part of the lesson.
How small is small enough?
Try the same twenty steps at three different sizes and record what happens.
- 80%, then 55%, then 30%.
- The same corridor and the same twenty presses each time.
- A steps-taken counter, reset before each attempt.
How to use this: Click the green flag and watch three attempts at three sizes, one after another.
Teacher note
The jump from “0 steps” to “20 steps” is sudden rather than gradual, which surprises pupils who expect a big sprite to be merely slower. It is worth saying plainly: this is not a difficulty setting, it is a yes-or-no. Either the sprite fits or the game is unplayable.
Tunnelling
Make the mouse so fast that the wall stops working — then explain why the wall check is not at fault.
- A run with a step of 4, and where it ends up.
- A run with a step big enough to clear a whole wall, and where that ends up.
- A bump counter for both.
How to use this: Click the green flag and watch two runs: a careful one, then a fast one.
Teacher reveal — why the check is innocent
The check only runs between moves. A step of 100 takes the mouse from one side of a 40-pixel wall to the other in a single move, so on every frame the check runs the mouse is standing in a corridor — and the honest answer to “are you in a wall?” is no.
The step size in this demo is chosen, not guessed: from x −180 a step of 100 lands on −80 and then 20, and neither of those overlaps the wall that runs from −40 to 0. A step of 60 lands on 0 and does get caught, which is why this is a measurement rather than a rule of thumb.
The professional fix is a swept check — test several points along the way — which is exactly what breaking a glide into small steps did in Lesson 3-25’s Extra. For Level 3 the rule is enough: never step further than your thinnest wall.
Facing the right way
Make the mouse turn to face the way it is going, all four directions, without ever appearing upside down.
- Left and right flip the mouse.
- Up and down do not rotate it — it is a mouse, not a rocket.
- It never appears belly-up, in any sequence of presses.
How to use this: Click the green flag and watch the mouse turn round four times without flipping over.
Teacher note
A good “going further” answer: the mouse wants left-right, an arrow or a bullet wants all-around, and a score label or a guard drawn face-on wants do-not-rotate. Choosing per sprite is the point — it is a costume decision, not a movement one.
Summary 5 min
old xandold ygive one wall check that works in every direction.- Judge x and y separately and the sprite slides along walls instead of sticking.
- Diagonal movement is about 41% faster. Shrink the step when two keys are down.
- A sprite wider than the corridor cannot move at all — and it looks like a dead script.
- Never step further than your thinnest wall, or you tunnel straight through.
set rotation style [left-right v]stops the sprite going belly-up.
- Sliding
- Moving along a wall you are pressed against, rather than stopping.
- Tunnelling
- Passing through a wall because the step was bigger than the wall.
- Step size
- How far a sprite moves each time round the loop.
- Rotation style
- Whether a sprite turns all the way round, flips, or stays put.
Hand in
Save your maze. Next lesson the cheese starts to matter — and you have to earn it before it will let you win.