- Learnt28 min · a jump is a number, and only from the ground
- Basic24 min · walk and jump
- Challenge 1–327 min · jump power, the double jump, how far
- Extrabonus · the trampoline
Review — falling 5 min
y velocityis the speed upwards. Gravity takes 1 off it every tick.- A landing goes too far into the ground. So
landpushes Pico back out and sets the speed to 0. - The push-out runs without screen refresh. So you never see it.
Quick-fire
Pico is standing still on the grass. What is its y velocity? And what would happen on the next few ticks if something set it to 12?
Reveal the answer
It is 0. Set it to 12 and Pico moves up 11, then 10, then 9… It slows to a stop and falls back. Gravity turns it round on its own. That is a jump. You have already made all of it except one block.
Today’s Topic 3 min
- A jump is
set [y velocity v] to (12) - The
on groundvariable: jump only from something solid - Jump power, jump height and air time
- A double jump, and why it needs a hat block
Learning outcome
By the end of this lesson you will be able to:
- Make Pico jump with one block.
- Stop it jumping again in mid-air.
- Predict how high and how far a jump will go.
Learnt — the jump 28 min
1 · A jump is one block
Keep last lesson’s loop as it is. To jump, set the speed to a positive number (more than 0). That is all:
when flag clicked
forever
change [y velocity v] by (-1)
change y by (y velocity)
land :: custom
end
when [space v] key pressed
set [y velocity v] to (12)
set block for you every 1.2 seconds.How to use this: Click the green flag. Pico jumps three times on its own; watch the highest monitor.
2 · The flying bug
A game checks its keys inside the loop. So the jump goes in there too. Now press space again while Pico is still in the air:
if <key (space v) pressed?> then
set [y velocity v] to (12)
end
How to use this: Click the green flag. Six presses come a third of a second apart. Watch Pico climb out of the top.
3 · Only from the ground
Pico may jump only when it is standing on something. The land block already knows when that is. It is the moment it pushes Pico out of the grass. So land gets one more job. It looks after a variable called on ground.
define land
set [on ground v] to (0)
if <touching color [#3FA34D]?> then
repeat until <not <touching color [#3FA34D]?>>
change y by (1)
end
set [y velocity v] to (0)
set [on ground v] to (1)
end
on ground goes back to 0 every tick. Only a real landing sets it to 1.
if <<key (space v) pressed?> and <(on ground) = (1)>> then
set [y velocity v] to (12)
end
How to use this: Click the green flag. The same six presses — count how many turn into jumps.
Basic — walk and jump 24 min
Open your meadow from last lesson. Pico already falls and walks; today it jumps.
Step 1 — the new variable
- Make a variable called
on ground. - Tick its box so you can watch it on the Stage while you test.
Step 2 — land keeps track
- Find the
landdefine hat you made last lesson. Do not make a new block. Addset [on ground v] to (0)at the very top. - Inside the
if, after the speed is set to 0, addset [on ground v] to (1). - Run it. The monitor should read 1 while Pico stands and 0 while it falls.
Step 3 — the jump
- At the end of the forever loop, add
if <<key (space v) pressed?> and <(on ground) = (1)>> then. - Inside it:
set [y velocity v] to (12).
Step 4 — try to break it
- Hold space down. Pico should bounce along, never flying.
- Tap space in mid-air. Nothing should happen.
- Walk off the ledge and tap space while falling. Nothing should happen then either.
- Try to jump onto the ledge from the ground. You cannot. Challenge 1 looks at why.
when flag clicked
set rotation style [left-right v]
go to x: (-150) y: (-94)
set [y velocity v] to (0)
forever
if <key (right arrow v) pressed?> then
point in direction (90)
change x by (4)
end
if <key (left arrow v) pressed?> then
point in direction (-90)
change x by (-4)
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
end
land from Learnt part 3.How to use this: Click the green flag. Walk with the arrows and jump with space. Try jumping in mid-air. You cannot.
Pico jumps once and then never again.
on ground is never set back to 1. The set … to (1) is missing from inside the if in land.
Holding space still makes Pico fly.
The and is missing. Or the jump is still under an old when [space v] key pressed hat. That hat does not ask about the ground. Delete the old hat.
Pico never jumps at all.
Look at the monitor while Pico stands still. Does it say 0? Then set [on ground] to (0) is after the if instead of before it. So it always wins.
The jump is tiny, or enormous.
That is the number in the set block. Challenge 1 measures what each number does.
Jump power
Three Picos jump at the same moment with powers of 8, 12 and 16.
- Each one records the highest point it reaches.
- Show how far each one rose above the ground.
- Guess the three numbers first.
How to use this: Click the green flag. All three jump together. Read the three rise monitors.
Teacher note
The rise for a power p is (p − 1) + (p − 2) + … + 1: a triangle number. That is why it grows so quickly — 16 does not rise twice as far as 8, it rises more than four times as far. A power of 18 rises 153, which clears the ledge; pupils who find that by trying have done the Extra’s maths without noticing.
The double jump
Let Pico jump once more in mid-air. Only once, not for ever.
- Make a variable
jumps left. Every landing sets it back to 2. - Each jump uses one. Pico can only jump if it has one left.
- A third press in the air does nothing until Pico lands again.
How to use this: Click the green flag. Three quick presses come. Watch jumps left run out. Then press space yourself.
Teacher reveal — why this one needs a hat block
when [space v] key pressed
jump :: custom
define jump
if <(jumps left) > (0)> then
set [y velocity v] to (12)
change [jumps left v] by (-1)
end
Inside the forever loop, a key that is held counts as pressed on every tick — so one press spends both jumps in two ticks and the double jump feels like a single tall one. when [space v] key pressed runs once per press, which is what a double jump needs. And land sets jumps left to 2 inside its if, so only a real landing refills it.
How far can Pico jump?
Do a running jump from the same spot three times. Walk at 2, then 4, then 6 pixels a tick.
- Measure from where Pico takes off to where it lands.
- Show all three lengths.
- Work out the rule that connects the speed and the length.
How to use this: Click the green flag and watch three running jumps from the same spot.
Teacher note
The air time does not depend on the walking speed at all — it is 24 ticks for a power of 12, whatever Pico’s feet are doing. So the length is the speed × 24, and a speed of 5 goes 120. Keep these numbers: next lesson builds platforms, and a gap wider than Pico can jump is a level nobody can finish.
The trampoline
The ledge is 140 above the ground. Pico’s best jump is 66. Add a trampoline that throws Pico high enough to land on it.
- Touching the
Trampolinesprite setsy velocityto 18. - Add a
boingscounter. One bounce must count once, not three times. - Walking into it from the side should launch Pico too.
How to use this: Click the green flag. Pico walks into the trampoline. It is thrown up onto the ledge.
Teacher note
Nothing about the trampoline is new: it is the jump block, run by a touch instead of a key. That is the idea to leave them with — every bounce pad, spring and launcher in a platform game is set [y velocity v] to ( ) with a different reason for running it.
Summary 5 min
- A jump is
set [y velocity v] to (12). Gravity does the rise, the top and the fall. on groundgoes back to 0 every tick. Only a real landing sets it to 1.- Jump only when a key is pressed and
on groundis 1. - Height grows much faster than power: 8 rises 28, 16 rises 120.
- Air time does not change with walking speed. So length = speed × air time.
- Jump power
- The speed a jump starts with.
- Air time
- How many ticks a jump spends off the ground. It is 24 for a power of 12.
- Flag variable
- A variable that is only ever 0 or 1. It answers one yes-or-no question.
- Double jump
- One extra jump allowed in mid-air, refilled by landing.
Hand in
Save your meadow. Next lesson the ground gets steps. You will find out what happens when Pico walks into one instead of jumping onto it.