What it does
You create a field from a definition and tick it with the player's input: turn, thrust, fire and defend. The field
runs whole fixed frames inside, then hands back its state and a stream of events, wave-start, fire,
rock-destroyed, ship-destroyed, saucer-spawn, hyperspace, shield-hit, beat and more, for your presenter
and sound to react to. It is deterministic for a seed and an input sequence, and the whole state snapshots and
restores.
The rocks are a split graph: each size has its outline scale, hit box, score and what it breaks into, and a cap on the field means a rock near the cap breaks into fewer pieces, as the arcade game did. Waves are a ramp or an authored table. The ship turns, thrusts and loses speed to friction under a speed cap, and after a crash it waits for a clear centre before it respawns. Shots have a count, a life and inherited velocity. Saucers follow a spawn timer that shrinks each time, hold off after a rock breaks unless few rocks are left, choose their size by score, and aim at the ship, a rock or nowhere in particular. Defence is hyperspace, which can fail, or a shield that drains and bounces rocks away. Homing hunters arrive late in a wave and break into smaller, faster hunters.
Every outline the rules collide with is returned as data, about the object's centre, along with the ghost positions to draw across a wrapping seam. So a glowing vector cabinet and a 3D scene show exactly the shapes that collide. Collision is the arcade's octagonal box test or exact polygon outlines, with shots swept as segments.
Features
- Split graphs — any number of rock sizes, each with a scale, hit box, score, split count and velocity rule, under a field cap.
- Waves — a start, step and maximum, or an authored table, drifting in from the edges or placed clear of the ship.
- Inertial ship — turn rate, thrust, friction, a speed cap and a safe respawn.
- Shots — limited count and life, inherited velocity, single or automatic fire, wrapping or stopped by walls.
- Saucers — spawn timer, quiet period, few-rocks threshold, size by score and aim with lead and score-based error.
- Hyperspace or shield — a failure roll for hyperspace; a draining shield that bounces rocks and absorbs shots.
- Hunters — tiers that steer towards the ship and split into smaller hunters.
- Lives and scoring — extra ships by score, score roll-over and a running total.
- Heartbeat — the tempo and tone for audio, quickening by time or by rocks left.
- Outlines as data — rock, ship, flame, saucer and hunter outlines, jagged outline generation and collision helpers.
- Three presets — the 1979 arcade rules, the 1981 deluxe sequel with easy and hard settings, and a bounded four-size arena.
Good for
- Classic rock-blasting shooters in the style of Asteroids, with wrapping, saucers and hyperspace.
- Shield-and-hunter variants in the style of Asteroids Deluxe, with a draining shield, faster rocks and killer satellites.
- Walled rock arenas, where rocks and shots bounce off the sides and split three ways.
- Mine-field and debris games, using the split graph and waves with your own outlines.
- 3D or vector presentations, since every collision outline is data the presenter can draw.
- Attract modes and replays, from the shipless attract field and deterministic input.
Make it yours
Everything is the definition passed to createAsteroidField, and each preset returns one to edit. The classic
preset takes knobs for lives, seed, the wave ramp, split count, shot count and life, wrapping, saucers, defence, the
extra-ship score and thrust; the deluxe preset adds easy or hard and hunters; and any field of the result can change:
outlines, sizes, scores, velocity rules, timers, aim and hit boxes.
Two materially different games from one pack: the classic arcade field, wrapping, with four shots, hyperspace and saucers; and the bounded arena preset, with bouncing walls, four rock sizes splitting three ways, exact polygon collision, authored waves, rapid short shots, and no saucers or defence. Between them sits anything you edit, such as a classic field where rocks come in two sizes splitting four ways, with six shots and walls.
A quick look
The classic rules, ticked with input and drawn with wrap copies:
const af = game.asteroidField;
const g = af.createAsteroidField(af.asteroidsPreset());
g.reset({ wave: 1 });
g.tick(dt, { turn: -1, thrust: true, fire: false, defend: false });
for (const e of g.drain()) { /* wave-start, fire, rock-destroyed, ship-destroyed, saucer-spawn, beat … */ }
const s = g.state;
for (const r of s.rocks) draw(g.rockOutline(r), g.ghosts(r.x, r.y, reach));
Works with
vector-2d,vector-fxandpost-bloom— for a glowing vector-cabinet look.world-3dandrender-3d— for a 3D presentation of the same rules.audio— for the heartbeat and the rest of the sound.actors— for movement chips when you want the parts of a space shooter rather than this whole game.scrolling-shooterandwave-arena— for scrolling shooters and room-based arena shooters instead.
Good to know
- It is one player: two-player alternation, high-score initials and the attract-mode score table are left to your presentation.
- Frames are fixed, 62.5 a second in the arcade presets and 60 in the bounded one, and a field holds at most 10,000 rocks.
- A snapshot holds the state but not the definition, so restore it into a field built from the same definition.
- The deluxe preset follows the operator's manual and player reports rather than the program, so some of its numbers are approximations.
- Ring barriers, tethered ships and enemy construction from other space shooters are not modelled;
arenahas barrier rings.






