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.
1. Build the spawnables
Section titled “1. Build the spawnables”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.
-
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.
-
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, emitworld:edge; down at the shields’ line, emitworld:invaded. - On Message
world:bombs→ a Random Range below 0.006 → Spawn a bomb at its own position. - On Contact (
with:shot) → emitworld:alien.killedwith its points as the payload → Destroy (Self). - On Message
world:clear→ Destroy (Self), so the rules can clear the field for a new game.
- On Message
-
Build the shot: a mover in the layer
shotthat hitsalien,shield, flying at0,0,-14for 1.2 s. Its graph destroys it on contact withalienand withshield, and On Destroy emitsworld:shot.gone. -
Build the bomb: a mover in the layer
bombthat hitsship,shield, falling at0,0,5.5for 3 s. It destroys itself on contact withshipand withshield. -
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.
2. Build the game file
Section titled “2. Build the game file”-
Save
alien-invasion.blend. Adddata/rows.json: five rows, each naming the alien cartridge for that row (asset: the address ofalien-c,alien-b,alien-b,alien-a,alien-a). -
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 = bombandarcade.grace = 1.5. -
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. -
Bind
move=keys:ArrowLeft/KeyA,ArrowRight/KeyD ; touch:x,fire=keys:Space/ArrowUp ; touch:tapandagain=keys:Enter/KeyR. Setspawn.preloadto the five spawnables’ addresses. -
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.
3. Write the rules
Section titled “3. Write the rules”-
A wave. Two nested For Loop nodes spawn 5 rows × 11. A Data Table on
data/rows.jsonnames each row’s cartridge. -
The march. On Tick sends
world:marchwith a vector payload, and every alien moves at once: one message moves all 55. When an alien reportsworld:edge, the next march is a drop and a turn. Each march also flipsmarchFrameand sendsworld:bombs. -
Speed up. The time between marches is an Expression on how many aliens are left,
0.05 + a * 0.012seconds withathe count, so the last few race. -
Fire. One shot at a time: a
shotAliveflag, set when you fire and cleared by the shot’sworld:shot.gone. An expression such asa && b && !creads “can fire”. -
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. -
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.againsendsworld:clearand 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.
4. Build and play
Section titled “4. Build and play”-
Press Build Cartridge and publish the game with its five spawnables (Publish and share).
-
Open it: the formation marches in step, flips its pose with every step, and drops a row when it reaches the edge.
What you learned
Section titled “What you learned”- One message can move every spawned copy at once.
- Copies of one graph roll their own random numbers.
sprite.face = ylays a sprite flat for a top-down camera, andsprite.framepicks its frame from a variable.
Next: Star swarm sends enemies diving along paths drawn in Blender.