Skip to content
ExploreMapGamesStoriesComicsVideosStudioPrintablesCode LabJourneys
By age โ–พ
  • ๐Ÿงธ Tiny Explorers2โ€“5
  • ๐Ÿฆ‰ Curious Learners6โ€“8
  • ๐Ÿ”ญ Young Investigators9โ€“12
  • ๐Ÿš€ Trailblazers13โ€“17
๐Ÿ‘คParent sign in
Kids Amazing World

A creative learning playground. No ads, no tracking, no chat. Every item is reviewed before it appears.

Explore

  • Explore
  • Learning journeys
  • Surprise me
  • Parent planner

For grown-ups

  • Child safety
  • Privacy
  • Terms (draft)
  • Free & Premium
  • Parent sign in

About this content

Some items in this build are placeholders written for development. Third-party resources are only listed with permission, a license, or an official embed.

โ† All game tutorials

๐Ÿš€ Space Battle

Blast waves of aliens before they land.

How to playYour functionsSettings you can changeStep by stepIdeas to tryLessons

๐ŸŽฎ How to play

Reach the goal score before you run out of lives. Shoot the aliens, dodge their bombs, and don't let any reach the bottom.

  • โ—€ โ–ถ buttons or โ† โ†’: Move your ship.
  • Fire button or the space bar: Shoot. You can only have a few shots in the air at once.

โš™๏ธ Your functions

You write these functions. The game calls them when something happens.

  • onHit()

    Runs every time you destroy an alien.

    function onHit() {
      score = score + 10;
    }
  • onDamage()

    Runs when a bomb hits you or an alien reaches the bottom.

    function onDamage() {
      lives = lives - 1;
    }
  • onWave(n)

    Runs when you wipe out a whole wave. n is the number of the wave you just beat.

    function onWave(n) {
      // a bonus for beating a wave?
    }

๐ŸŽš๏ธ Settings you can change

Variables at the top of your code are the game's settings. Change a value, press Play, and see what happens.

ship = "๐Ÿš€"
Your ship.
alien = "๐Ÿ‘พ"
The invaders.
goal = 100
Reach this score to win.
lives = 3
Hits you can take.
speed = 2
From 1 (slow) to 5 (fast).
maxBullets = 3
How many of your shots can be flying at once (1 to 6).
danger = 0.1
From 0 to 1: how often the aliens drop bombs. 0 means never.
wave = 1
The current wave. The game counts it up for you. set by the game
bullet = "๐Ÿ”น"
The emoji for your shots. optional
bomb = "๐Ÿ’ฃ"
The emoji for alien bombs. optional
score = 0
Your points. The game starts it at 0 and you change it in your functions. set by the game

๐Ÿชœ Step by step

Each step shows code you can add to the end of your game's code. A function or variable written later replaces the earlier one, so you never have to delete anything.

  1. 1Play the starter

    Move under the aliens and fire. Each alien you destroy runs onHit.

    function onHit() {
      score = score + 10;
    }
  2. 2More firepower

    Allow more shots at once, and make the aliens drop fewer bombs.

    let maxBullets = 5;
    let danger = 0.05;
  3. 3Armour that takes two hits

    A counter can make a rule apply only some of the time. Here you only lose a life on every second hit, because the first one just dents your armour.

    let hits = 0;
    
    function onDamage() {
      hits = hits + 1;
      if (hits % 2 === 0) {
        lives = lives - 1;
      }
    }
  4. 4A bigger magazine each wave

    onWave gets the wave number n, and you can change any setting there. Here each wave you beat scores 100 and lets you have one more shot in the air at once (up to 6).

    function onWave(n) {
      score = score + 100;
      maxBullets = Math.min(6, maxBullets + 1);
    }
Show the full starter code
// ๐Ÿš€ Space Battle!
let ship = "๐Ÿš€";
let alien = "๐Ÿ‘พ";
let goal = 100;         // reach this score to win
let lives = 3;
let speed = 2;         // 1 (slow) to 5 (fast)
let maxBullets = 3;    // how many shots can be flying at once
let danger = 0.1;        // 0 to 1: how often aliens drop bombs

function onHit() {
  score = score + 10;
}

function onDamage() {
  lives = lives - 1;
}

// n is the wave you just beat
function onWave(n) {
  // a bonus for beating a wave?
}

๐Ÿ’ก Ideas to try

  • A bug-zapper: a ๐Ÿ•ท๏ธ ship against ๐Ÿ› aliens.
  • A bullet-hell mode: danger 0.6 with 6 lives.
  • Make each wave pay double what the last one did.

Tips

  • Aliens march sideways and step down at the edges. Take them out from one side first.
  • Waves get bigger each time, so save your shots for good targets.

๐ŸŽ“ Lessons for this game

  • ๐Ÿ”’Space Battle: first blastPremium
  • ๐Ÿ”’Space Battle: shieldsPremium
  • ๐Ÿ”’Space Battle: wave bonusPremium

๐Ÿ› ๏ธ Make your own Space Battle game

Game Studio and the full lessons are part of Premium.

See Premium
โ† ๐ŸŽ๏ธ Racing