Skip to content

Phase 5: Zylons, photons, shields, meteors and explosions (MANUAL_SPEC §16, §17.7, §17.8, §18.3) - #8

Merged
spacehunter merged 2 commits into
mainfrom
h/star-raiders-phase-5-zylons-photons-shie-iyvb
Nov 28, 2026
Merged

spacehunter merged 2 commits into
mainfrom
h/star-raiders-phase-5-zylons-photons-shie-iyvb

Conversation

@spacehunter

Copy link
Copy Markdown
Owner

Phase 5 of docs/OVERHAUL_PLAN.md Part 3. The rules come from MANUAL_SPEC §16, §17.7, §17.8, §17.13 and §18.3. Where the spec leaves a detail open, the ROM routine it cites decides it: MANEUVER, TRIGGER, COLLISION, INITEXPL, INITPOSVEC, GAMELOOP steps 8–15 and 26–27, and the tables ZYLONSHAPTAB, ZYLONFLPATTAB, ZYLONVELTAB, ZYLONHOMVELTAB, HITMIN/MAXZTAB, PLSHAP1/2TAB, PLSHAPOFF/HEIGHT/COLOR/BRITTAB.

What changed

  • src/sim/zylons.ts (§17.7, §17.8). It simulates the ROM's five PLAYER objects plus the explosion, in KM in the ship frame:
    • At most 2 Zylon ships and 1 Zylon torpedo. A new ship replaces a dead one only while the sector's galaxy count allows.
    • Ships spawn at least 28928 KM ahead. The type mix is 4/8 fighter, 3/8 cruiser, 1/8 basestar on every level (ZYLONSHAPTAB).
    • The game steers each ship every 8 loops:
      • velocity indices step toward random milestones (±62/±30/±4 KM/loop patterns);
      • within 8192 KM, a visible ship switches to the attack pattern: it weaves around the cross hairs and dives in to 2560 KM, then pulls out;
      • on WARRIOR and COMMANDER only, there is a 48/256 chance of a back attack.
    • Ships swing with the player's turns (the ROM's ZYLONTIMX/Y follow timers).
    • The Zylon torpedo (§17.7) fires near our plane and within 8192 KM. It lives 62 loops and flies at 80 KM/loop. It homes at 1/4/8/20 KM/loop by level. Zylons never fire from behind at NOVICE.
  • Photons (§17.7):
    • one photon per press, from alternating barrels (±256 KM to the side, 256 KM below);
    • a barrel refuses to fire while its last torpedo is 23 loops old or younger (TRIGGER: life ≥ 232);
    • 255-loop life at 102 KM/loop, not carried by our own speed;
    • −10 energy per photon;
    • the sparkle comes from ANDing the shape with random bits every frame;
    • damaged photons fire from one barrel only, and destroyed photons don't fire;
    • shields no longer block firing.
  • Hits follow COLLISION: the two sprites' pixels must overlap, and the target must be inside the depth window.
    • A basestar dies only to a torpedo less than 15 loops old. An older torpedo bursts on its hull and is used up, but the basestar survives.
    • Meteors and the Zylon torpedo can be shot down, for no score.
    • A Zylon kill gives +6 and K+1, and comes off the galaxy map.
  • Shields (§5.9, §17.7): every hit costs 100 energy and rolls §17.3 damage. A hit while the shields are down destroys the ship: the game switches to the front view and plays the destroyed end sequence. The hit test reads the panel's SHIELDSCOLOR, so damaged shields protect only while they flicker on.
  • Meteors (§16, §17.7):
    • on 3 of every 4 loops (on every loop in an empty sector), a 4/256 chance of a new meteor while PLAYER2 is dead or off screen;
    • it starts 3840 KM ahead and flies at −8 KM/loop;
    • a meteor hit works like a torpedo hit: it always destroys a subsystem, and it does no damage at NOVICE with the shields up;
    • no meteors in starbase sectors or during hyperwarp.
  • Explosions: 32 fragments with velocities −7..+7 KM/loop, lasting 128 loops. They are drawn as single playfield pixels coloured like the stars.
  • Red alert sounds only on arriving in a Zylon sector. STARBASE SURROUNDED no longer plays the alert; its "message from starbase" tune is Phase 12.
  • Sprites (src/render/sprites.ts, §17.13, §18.3):
    • the ROM bitmaps, byte for byte, with 8 distance size cells (high byte of |z| ÷ 2), and nothing drawn at 8192 KM or more;
    • one sprite row per scanline (half a playfield row), so pixels are twice as wide as tall;
    • grey/white brightness by range ($0E near to $04 far);
    • the basestar colour flickers at random every frame;
    • the starbase is drawn as the three-part orange pulsing sprite;
    • this replaces the Phase 3 placeholder blobs.
  • Deleted: entities/Enemy.ts, entities/EnemyProjectile.ts, entities/PhotonTorpedo.ts, systems/CombatSystem.ts, config/EnemyConfig.ts. Callers are switched: Game, the long-range scan (now ±40,000 KM), θΦR tracking, and M as the target toggle.
  • Debug hook and capture:
    • __sr.spawn now takes KM. A placed ship flies straight in.
    • New __sr.zylons() and __sr.meteor(x,y,z).
    • New shots: 11-fighter-approach, 11a-fighter-hit, 11b-explosion, 12-meteor, 12a-meteor-shot, 13-fighter, 13a-cruiser, 13b-basestar, plus the --sequence fighter-kill GIF.

