- Learnt28 min · water, and a star
- Basic24 min · the level
- Challenge 1–327 min · a checkpoint, a crab, the stomp
- Extrabonus · ship it
Review — the arc so far 5 min
- Gravity changes the speed. The speed changes y. A jump sets the speed.
landpushes out of floors and ceilings.walkundoes moves into walls.- A hitbox costume does the touching, and nobody ever sees it.
Quick-fire
You can climb your level from bottom to top. Why is it not a game yet?
Reveal the answer
You cannot lose and you cannot win. A game needs a way to fail, like the water or a crab. It also needs a moment that says you have finished. You already know how to build both. Today you put them in the level.
Today’s Topic 3 min
- A second rule colour: water
- A
statevariable withplay,wonandover, from Storm Flight - A respawn point (where you come back after losing a life) that a checkpoint can move
- An enemy you can defeat from above
Learning outcome
By the end of this lesson you will be able to:
- Give a level a hazard (something that costs a life), lives and a goal.
- Move the place a player comes back to.
- Use the speed to tell a stomp from walking into an enemy.
Learnt — losing and winning 28 min
1 · A second rule colour
The pit is painted one flat blue, and blue means water. We ask the same question as for the ground, but about a different colour. And the answer does something different:
if <touching color [#2F80ED]?> then
change [lives v] by (-1)
go to x: (-215) y: (-104)
set [y velocity v] to (0)
end
land. Blue costs a life, and Pico goes back to the start.How to use this: Click the green flag. Pico walks off the end of step 2 into the water.
2 · A goal, and a state
Touching the star wins. But the loop still reads the arrow keys. Pico still falls. The loop still checks the water. So the win needs to stop the game. For that we use Storm Flight’s state variable:
forever
if <(state) = [play]> then
land :: custom
if <touching (Star v)?> then
set [state v] to [won]
switch costume to (pico happy v)
say [Level complete!]
end
end
end
land as before. The whole game lives inside if <(state) = [play]> then. So when the state changes, the game just stops.How to use this: Click the green flag. Watch Pico climb to the star on its own.
Basic — the level 24 min
Open your climber from last lesson. Today it becomes a game you can win and lose.
Step 1 — two new variables
- Make
lives(how many tries are left) andstate. Show both monitors. - When the flag is clicked, set
livesto 3 andstatetoplay.
Step 2 — the water bites
- Delete last lesson’s
if <(y position) < (-150)> thencheck. The water does that job now. - After
land, add the water check from Learnt part 1. Pick the blue with the eyedropper. - Inside it, check if
liveshas reached 0. If so, setstatetooverand say so.
Step 3 — the whole game inside one if
- Put an
if <(state) = [play]> theninside the forever. - Drag everything that was in the forever into it.
- Change the star check so it sets
statetowon.
Step 4 — play it both ways
- Win it. Check nothing moves afterwards.
- Then lose on purpose three times. Check the game really ends.
when flag clicked
set rotation style [left-right v]
go to x: (-215) y: (-104)
set [y velocity v] to (0)
set [lives v] to (3)
set [state v] to [play]
forever
if <(state) = [play]> then
if <key (right arrow v) pressed?> then
point in direction (90)
walk (4) :: custom
end
if <key (left arrow v) pressed?> then
point in direction (-90)
walk (-4) :: custom
end
change [y velocity v] by (-1)
change y by (y velocity)
land :: custom
if <<key (space v) pressed?> and <(on ground) = (1)>> then
set [y velocity v] to (12)
end
if <touching color [#2F80ED]?> then
change [lives v] by (-1)
go to x: (-215) y: (-104)
set [y velocity v] to (0)
if <(lives) = (0)> then
set [state v] to [over]
say [Out of lives.]
end
end
if <touching (Star v)?> then
set [state v] to [won]
switch costume to (pico happy v)
say [Level complete!]
end
end
end
walk and land are the hitbox ones from Lesson 3-31. They have the ceiling check from its Challenge 1.How to use this: Click the green flag. Use the arrows to walk and space to jump. Reach the star. Then try falling in the water.
One splash takes all three lives.
The go-to is missing. So Pico is still in the water on the next tick, and the tick after that. Moving Pico out stops it counting again.
After I win, Pico still falls and walks.
Some blocks are outside the if <(state) = [play]>. Drag them in.
The water never does anything.
The blue was picked from the colour wheel, not from the Stage. Two blues can look the same but not be the same. Pick it with the eyedropper.
Pico gets the happy face for a moment and then loses it.
land and walk switch back to pico every tick. Once the state is won they stop running, so the happy face stays. Check that the star test sets the state.
A checkpoint
Put a flag on step 2. Once Pico has touched it, the water sends Pico back to the flag. It no longer goes to the start.
- Two variables,
respawn xandrespawn y. Set them to the start when the flag is clicked. - The flag changes costume when Pico reaches it. It moves the respawn point to itself.
- The water now uses
go to x: (respawn x) y: (respawn y).
How to use this: Click the green flag. Pico climbs to the flag, then walks off into the water.
Teacher note
The move worth pointing out: the respawn point stopped being two numbers typed into a block and became two variables. Anything in the game can change a variable — so anything can now decide where you come back. That is the whole idea of a checkpoint.
A crab on patrol
Add a crab that walks back and forth along the right-hand bank.
- It walks 30 ticks one way and 30 back, for ever. This is Cheese Maze’s patrol.
- Touching it costs Pico a life and sends it to the respawn point.
- The crab stops when the state is not
play.
How to use this: Click the green flag. Pico stands still on the right-hand bank and waits.
Teacher note
The crab moves with change x by (-3) in a repeat rather than glides, so it can be asked to stop at any tick. A glide cannot be paused halfway — which matters the moment the state stops being play.
The stomp
Landing on the crab should defeat it. Walking into it should still hurt.
- Touching the crab while
y velocityis below 0 (falling) is a stomp. - A stomp hides the crab and bounces Pico up a little.
- Any other touch costs a life, as before.
How to use this: Click the green flag. Pico jumps as the crab comes and lands on top of it.
Teacher reveal — the speed tells you which way
if <touching (Crab v)?> then
if <(y velocity) < (0)> then
broadcast [stomped v]
set [y velocity v] to (8)
else
change [lives v] by (-1)
go to x: (respawn x) y: (respawn y)
set [y velocity v] to (0)
end
end
The same trick as the head bump in 3-31: the sign of y velocity says how Pico arrived. Falling means from above. The bounce of 8 is not physics, it is feedback — a stomp that does not bounce feels like nothing happened.
Ship it
Put the whole arc together into one platform game. Make it good enough to give to somebody else.
- A title screen that explains the keys. A round starts from it.
- Falling, jumping, steps, walls, head bumps and a hitbox.
- Three lives, water, a checkpoint and a crab you can stomp.
- A clock, and a best time that stays after the round ends.
How to use this: Click the green flag and read the title. Then play: arrows to walk, space to jump. Reach the star.
Teacher note
Notice how little of this lesson was new code. Lives and states are Storm Flight; the patrol is Cheese Maze; the clock and the best time are 3-27’s. The only genuinely new idea is reading the sign of a speed to tell a stomp from a collision. A finished game is mostly the pieces you already had, put in the right order.
Summary 5 min
- A second flat colour can be a second rule. Green holds you up. Blue takes a life.
- After moving Pico straight to a new place, set the speed to 0. Somewhere new means starting still.
- The whole game sits inside
if <(state) = [play]> then. So winning or losing just stops it. - A checkpoint is a respawn point kept in variables. The level can change them.
- Falling onto an enemy is a stomp. The sign (+ or −) of
y velocitytells you which.
- Hazard
- Anything in a level that costs a life to touch.
- Respawn point
- Where the player comes back after losing a life.
- Checkpoint
- A place that moves the respawn point once you reach it.
- Stomp
- Defeating an enemy by landing on it from above.
Hand in
Save your game. You have finished the Jump Quest arc. You made a character that moves by a number gravity changes. It lives on one screen you painted yourself.