- 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. Today we use two old ideas again.
when I start as a cloneanddelete this clone, from Topic 1.10.- A clone that falls from a random x along the top. The catching game used this.
Quick-fire
Right now, whoever holds their key wins. Why is that not much of a game?
Reveal the answer
There is nothing to decide. A game needs a choice. A choice means you have two or more things to pick from.
Today’s Topic 3 min
- Three keys for each player: forward, up and down.
- Asteroids are clones. They fall across both lanes.
- Why the touching check goes on the rocket, not on the asteroid.
- A star that helps you, instead of costing you.
Learning outcome
By the end of this lesson you will be able to:
- Steer a rocket up, down and forward.
- Fill the Stage with clones that come and then delete themselves.
- Say which sprite should do a touching check, and why.
Learnt — steering, rocks, stars 28 min
1 · Two more keys
A lane was one key. To dodge, a player must move up and down too. That 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. Every second it makes a clone. The clone starts at a random place on the top and falls.
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. The rocket is the right place. Here is why.
- When a rock touches “a rocket”, it does not know WHICH rocket. So it cannot knock the right one back.
- One asteroid can touch both rockets at once. Two checks can handle that. One shared check cannot.
- The rocket is the thing that changes. The sprite that changes 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
Rocks only cost you. A star should help you. It is the same clone shape, but it pushes you forward. It has one extra job: vanish 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
The rocket also needs one more if in its touching stack. This one moves it forward.
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
Build it in steps. Test each step on your own before you race anybody.
Step 1 — steering
- Add the up and down ifs to rocket 1.
- Fly in every direction to test it. Try two keys at once.
- 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 number of rocks 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 fewer stars than rocks.
- Add the catch check inside its repeat loop. Add one for each 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.
- Is it every time? Then 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 keeps running while the rocket is still inside the rock.
The star boosts both players.
It does not delete itself when it is caught. The delete goes inside the touching if. That if is in the clone’s repeat loop.
I can see a giant asteroid sitting in the middle.
The maker did not hide. hide is the first block after its green flag.
A field you can actually fly through
With too many rocks, the race is luck. With too few, nobody notices them. Find the number in between.
- You tried at least three different speeds for making rocks.
- 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 easy to notice, even when you are not looking at your rocket.
- A sound.
- Something you can see: a colour, a spin, a shrink, a bubble.
- It goes back to normal afterwards.
- After two hits in a row, the rocket does not stay 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 make you choose. Go for it, or stay on the fast line? Change it until the answer is hard.
- The boost is big enough to make you want it.
- A star that is out of your way can make you lose the race.
- Stars are rare. A race can end 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 flies at a rocket, not straight down.
- It picks the rocket that is further ahead.
- It still deletes itself once it leaves the Stage.
- The normal 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 is not just about holding a key now. It is about where to fly.
- Three ifs give a player forward, up and down.
- One hidden sprite makes every asteroid. Every clone deletes itself.
- The sprite that changes should usually ask the question.
- A cost and a reward together give you a choice. 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, it is forty steps back.
- Boost
- Something that helps the player. Often worth a detour, but not always.
- Spawn rate
- How often new clones are made. Too fast, and your field is a wall.
Next lesson: the last part of Space Race. Three races, a scoreboard and a champion.