- Learnt28 min · the aim, the bullet, the wave
- Basic24 min · build the first draft
- Challenge 1–327 min · move, shoot, defend
- Extrabonus · design it properly
Review — the Car Race, finished 5 min
- A broadcast says where to go. A variable says what was chosen.
- Give every setting a default before the player sees anything.
- A My Block is useful even with no inputs.
- Clones let one sprite be in many places at once.
Quick-fire
You have one sprite. You need twenty of them on screen at once. What do you use?
Reveal the answer
Clones. You will use them twice today. Once for the bullets, and once for the skeletons.
Today’s Topic 3 min
- Planning a game before building it
- Aiming with the mouse
- A bullet that knows where it is going
- Enemies that keep coming
Learning outcome
By the end of this lesson you will be able to:
- Make a sprite face the mouse pointer.
- Fire a clone that flies in a straight line and then deletes itself.
- Spawn enemies at random, and remove them when they are hit. To spawn means to make a new one appear.
Learnt — a game you aim 28 min
The rules, before the blocks
You have built two games now. Both times, it was easier when we chose the rules first. So here are our rules:
- You move with the arrow keys.
- Your aim always follows the mouse.
- Click to shoot. The bullet goes where the aim was pointing.
- Enemies come from the left, at random, for ever.
That is all. Four rules make a game. The rest just makes it nicer.
Aiming with the mouse
We need two sprites and two blocks. A crosshair is an aiming mark. It sits on the mouse pointer. The player turns to face it.
when flag clicked
go to [front v] layer
forever
go to [mouse-pointer v]
end
set rotation style [left-right v]
forever
point towards [mouse-pointer v]
end
left-right stops the knight turning upside down when you aim behind him.Firing a bullet
When you press the mouse, the player makes a clone of the Bullet sprite:
when flag clicked
forever
wait until <mouse down?>
create clone of [Bullet v]
wait until <not <mouse down?>>
end
wait until <not <mouse down?>> trick as the Whack-a-mole hammer.Then the clone moves to the player and points the right way:
when I start as a clone
go to [Player v]
point towards [mouse-pointer v]
go to [front v] layer
show
repeat until <(x position) > (235)>
move (7) steps
end
delete this clone
point towards [mouse-pointer v] happens once, right at the start. After that the bullet just goes straight.Enemies that keep coming
One sprite makes all of them. The original stays hidden. It only makes clones:
when flag clicked
hide
forever
wait (pick random (0.8) to (2.5)) seconds
go to x: (-210) y: (pick random (-140) to (140))
create clone of [myself v]
end
when I start as a clone
show
repeat until <(x position) > (225)>
change x by (1.6)
if <touching [Bullet v]?> then
change [score v] by (1)
delete this clone
end
end
delete this clone
Basic — the first draft 24 min
New project. Four sprites: Player, Aim, Bullet, Zombie.
Step 1 — draw quickly
Draw them as if you are looking down from above. That is easiest. The player is a circle with something sticking out. The enemy is a blob. The bullet is a small dot, and the aim is a cross. Take five minutes, not fifty.
Step 2 — the aim
Use a forever loop with go to [mouse-pointer v] inside it. Add go to [front v] layer so it is never hidden behind anything.
Step 3 — the player
Use the movement loop from Lesson 6. It uses change x by (px) and change y by (py) instead of move (10) steps. Then add point towards [mouse-pointer v] at the bottom.
Step 4 — shooting
Build the player’s second stack. Then build the Bullet’s clone script.
Step 5 — the enemies
Build the spawner and the walker.
Step 6 — hitting
Add the touching [Bullet v]? check to the enemy. Add a matching touching [Zombie v]? to the bullet, so it does not fly on through.
Step 7 — play it
Play for two minutes without stopping. Write down anything that felt wrong.
The player spins upside down.
Add set rotation style [left-right v] at the start. Or use set rotation style [all around v] if your drawing looks fine from any angle. A drawing seen from above usually does.
One click gives me a stream of bullets.
The wait until <not <mouse down?>> is missing. So the loop fires again as soon as it comes round.
No enemies ever appear.
Maybe the clone never gets show. Or it spawns on the edge and deletes itself straight away. Move the spawn point inwards.
Bullets fly straight through the enemies.
They move too far each step, so they jump right over. Instead of one move (14) steps, use two move (7) steps blocks. Put the touching check between them.
The game gets slower and slower.
Something is not deleting its clones. The bullet and the enemy both need a delete this clone at the end of their trip. Being hit is not enough.
Move and aim
- Arrow keys move the player. It slides to a stop.
- The crosshair follows the mouse everywhere.
- The player always faces the mouse.
- The player cannot leave the Stage.
Shooting
- One click, one bullet.
- The bullet starts at the player and goes where you were aiming.
- It disappears when it leaves the Stage.
- Holding the button down does not fire a stream of bullets.
Teacher note
The seven-bullets-from-three-clicks bug is worth doing on purpose. Build it with broadcast [Fire] first, click three times, and count. Then ask why. The answer — a when I receive [Fire v] hat runs on every clone — is a rule they have known since Level 1’s Lesson 10 and have never seen bite.
Hold the line
This is the mission from the slides: the first draft you can play.
- Enemies arrive from the left at random times and random heights.
- They walk across and disappear at the far side.
- A bullet stops one, and your score goes up.
- It can be played for two minutes without slowing down.
Teacher reveal — what to fix first
Most drafts have the same three problems, in this order of annoyance:
- Bullets pass through. The step is bigger than the enemy. Halve it and check twice.
- Nothing happens when you lose. There is no losing yet — that is next lesson, and it is fine to leave it.
- It gets slow. Clones are not being deleted. Ask them to hold down the mouse for thirty seconds and watch.
Design it properly
The slides ask you to draft your game and write the rules down before you build any more. Make it your game, not ours.
- What is the player, and what is chasing them?
- How do you lose?
- Is there a way to win, or does it go for ever?
- What gets harder as you go?
Summary 5 min
- Write the rules before the blocks. Four rules make a game.
go to [mouse-pointer v]andpoint towards [mouse-pointer v]are all an aim needs.point towards [mouse-pointer v]runs once. After that a bullet cannot be steered.- A
when I receive [Fire v]hat runs on every clone. That is why the player makes the clone, not the bullet. - Never spawn a sprite on the edge if you then check whether it is touching the edge.
- Aim
- A sprite that shows where you are pointing.
- Spawn
- To make a new enemy appear.
- Wave
- Enemies arriving one after another.
- Draft
- The first version that plays. Ugly is fine.
Hand in
Share your draft. Send the link and your five rules to your teacher. Next lesson, the enemies fight back.