Make a Space Shooter Game in Scratch for Kids

KidsKod original illustration.

Ready to make a space shooter game in Scratch? You will fly a ship across the bottom of the screen, fire a laser with the space bar, dodge swooping enemies, and keep score. This KidsKod walkthrough is for ages 8 to 14 who already know how to click the green flag and snap a few blocks together.

Brand new to Scratch? Start with What Is Scratch? A Fun Guide for Kids, then come back for this space mission.

What you need

  • A free Scratch account at scratch.mit.edu, used with a parent nearby
  • About 35 to 45 minutes
  • A simple spaceship idea, a laser, and one friendly enemy (paint them or pick them from the Scratch library)

What you will learn

By the end, you will have:

  • A ship that slides left and right with the arrow keys
  • A laser that fires when you press the space bar
  • An enemy that appears at a random spot and flies downward
  • A score that goes up when a laser hits an enemy
  • A lives counter and a short game-over message

Step 1: Set the space stage and the ship

  1. Click Create in Scratch.
  2. Delete the cat if you want a clean stage.
  3. On the Stage, open the Backdrops tab. Choose a night-sky backdrop, or paint a dark background with a few stars.
  4. Add a spaceship sprite, or paint a simple triangle ship in a bright color. Rename the sprite to Ship.
  5. Shrink the ship so it has room to dodge, and place it near the bottom of the stage.
  6. On Ship, set the rotation style to don't rotate so the costume does not flip when you press left or right.

A small, tidy ship is easier to steer than a huge one. If it hangs off the bottom of the stage, drag it up a little before you start coding.

Step 2: Fly the ship with the arrow keys

Use key ... pressed? inside a forever loop, not two separate "when key pressed" hats, so the ship keeps moving while you hold a key. Put this on Ship:

when green flag clicked
set rotation style [don't rotate]
go to x: 0 y: -140
forever
  if <key [right arrow] pressed?> then
    change x by 8
  end
  if <key [left arrow] pressed?> then
    change x by -8
  end
  if <(x position) > 220> then
    set x to 220
  end
  if <(x position) < -220> then
    set x to -220
  end
end

Click the green flag and hold the arrows. If the ship feels slow, try 10. If it feels wild, try 6.

Step 3: Fire a laser with the space bar

  1. Paint a short yellow or white rectangle, or choose a small bolt sprite. Rename it to Laser.
  2. Make the laser quite small so a hit feels fair.
  3. The laser should start hidden, then appear at the ship, fly upward, and hide again when it leaves the stage or hits an enemy.

Put this on Laser:

when green flag clicked
hide
forever
  if <key [space] pressed?> then
    go to [Ship v]
    show
    repeat until <<touching [edge v]?> or <touching [Enemy v]?>>
      change y by 12
    end
    hide
    wait 0.25 seconds
  end
end

The short wait stops the laser from firing in one long stream if you hold the space bar. If you have not created Enemy yet, start with only touching [edge v]?, then add the enemy check in Step 5.

Step 4: Add an enemy that flies down

  1. Choose or paint a friendly alien, a rock, or a little saucer. Rename the sprite to Enemy.
  2. Keep the costume simple and not too large, so the ship has a fair chance to dodge.
  3. Make two variables for all sprites: score and lives. Show both on the stage.

The enemy starts just above the stage at a random x position, flies downward, and starts again from the top. Put this on Enemy:

when green flag clicked
set [score v] to 0
set [lives v] to 3
forever
  go to x: (pick random -200 to 200) y: 170
  show
  repeat until <(y position) < -170>
    change y by -5
  end
  hide
  wait 0.3 seconds
end

Click the green flag. Enemies should appear at different spots along the top and travel down. If they feel too fast, change -5 to -3.

Step 5: Detect hits and keep score

Now connect the laser and the enemy. Change the enemy's repeat until block so it also stops when the enemy is touching the laser, then add a point:

repeat until <<(y position) < -170> or <touching [Laser v]?>>
  change y by -5
end
if <touching [Laser v]?> then
  change [score v] by 1
  hide
  wait 0.2 seconds
else
  hide
  wait 0.3 seconds
end

Keep this inside the same forever loop from Step 4. Fire at an enemy and watch score go up by 1. If it does not, confirm the sprite is named exactly Enemy, and that the laser script also uses touching [Enemy v]?. A small play sound [pop v] after the score change makes a hit feel great.

Step 6: Add lives and a game over

The game should cost a life if an enemy reaches the bottom, or if an enemy bumps into the ship. Expand the else from Step 5, and check lives at the end of the loop:

if <touching [Laser v]?> then
  change [score v] by 1
  hide
  wait 0.2 seconds
else
  if <<touching [Ship v]?> or <(y position) < -170>> then
    change [lives v] by -1
  end
  hide
  wait 0.3 seconds
end
if <(lives) < 1> then
  say Game over! for 2 seconds
  stop [all v]
end

The last two lines go at the end of the forever loop. stop all freezes every sprite so the game-over message does not fire again and again. Try a full round: move, shoot, score, lose lives, and see the game end when lives reach 0. If lives drop too quickly, only lose a life when the enemy touches the ship.

Kiko's tip

Get one ship, one laser, and one enemy working before you add more enemies. A single loop you can finish is easier to debug than five clones that all misbehave at once.

Try these fun upgrades

When the basic shooter works, pick one upgrade and finish it before adding another:

  • Faster waves: After the score reaches 5, change the enemy speed from -5 to -7 so later waves feel more exciting.
  • More enemies: Use create clone of [myself v] on Enemy so two or three aliens can be on the screen at once. Put the downward flight on when I start as a clone, and use delete this clone after a hit.
  • A power-up star: Add a star sprite that falls more slowly. If the ship touches it, give a bonus point or a short burst of faster lasers.

You just built a real arcade-style game with movement, shooting, scoring, and lives. That is a big step. Save your project, play it a few times, then try one upgrade. When you are ready, KidsKod has more Scratch games waiting for you.

Next Post Previous Post
No Comment
Add Comment
comment url