- Learnt28 min · a level is a number; the handover
- Basic24 min · two levels
- Challenge 1–327 min · the pile-up, a title card, the best level
- Extrabonus · levels in a list
Review — a camera that follows 5 min
- Pico walks for real;
scroll the worldpulls everything back at the end of the tick. - World x is
((scroll x) + (x position)). - Respawns, enemies and checkpoints are world positions.
Quick-fire
Your Ground sprite switches to L1 screen 1, L1 screen 2… using join. What is the smallest change that would make it draw a different set?
Reveal the answer
Put the level number in the join. L1 is “L” and 1; make the 1 a variable called level and the same blocks draw level 2’s costumes. That is the whole of today’s first idea.
Today’s Topic 3 min
- A
levelvariable picks the screens and the sky - Rebuilding the world: old clones delete, new ones are made
- A
next levelMy Block - Title cards, using Storm Flight’s state
Learning outcome
By the end of this lesson you will be able to:
- Choose a level’s costumes and backdrop from one number.
- Replace one level with another without leaving anything behind.
- Hold the game still while a title card is showing.
Learnt — levels 28 min
1 · A level is a number
Paint level 2’s screens as four more Ground costumes, named L2 screen 1 to L2 screen 4, and add a second backdrop. Name the backdrops Level 1 and Level 2. Now both choices are a join:
switch costume to (join (join [L] (level)) (join [ screen ] (screen)))
switch backdrop to (join [Level ] (level))
How to use this: Click the green flag. Level 1 scrolls past, then level 2 is built and scrolls past.
2 · The handover
When Pico reaches the flag, everything about the level has to change at once. One My Block does it, and the build broadcast is answered by every copy of Ground: a clone deletes itself, and the original builds the new level.
define next level
change [level v] by (1)
switch backdrop to (join [Level ] (level))
set [scroll x v] to (0)
go to x: (-180) y: (-104)
set [y velocity v] to (0)
broadcast [build v] and wait
broadcast [scroll v]
broadcast [build v] and wait, so the new screens exist before anything is placed.
when I receive [build v]
if <(is clone) = (1)> then
delete this clone
else
build the level :: custom
end
build the level is last lesson’s clone-making script, moved into a My Block. is clone is for this sprite only: the original keeps 0, and every clone sets it to 1 the moment it starts.How to use this: Click the green flag. Pico walks the last stretch of level 1 to the flag, then carries on into level 2.
Basic — two levels 24 min
Open your scroller from last lesson and give it a second level.
Step 1 — paint level 2
- Duplicate the four Ground costumes, rename them
L2 screen 1toL2 screen 4, and repaint them — harder than level 1. - Keep the same green for solid ground and the same blue for water.
- Add a second backdrop; name the two
Level 1andLevel 2.
Step 2 — the number
- Make
levelfor all sprites, andis cloneon Ground for this sprite only. - Change the costume and backdrop switches to the joins from Learnt part 1.
Step 3 — build on request
- Change Ground’s
when flag clickedtowhen I receive [build v], with the clone check from part 2. - In the clone’s start script, add
set [is clone v] to (1). - Pico’s flag script sets
levelto 1, thenbroadcast [build v] and wait.
Step 4 — the flag
- Make the
next levelblock. - Touching the flag on level 1 runs it; touching it on level 2 wins the game.
if <touching (Flag v)?> then
if <(level) = (2)> then
set [state v] to [won]
say [Both levels - you win!]
else
next level :: custom
end
end
if <(state) = [play]> then, as in Storm Flight.How to use this: Click the green flag. Arrows to walk, space to jump. Reach the flag on level 1, then on level 2.
Level 2 appears but looks like level 1.
The costume switch still says L1 instead of joining in level, or it runs before level has changed.
Level 2 is drawn on top of level 1.
The old clones are not deleting themselves. That is Challenge 1.
Nothing is there at all after the flag.
A costume name does not match the join — check for a missing space. Scratch keeps the old costume when asked for one that does not exist.
Pico reaches the flag and skips straight to level 3.
Pico is still touching the flag on the next tick. next level must move Pico back to the start before anything else can check the flag again.
The pile-up
Count the screens. Build level 2 once without the delete, once with it.
- A
screenscounter: +1 when a clone starts, −1 when one deletes. - The original counts as one screen.
- Read the counter after each build.
How to use this: Click the green flag. Level 1 is built, then level 2 — with the old clones left in place.
Teacher note
A pile-up is easy to miss, because the new screens are drawn over the old ones and most of the time look fine. The counter is the honest check — and three extra clones per level adds up fast against Scratch’s limit of 300.
A title card
Show “LEVEL 1” and “LEVEL 2” for a moment at the start of each level, with the game held still.
- Set
statetotitle, show the card, then set it toplay. - The loop only moves Pico when the state is
play. - Test it by holding the arrow key down through a card.
How to use this: Click the green flag. The arrow key is held down the whole time — watch whether Pico moves during the cards.
Teacher note
This is Storm Flight’s title screen, reused. The point worth drawing out: nothing had to be added to Pico’s physics, because the state check already wraps it — Lesson 3-23’s pause and today’s title card are the same idea.
The furthest level
Keep a best level that survives losing and starting again.
- It is set to 0 only when the project is first opened.
- Every time a level starts, raise it if this level is higher.
- Starting again from level 1 must not lower it.
How to use this: Click the green flag. Pico reaches level 2, then starts again from level 1.
best level is on screen and never goes down, however often you lose.Teacher note
The same shape as every best in this level — a high score in Storm Flight, a best time in Cheese Maze — on a new kind of number. By now the pupils should be writing it without being shown.
Levels in a list
Let a list decide the order of the levels. Change the list, and the game plays them in a different order — without a single script changing.
- A list
level order, holding2then1. - A
stagecounter: stage 1 plays(item (stage) of [level order v]). - The flag moves on one stage, not one level.
How to use this: Click the green flag and read which level each stage of the game turns out to be.
Teacher note
Watch for pupils who put the same level in the list twice. It works — and it is a perfectly good design choice, a revisited level. The list does not care.
Summary 5 min
- One
levelvariable chooses the screens and the sky, throughjoin. - A new level is a rebuild: clones delete themselves, the original makes new ones.
next levelchanges the number, resets the scroll and Pico, then builds.- A title card is a state in which the game loop moves nothing.
- Level
- One complete stretch of world, with its own screens and sky.
- Rebuild
- Throwing the old level’s clones away and making the new level’s.
- Title card
- A moment between levels when the game is held still.
- Data-driven
- Behaviour decided by a list or a variable, not by changing scripts.
Hand in
Save your game. Next lesson, both levels fill up with coins.