- 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. 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. Go back there if it was a wall. One shape works for any direction, even ones 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, and how to measure it.
- 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 instead of stopping against it.
- Predict, then measure, three ways wall checks go wrong.
Learnt — a better shape 28 min
1 · Remember where you were
You do not need an undo for every direction. Save the position before moving. Go back to it if the move hit a wall:
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. One combined check stops you dead. Both moves are undone because one of them failed. Check x and y separately, and the move that works 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 if you can play a maze at all. They have to fit together:
- the corridor width: about 40 pixels here.
- the sprite’s width: 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 will rebuild the movement 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. Do not use 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 steer. The mouse faces the way it goes 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, not one inside each. Separate them.
It vibrates when I hold a key against a wall.
That is normal, and hard to see 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
Do not argue about it. Measure it.
- Take forty steps to the right, in the open. Write down the distance.
- Take forty steps right-and-up. Write down 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. Write down what happens.
- 80%, then 55%, then 30%.
- The same corridor and the same twenty presses each time.
- A steps-taken counter, reset before each try.
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 to blame.
- A run with a step of 4, and where it ends up.
- A run with a step big enough to jump 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, in all four directions. It must never look upside down.
- Left and right flip the mouse.
- Up and down do not rotate it. It is a mouse, not a rocket.
- It never looks belly-up, whatever keys you press.
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 you one wall check for every direction.- Check x and y separately. Then 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. It looks like the script is broken.
- Never step further than your thinnest wall. If you do, 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, instead of 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. You have to earn it before it lets you win.