- Learnt28 min · steering, asteroids, who checks, the boost
- Basic25 min · build the obstacle race
- Challenge 1–327 min · a flyable field, a bump you feel, a star worth the detour
- Extrabonus · an asteroid that hunts the leader
Review — where we got to 5 min
The race has a countdown nobody can beat. Two ideas from much earlier come back today.
when I start as a cloneanddelete this clone, from Topic 1.10.- A falling clone from a random x along the top — the catching game’s whole shape.
Quick-fire
Your race is won by whoever holds their key hardest. Why is that not much of a game?
Reveal the answer
There is nothing to decide. A game needs a choice, and a choice needs at least two things you could do with the same second.
Today’s Topic 3 min
- Three keys per player: forward, up and down
- Asteroids as clones drifting down across both lanes
- Why the touching check belongs on the rocket, not on the asteroid
- A star that pays instead of costing
Learning outcome
By the end of this lesson you will be able to:
- Give a player two-way steering as well as forward.
- Fill a Stage with clones that appear and clean themselves up.
- Say why a collision check belongs on one sprite rather than the other.
Learnt — steering, rocks, stars 28 min
1 · Two more keys
A lane was one key. To dodge, a player needs to move up and down as well, which is two more ifs in the same forever loop.
- Open rocket 1’s controller.
- Right-click the key-if and choose Duplicate. Twice.
- Change one copy’s key to
wand its block tochange y by (4). - Change the other to
sandchange y by (-4). - On rocket 2, use the up and down arrows to match its right arrow.
forever
if <key [d v] pressed?> then
change x by (4)
end
if <key [w v] pressed?> then
change y by (4)
end
if <key [s v] pressed?> then
change y by (-4)
end
end
2 · Asteroids
One sprite makes all of them. It hides itself, and every second it makes a clone that starts somewhere random along the top and drifts down.
when flag clicked
hide
forever
wait (1) seconds
create clone of [myself v]
end
when I start as a clone
set size to (70) %
go to x: (pick random (-120) to (170)) y: (170)
show
repeat (36)
change y by (-10)
end
delete this clone
How to use this: Click the green flag to start it. Nothing else to press — watch it through, then use ↺ Reset to run it again.
3 · Who asks the question?
You could put the touching check on the asteroid or on the rocket. On the rocket is right, and it is worth knowing why.
- An asteroid touching “a rocket” does not know WHICH rocket, so it cannot knock the right one back.
- One asteroid can touch both rockets at once. Two separate checks handle that; one shared check does not.
- The rocket is the thing being affected, and the sprite that changes is usually the sprite that should ask.
when flag clicked
forever
if <touching [Asteroid v]?> then
start sound [Bonk v]
change x by (-40)
wait (0.4) seconds
end
end
How to use this: Click the green flag, then click the stage once and hold D, S or W to fly Rocket 1.
4 · Something worth chasing
An obstacle course is all cost and no reward. The star is the same clone shape with the sign flipped, plus one extra job: disappear when it is caught.
when I start as a clone
go to x: (pick random (-120) to (160)) y: (170)
show
repeat (36)
change y by (-10)
if <touching [Rocket 1 v]?> then
start sound [Collect v]
delete this clone
end
end
delete this clone
And on the rocket, one more if in the collision stack, paying out instead of charging.
if <touching [Star v]?> then
change x by (60)
end
How to use this: Click the green flag, then click the stage once and hold D, S or W to fly Rocket 1.
How to use this: Click the green flag, click the stage once, then steer both rockets yourself: W, S and D for one, the arrow keys for the other.
Basic — build the obstacle race 25 min
Four passes. Test after every one, on your own, before you play it against anybody.
Step 1 — steering
- Add the up and down ifs to rocket 1.
- Test flying in every direction, including diagonally.
- Do the same on rocket 2 with the arrow keys.
Step 2 — the asteroids
- Add a rock sprite and name it
Asteroid. - Build the maker stack. Remember the hide.
- Build the clone stack, ending in delete this clone.
- Run it and watch for a minute. The field should stay steady.
Step 3 — the bump
- Add the collision stack to rocket 1.
- Test by flying into rocks on purpose.
- Duplicate the stack onto rocket 2.
Step 4 — the star
- Add a star sprite with its own maker and clone stacks.
- Make it rarer than the asteroids.
- Add the catch check inside its repeat loop, one per rocket.
- Add the boost if to both rockets.
Step 5 — race it
- Race yourself five times, driving both rockets.
- Count how often a race is decided by a star.
- If it is every single time, the star is worth too much.
The asteroids stop coming after a while.
You have hit Scratch’s 300-clone limit. The clone stack is missing its delete this clone, or the maker is making them far too fast.
Hitting one rock throws me right off the screen.
There is no wait after the knock-back, so the check fires every frame while the rocket is still inside the rock.
The star boosts both players.
It is not deleting itself when it is caught. The delete goes inside the touching if, in the clone’s repeat loop.
I can see a giant asteroid sitting in the middle.
The maker sprite never hid. hide is the first block after its green flag.
A field you can actually fly through
Too many rocks and the race is luck. Too few and nobody notices them. Find the number in between.
- You have tried at least three different spawn speeds.
- A good player can cross without being hit.
- A player who is not looking gets hit.
- You can say which speed you kept.
A bump you can feel
Right now a hit is a small jump backwards. Make it something a player notices without looking at their own rocket.
- A sound.
- Something visible: a colour, a spin, a shrink, a bubble.
- It goes back to normal afterwards.
- Two hits in a row do not leave the rocket stuck looking hurt.
Teacher note — undoing an effect
A change [color v] effect by (25) with no matching set [color v] effect to (0) leaves the rocket a different colour every race. That is the bug worth catching here, and it is the same bug the mood script had in Pet Pal: something turned on and never turned off.
A star worth the detour
A star should be a decision: go for it, or stay on the fast line? Tune it until the answer is not obvious.
- The boost is big enough to be tempting.
- Going for one out of your way can lose you the race.
- Stars are rare enough that a race can pass without one.
- You can say what you set the boost to and why.
Teacher note — a good decision is one nobody agrees on
The success condition really is the disagreement. If everyone chases every star, the boost is too big and there is no decision. If nobody bothers, it is too small. A class arguing about it has built a game with a strategy in it, which is a long way from where they were at Topic 1.1.
An asteroid that hunts
Add one asteroid that does not drift straight down. It heads for whoever is in front, so being in the lead costs something.
- One asteroid moves towards a rocket rather than straight down.
- It picks whichever rocket is further ahead.
- It still deletes itself once it leaves the Stage.
- The ordinary drifting asteroids still work.
Teacher notes — point towards, and comparing two positions
when I start as a clone
go to x: (pick random (-120) to (170)) y: (170)
show
if <([x position v] of [Rocket 1 v]) > ([x position v] of [Rocket 2 v])> then
point towards [Rocket 1 v]
else
point towards [Rocket 2 v]
end
repeat (60)
move (6) steps
end
delete this clone
Two new things at once, so this is a genuine stretch. point towards [Rocket 1 v] aims a sprite at another one, and ([x position v] of [Rocket 1 v]) — from Sensing — reads a number off a sprite that is not this one.
It aims ONCE, when the clone is born, and then flies straight. A version that re-aims every frame is unavoidable and stops being fun, which is worth letting a fast pupil discover for themselves.
Going further: next lesson three races become a match, and one of them becomes a champion.
Summary 4 min
The race stopped being about holding a key and started being about where to fly.
- Three ifs give a player forward, up and down.
- One hidden sprite makes every asteroid, and every clone deletes itself.
- The sprite that changes is usually the sprite that should ask the question.
- A cost and a reward together make a decision. Either one alone does not.
- Clone
- A copy of a sprite made while the project runs. It must delete itself when done.
- Obstacle
- Something that costs the player. Here, forty steps backwards.
- Boost
- Something that pays the player. Worth a detour, but not always.
- Spawn rate
- How often new clones are made. The difference between a field and a wall.
Next lesson: the last lesson of the arc — three races, a scoreboard, and a champion.