Checks

  • npm run build passes.
  • npm test: 187 tests pass (42 new). They cover the basestar rule, shields-down death, the 23-loop refire, the type mix, the meteor rules, the 2-ship/1-torpedo limits, homing by level, back attacks, explosions, the sprite bitmaps, size cells and the basestar flicker.
  • The npm run capture -- --seed 1979 run plays to mission end (zero energy) in 29 shots. Two runs gave identical hashes, with no page errors.

Calls I made where the spec is silent or loose

  • Refire: the spec says "after 23 loops". The ROM's TRIGGER compares the barrel's torpedo life against 232, so a barrel fires again on the 24th loop after its last launch. Barrels alternate, so two quick shots are possible.
  • Turn following: the ROM adds the stick to the Zylon velocity index. The ships therefore swing the same way as the view, as the spec's "swing with your turns" says. I implemented this literally.
  • Ships behind you at NOVICE: a ship that has passed you keeps to the far rear, around −62,000 KM, until you turn. The ROM's unsigned high-byte comparisons do the same; I kept them on purpose.
  • Capture shots 11–13: they raise the shields, per the manual's NOVICE drill "press S and C". Without them, the fighter's return fire destroys the ship, as the rules say it should.
  • Left to later phases: photon homing on lock-on and the attack computer (Phase 6), shooting a starbase (Phase 10), hyperwarping into a meteor (Phase 8), the explosion sound delay and the POKEY sounds (Phase 12). Until Phase 8, the arrival marker's row stands in for the vicinity mask.

Evidence

Seeded NOVICE run (seed 1979, capture --sequence fighter-kill): a fighter's grey H approaches, two photons leave the alternating barrels, the hit, then the 32-fragment explosion. The fighter's own torpedo then hits the raised shields (random-colour flash, −100 energy). Left: the full frame; right: 2× zoom of the centre.

Seeded NOVICE run (seed 1979, capture --sequence fighter-kill): a fighter's grey H approaches, two photons leave the alternating barrels, the hit, then the 32-fragment explosion. The fighter's own torpedo then hits the raised shields (random-colour flash, −100 energy). Left: the full frame; right: 2× zoom of the centre.

Fighter, cruiser and basestar: the manual's sprite plates, the in-game sprite at cell 0 (capture shots 13, 13a, 13b), and all 8 ROM shape cells with grey brightness by range ($0E near, $04 far). The basestar's colour flickers at random each frame.

Fighter, cruiser and basestar: the manual's sprite plates, the in-game sprite at cell 0 (capture shots 13, 13a, 13b), and all 8 ROM shape cells with grey brightness by range ($0E near, $04 far). The basestar's colour flickers at random each frame.

Meteor shot down (capture shots 12 and 12a): a green meteor comes in at −8 KM/loop plus our speed, a photon hits it, it explodes into 32 fragments, and K stays at 19 because meteors score nothing.

Meteor shot down (capture shots 12 and 12a): a green meteor comes in at −8 KM/loop plus our speed, a photon hits it, it explodes into 32 fragments, and K stays at 19 because meteors score nothing.

Contact sheet of the seed-1979 capture: 29 shots running to mission end (09-zero-energy), including the new Phase 5 shots 11–13b. Two runs gave identical hashes.

Contact sheet of the seed-1979 capture: 29 shots running to mission end (09-zero-energy), including the new Phase 5 shots 11–13b. Two runs gave identical hashes.

@spacehunter
spacehunter merged commit fef74d8 into main Nov 28, 2026
@spacehunter
spacehunter deleted the h/star-raiders-phase-5-zylons-photons-shie-iyvb branch November 28, 2026 02:22
@spacehunter
spacehunter restored the h/star-raiders-phase-5-zylons-photons-shie-iyvb branch November 28, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant