Skip to content

Alien invasion

For creatorsAdd-on 1.104.0+

In this tutorial you build a formation of aliens that marches side to side, drops a row at each edge and speeds up as it thins out, while you fire one shot at a time from behind shields. Nothing here is new machinery: it is the spawner, arcade bodies, sprites and expressions from earlier tutorials, used at a larger scale. The new lesson is one graph with many owners. This builds on tutorial 6, Functions.

▶ Play the finished game: ← → move, Space fires, Enter plays again. On a phone, hold a finger to the left or right of the ship to move it, and tap to fire.

Each alien is its own small cartridge with a sprite, an Arcade Sensor in the layer alien, and its own graph. Build three kinds (alien-a, alien-b, alien-c), a shot and a bomb, each in its own file as in tutorial 2.

  1. Draw each alien in two poses and pack the strip as a sprite sheet (tutorial 3 shows how). Give its one object Sprite and Arcade Sensor, with the tags in the table.

  2. Give the alien an Asset-scope graph:

    • On Message world:march → Translate (Self) by the message’s Payload, a vector the rules send. Then ask its own position: past the edge, emit world:edge; down at the shields’ line, emit world:invaded.
    • On Message world:bombs → a Random Range below 0.006 → Spawn a bomb at its own position.
    • On Contact (with: shot) → emit world:alien.killed with its points as the payload → Destroy (Self).
    • On Message world:clear → Destroy (Self), so the rules can clear the field for a new game.
  3. Build the shot: a mover in the layer shot that hits alien,shield, flying at 0,0,-14 for 1.2 s. Its graph destroys it on contact with alien and with shield, and On Destroy emits world:shot.gone.

  4. Build the bomb: a mover in the layer bomb that hits ship,shield, falling at 0,0,5.5 for 3 s. It destroys itself on contact with ship and with shield.

  5. Press Build Cartridge in each file.

Object Components Tags
Alien Sprite, Arcade Sensor sprite.frames = 2, sprite.face = y (lying flat, facing up), sprite.frame = marchFrame (a variable picks the pose), arcade.layer = alien, asset.primary = 1
Shot Sprite, Arcade Mover arcade.layer = shot, arcade.hits = alien,shield, arcade.velocity = 0,0,-14, arcade.lifetime = 1.2
Bomb Sprite, Arcade Mover arcade.layer = bomb, arcade.hits = ship,shield, arcade.velocity = 0,0,5.5, arcade.lifetime = 3

sprite.frame lets one variable flip the whole formation’s pose at each step. Sprite sheets are shared, so 55 aliens use one picture.

  1. Save alien-invasion.blend. Add data/rows.json: five rows, each naming the alien cartridge for that row (asset: the address of alien-c, alien-b, alien-b, alien-a, alien-a).

  2. Add the ship: Sprite and Arcade Mover with arcade.drive = move, arcade.driveSpeed = 7, arcade.driveAxis = x, arcade.min = -6.4,0,5.6, arcade.max = 6.4,0,5.6, arcade.layer = ship, arcade.hits = bomb and arcade.grace = 1.5.

  3. Add the shields: small blocks with Sprite and Arcade Sensor in the layer shield, each with a graph that destroys the block on any contact.

  4. Bind move = keys:ArrowLeft/KeyA,ArrowRight/KeyD ; touch:x, fire = keys:Space/ArrowUp ; touch:tap and again = keys:Enter/KeyR. Set spawn.preload to the five spawnables’ addresses.

  5. Look straight down with an orthographic camera: camera.mode = fixed, camera.projection = ortho, camera.at = 0,20,1.6, camera.target = 0,0,-0.2, camera.orthoHeight = 7.6, camera.orthoMinWidth = 14.2.

  1. A wave. Two nested For Loop nodes spawn 5 rows × 11. A Data Table on data/rows.json names each row’s cartridge.

  2. The march. On Tick sends world:march with a vector payload, and every alien moves at once: one message moves all 55. When an alien reports world:edge, the next march is a drop and a turn. Each march also flips marchFrame and sends world:bombs.

  3. Speed up. The time between marches is an Expression on how many aliens are left, 0.05 + a * 0.012 seconds with a the count, so the last few race.

  4. Fire. One shot at a time: a shotAlive flag, set when you fire and cleared by the shot’s world:shot.gone. An expression such as a && b && !c reads “can fire”.

  5. A kill. On world:alien.killed, add the payload to the score and take one from the count. A cleared wave brings the next one, a little lower.

  6. The end. A bomb on the ship costs a life (only while playing). No lives left, or world:invaded, ends the game and keeps the best score. again sends world:clear and starts a new formation.

Many owners, many rolls. All 55 aliens run the same graph, so their Random Range nodes share a seed. Each copy still rolls its own numbers, because each owner’s id is mixed into the seed: bombs fall a few at a time, at many moments, and the same way on every run.

  1. Press Build Cartridge and publish the game with its five spawnables (Publish and share).

  2. Open it: the formation marches in step, flips its pose with every step, and drops a row when it reaches the edge.

  • One message can move every spawned copy at once.
  • Copies of one graph roll their own random numbers.
  • sprite.face = y lays a sprite flat for a top-down camera, and sprite.frame picks its frame from a variable.

Next: Star swarm sends enemies diving along paths drawn in Blender.