Add seven enemy weapon patterns and a rolling ?combat demo wave sequence

- New hostiles frames 1–7 (bomber → warden) with distinct stats and
  monotonic difficulty ramp in data/combat.json
- Shared js/combat/Weapons.js dispatch for lance, spray, burst, rapid,
  ring, missile, and combo patterns used by both combat contexts
- New dodgeable heat-seeking Missile (capped turn-rate homing) plus pure
  geometry helpers in Combat.js
- Rewire ?combat boot to startWaves('combat_demo'): 7 rolling waves, one
  type each, 6 ships per wave, 3 concurrent, replacement per kill
- Add missile_fire SFX voice and extend tests/CDP demo checks for all
  patterns and the full wave run
This commit is contained in:
Brian Fertig 2026-09-20 08:17:34 -06:00
parent 658babe216
commit 69ce598f6c
15 changed files with 1435 additions and 48 deletions

View File

@ -1 +1 @@
{"version":1,"dirMtimeMs":1789832404716.821,"goals":[]}
{"version":1,"dirMtimeMs":1789880763752.7512,"goals":[]}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,121 @@
{
"version": 3,
"id": "mu986lbo-140zqa",
"objective": "=== Goal ===\nObjective: Give the 7 new enemy ships (spritesheet frames 1–7) distinct stats and attack patterns using a mix of weapon types (heat-seeking missiles, spray, plus new ideas), ramping modestly in difficulty frame 1 → 7, and rewire the ?combat demo to send a sequence of rolling waves — one wave per ship type in difficulty order, 6 ships of that type per wave, 3 on screen at a time.\n\nSuccess criteria:\n- data/combat.json → enemyTypes has 7 new types (frames 1–7), each with distinct stats + a distinct weapon pattern; difficulty (hull/shields/damage) climbs monotonically frame 1 → 7 with only modest bumps (not a wall).\n- Weapon types actually implemented and used: heat-seeking missile (dodgeable — capped turn-rate), spray fan, rapid burst, rapid-fire, ring burst, and a heavy/elite combo. The missile is the only genuinely new projectile; the rest are loops/config over the existing bolt.\n- All 7 fire their pattern correctly in BOTH the main-game ?combat boot and the standalone range (shared firing path).\n- The ?combat boot now dispatches a sequence of rolling waves: 7 waves in difficulty order, each wave = 6 ships of that single type, maxConcurrent=3, each kill sending in a replacement (replacePerKill=1).\n- dev/combat.test.mjs still passes (pure Node modules: EnemyTypes/Waves stay Phaser-free).\n\nBoundaries:\n- In scope: data/combat.json (enemyTypes + a new wave script + ?combat wiring), js/combat (new weapon behaviors: EnemyShip firing, a missile projectile, fireEnemy dispatch in both CombatScene and CombatSystem), dev/combat.test.mjs.\n- Out of scope: new art/sprites, player-ship changes, the XP curve, and the existing pirate_ambush quest wave (stays as-is). The pre-existing frame-0 raider stays untouched.\n- New weapons must not break the standalone range (combat.html / dev server /combat) — it shares the firing path.\n\nConstraints (hard rules):\n- Heat-seeking missiles MUST be dodgeable: capped turn-rate + moderate speed, so the player can out-turn them.\n- Each subsequent ship only a LITTLE harder than the previous (modest +hull/+shields/+damage), not a big jump.\n- Keep EnemyTypes.js and Waves.js pure (no Phaser/scene imports) so dev/combat.test.mjs runs in bare Node.\n- ?combat demo: exactly 7 waves, one type each, in difficulty order; rolling; 6 per wave; 3 concurrent; 1 replacement per kill.\n- Don't mutate shared config sections in place (deepMerge already guards this; follow the pattern).\n\nVerification contract:\n- Run dev/combat.test.mjs → 0 failures.\n- grep confirms the new wave script is wired to the ?combat boot (spawnPack replaced) and all 7 frames are referenced in enemyTypes.\n- Manual browser check of ?combat: 7 waves fire in order, 3 on screen at a time, one type per wave; missiles visibly home and can be dodged; spray/burst/ring render correctly.\n- Re-read the 7-ship roster table and confirm each type's pattern + difficulty bump is present.\n\nIf blocked: stop and ask the user.",
"status": "complete",
"autoContinue": true,
"usage": {
"tokensUsed": 10055317,
"activeSeconds": 7168
},
"sisyphus": false,
"revision": 142,
"createdAt": "2026-09-20T02:57:00.276Z",
"updatedAt": "2026-09-20T05:06:03.752Z",
"scheduler": {
"version": 1,
"owner": "01a0bcb6-3151-728d-8a3d-e5448d16a70b",
"generation": "e1b3640c-c13f-41e4-9c2d-4b3af8df49d9",
"used": 1,
"phase": "running",
"repairUsed": false,
"decision": {
"kind": "ready",
"nextAction": "Continue pursuing the goal, then verify and complete it when satisfied.",
"purpose": "ready"
},
"dispatch": {
"id": "18fbeaa1-987d-4e0e-a7e6-57129de676e8",
"kind": "ready",
"claimedAt": 1789873020301
}
},
"taskList": {
"tasks": [
{
"id": "task-1",
"title": "Design 7 enemyTypes (frames 1–7) in data/combat.json",
"status": "complete",
"verificationContract": "combat.json has 7 enemyTypes entries (frames 1–7), each with distinct stats + weapon config; hull/shields/damage climb monotonically with modest bumps; EnemyTypes.enemyTypeIds()/enemySheetList() resolve all 7.",
"completedAt": "2026-09-20T03:05:24.312Z",
"evidence": "Node check: 7 types (frames 1–7) resolve; hull 80→150, xp 18→42 monotonic; 7 distinct patterns; combat_demo normalizes to 7 rolling waves (6/3/1 each)"
},
{
"id": "task-2",
"title": "Implement new weapon behaviors (missile + spray/burst/ring/rapid/heavy)",
"status": "complete",
"verificationContract": "Missile projectile class with capped turn-rate homing exists; spray/burst/ring/rapid dispatch from fireEnemy in BOTH CombatScene and CombatSystem; EnemyTypes.js + Waves.js remain pure Node (no Phaser import).",
"completedAt": "2026-09-20T04:21:17.494Z",
"evidence": "Missile.js (capped turn homing, Node-tested) + Weapons.js firePattern dispatch all 7 patterns; both contexts wired (CombatScene/CombatSystem.fireEnemy → firePattern); Node suite green importing EnemyT"
},
{
"id": "task-3",
"title": "Rewire ?combat boot to the 7-wave rolling sequence",
"status": "complete",
"verificationContract": "GameScene ?combat boot calls startWaves(new script) instead of spawnPack; script = 7 rolling waves, 6 per wave, one type each, difficulty order, maxConcurrent=3, replacePerKill=1.",
"completedAt": "2026-09-20T04:21:17.495Z",
"evidence": "GameScene:1050 startWaves('combat_demo') (spawnPack no longer the boot path); combat_demo = 7 rolling waves bomber→warden, 6/3/1 each; Node e2e run passes; browser sfxcheck found live wave ship after "
},
{
"id": "task-4",
"title": "Extend tests + manual playtest verification",
"status": "complete",
"verificationContract": "dev/combat.test.mjs passes (0 failures) incl. new script normalize/runner cases; manual ?combat run shows 7 waves in order, 3 at a time, missiles dodgeable, spray/burst/ring render.",
"completedAt": "2026-09-20T05:03:03.768Z",
"evidence": "node dev/combat.test.mjs: all checks passed (0 failures). CDP demo check PASS: range renders all 7 patterns w/ shape; main 7 waves in order, 3 on screen, replacement/kill, 42 kills done. sfxcheck PASS"
}
],
"blockCompletion": true,
"proposedAt": "2026-09-20T02:56:38.761Z"
},
"stopReason": "agent",
"archivedPath": ".pi/goals/archived/goal_2026091923060370_mu986lbo-140zqa.md"
}
# Goal Prompt
=== Goal ===
Objective: Give the 7 new enemy ships (spritesheet frames 1–7) distinct stats and attack patterns using a mix of weapon types (heat-seeking missiles, spray, plus new ideas), ramping modestly in difficulty frame 1 → 7, and rewire the ?combat demo to send a sequence of rolling waves — one wave per ship type in difficulty order, 6 ships of that type per wave, 3 on screen at a time.
Success criteria:
- data/combat.json → enemyTypes has 7 new types (frames 1–7), each with distinct stats + a distinct weapon pattern; difficulty (hull/shields/damage) climbs monotonically frame 1 → 7 with only modest bumps (not a wall).
- Weapon types actually implemented and used: heat-seeking missile (dodgeable — capped turn-rate), spray fan, rapid burst, rapid-fire, ring burst, and a heavy/elite combo. The missile is the only genuinely new projectile; the rest are loops/config over the existing bolt.
- All 7 fire their pattern correctly in BOTH the main-game ?combat boot and the standalone range (shared firing path).
- The ?combat boot now dispatches a sequence of rolling waves: 7 waves in difficulty order, each wave = 6 ships of that single type, maxConcurrent=3, each kill sending in a replacement (replacePerKill=1).
- dev/combat.test.mjs still passes (pure Node modules: EnemyTypes/Waves stay Phaser-free).
Boundaries:
- In scope: data/combat.json (enemyTypes + a new wave script + ?combat wiring), js/combat (new weapon behaviors: EnemyShip firing, a missile projectile, fireEnemy dispatch in both CombatScene and CombatSystem), dev/combat.test.mjs.
- Out of scope: new art/sprites, player-ship changes, the XP curve, and the existing pirate_ambush quest wave (stays as-is). The pre-existing frame-0 raider stays untouched.
- New weapons must not break the standalone range (combat.html / dev server /combat) — it shares the firing path.
Constraints (hard rules):
- Heat-seeking missiles MUST be dodgeable: capped turn-rate + moderate speed, so the player can out-turn them.
- Each subsequent ship only a LITTLE harder than the previous (modest +hull/+shields/+damage), not a big jump.
- Keep EnemyTypes.js and Waves.js pure (no Phaser/scene imports) so dev/combat.test.mjs runs in bare Node.
- ?combat demo: exactly 7 waves, one type each, in difficulty order; rolling; 6 per wave; 3 concurrent; 1 replacement per kill.
- Don't mutate shared config sections in place (deepMerge already guards this; follow the pattern).
Verification contract:
- Run dev/combat.test.mjs → 0 failures.
- grep confirms the new wave script is wired to the ?combat boot (spawnPack replaced) and all 7 frames are referenced in enemyTypes.
- Manual browser check of ?combat: 7 waves fire in order, 3 on screen at a time, one type per wave; missiles visibly home and can be dodged; spray/burst/ring render correctly.
- Re-read the 7-ship roster table and confirm each type's pattern + difficulty bump is present.
If blocked: stop and ask the user.
## Progress
- Status: complete
- Auto-continue: on
- Sisyphus mode: no
- Time spent: 1h59m28s
- Tokens used: 10M (10,055,317) tokens
## Tasks
<!-- blockCompletion: true -->
- [x] task-1: Design 7 enemyTypes (frames 1–7) in data/combat.json — evidence: Node check: 7 types (frames 1–7) resolve; hull 80→150, xp 18→42 monotonic; 7 distinct patterns; combat_demo normalizes to 7 rolling waves (6/3/1 each)
- [x] task-2: Implement new weapon behaviors (missile + spray/burst/ring/rapid/heavy) — evidence: Missile.js (capped turn homing, Node-tested) + Weapons.js firePattern dispatch all 7 patterns; both contexts wired (CombatScene/CombatSystem.fireEnemy → firePattern); Node suite green importing EnemyT
- [x] task-3: Rewire ?combat boot to the 7-wave rolling sequence — evidence: GameScene:1050 startWaves('combat_demo') (spawnPack no longer the boot path); combat_demo = 7 rolling waves bomber→warden, 6/3/1 each; Node e2e run passes; browser sfxcheck found live wave ship after
- [x] task-4: Extend tests + manual playtest verification — evidence: node dev/combat.test.mjs: all checks passed (0 failures). CDP demo check PASS: range renders all 7 patterns w/ shape; main 7 waves in order, 3 on screen, replacement/kill, 42 kills done. sfxcheck PASS

View File

@ -48,3 +48,16 @@
{"type":"goal_paused","goalId":"mu7ieab2-f24hte","reason":"user","status":"paused","at":"2026-09-19T14:55:34.986Z"}
{"type":"goal_focused","goalId":"mu7ieab2-f24hte","reason":"selected","at":"2026-09-19T15:32:31.167Z"}
{"type":"goal_focused","goalId":"mu7ieab2-f24hte","reason":"selected","at":"2026-09-19T15:38:35.941Z"}
{"type":"goal_created","goalId":"mu986lbo-140zqa","objective":"=== Goal ===\nObjective: Give the 7 new enemy ships (spritesheet frames 1–7) distinct stats and attack patterns using a mix of weapon types (heat-seeking missiles, spray, plus new ideas), ramping modestly in difficulty frame 1 → 7, and rewire the ?combat demo to send a sequence of rolling waves — one wave per ship type in difficulty order, 6 ships of that type per wave, 3 on screen at a time.\n\nSuccess criteria:\n- data/combat.json → enemyTypes has 7 new types (frames 1–7), each with distinct stats + a distinct weapon pattern; difficulty (hull/shields/damage) climbs monotonically frame 1 → 7 with only modest bumps (not a wall).\n- Weapon types actually implemented and used: heat-seeking missile (dodgeable — capped turn-rate), spray fan, rapid burst, rapid-fire, ring burst, and a heavy/elite combo. The missile is the only genuinely new projectile; the rest are loops/config over the existing bolt.\n- All 7 fire their pattern correctly in BOTH the main-game ?combat boot and the standalone range (shared firing path).\n- The ?combat boot now dispatches a sequence of rolling waves: 7 waves in difficulty order, each wave = 6 ships of that single type, maxConcurrent=3, each kill sending in a replacement (replacePerKill=1).\n- dev/combat.test.mjs still passes (pure Node modules: EnemyTypes/Waves stay Phaser-free).\n\nBoundaries:\n- In scope: data/combat.json (enemyTypes + a new wave script + ?combat wiring), js/combat (new weapon behaviors: EnemyShip firing, a missile projectile, fireEnemy dispatch in both CombatScene and CombatSystem), dev/combat.test.mjs.\n- Out of scope: new art/sprites, player-ship changes, the XP curve, and the existing pirate_ambush quest wave (stays as-is). The pre-existing frame-0 raider stays untouched.\n- New weapons must not break the standalone range (combat.html / dev server /combat) — it shares the firing path.\n\nConstraints (hard rules):\n- Heat-seeking missiles MUST be dodgeable: capped turn-rate + moderate speed, so the player can out-turn them.\n- Each subsequent ship only a LITTLE harder than the previous (modest +hull/+shields/+damage), not a big jump.\n- Keep EnemyTypes.js and Waves.js pure (no Phaser/scene imports) so dev/combat.test.mjs runs in bare Node.\n- ?combat demo: exactly 7 waves, one type each, in difficulty order; rolling; 6 per wave; 3 concurrent; 1 replacement per kill.\n- Don't mutate shared config sections in place (deepMerge already guards this; follow the pattern).\n\nVerification contract:\n- Run dev/combat.test.mjs → 0 failures.\n- grep confirms the new wave script is wired to the ?combat boot (spawnPack replaced) and all 7 frames are referenced in enemyTypes.\n- Manual browser check of ?combat: 7 waves fire in order, 3 on screen at a time, one type per wave; missiles visibly home and can be dodged; spray/burst/ring render correctly.\n- Re-read the 7-ship roster table and confirm each type's pattern + difficulty bump is present.\n\nIf blocked: stop and ask the user.","sisyphus":false,"autoContinue":true,"at":"2026-09-20T02:57:00.276Z"}
{"type":"task_list_set","goalId":"mu986lbo-140zqa","taskCount":4,"blockCompletion":true,"at":"2026-09-20T02:57:00.276Z"}
{"type":"task_started","goalId":"mu986lbo-140zqa","taskId":"task-1","at":"2026-09-20T02:57:57.911Z"}
{"type":"task_complete","goalId":"mu986lbo-140zqa","taskId":"task-1","evidence":"Node check: 7 types (frames 1–7) resolve; hull 80→150, xp 18→42 monotonic; 7 distinct patterns; combat_demo normalizes to 7 rolling waves (6/3/1 each)","at":"2026-09-20T03:05:24.313Z"}
{"type":"task_started","goalId":"mu986lbo-140zqa","taskId":"task-2","at":"2026-09-20T03:05:24.314Z"}
{"type":"task_complete","goalId":"mu986lbo-140zqa","taskId":"task-2","evidence":"Missile.js (capped turn homing, Node-tested) + Weapons.js firePattern dispatch all 7 patterns; both contexts wired (CombatScene/CombatSystem.fireEnemy → firePattern); Node suite green importing EnemyT","at":"2026-09-20T04:21:17.494Z"}
{"type":"task_complete","goalId":"mu986lbo-140zqa","taskId":"task-3","evidence":"GameScene:1050 startWaves('combat_demo') (spawnPack no longer the boot path); combat_demo = 7 rolling waves bomber→warden, 6/3/1 each; Node e2e run passes; browser sfxcheck found live wave ship after ","at":"2026-09-20T04:21:17.495Z"}
{"type":"task_complete","goalId":"mu986lbo-140zqa","taskId":"task-4","evidence":"node dev/combat.test.mjs: all checks passed (0 failures). CDP demo check PASS: range renders all 7 patterns w/ shape; main 7 waves in order, 3 on screen, replacement/kill, 42 kills done. sfxcheck PASS","at":"2026-09-20T05:03:03.769Z"}
{"type":"completion_requested","goalId":"mu986lbo-140zqa","at":"2026-09-20T05:03:52.556Z"}
{"type":"audit_started","goalId":"mu986lbo-140zqa","at":"2026-09-20T05:03:52.557Z"}
{"type":"audit_result","goalId":"mu986lbo-140zqa","verdict":"approved","report":"The config file looks complete. Now let me inspect the combat modules and tests.\n\nThe CDP endpoint and dev server are both live. Let me run the browser verification harnesses myself to confirm the claims.\n\nBoth independent browser harnesses pass. Let me verify the change scope didn't touch out-of-scope files and confirm the remaining details.\n\nAll success criteria verified against real artifacts, with independent re-runs of the verification contract:\n\n**1. Seven new types (frames 1–7), distinct stats + patterns, monotonic modest ramp** — `data/combat.json → enemyTypes`: bomber(f1, 80/10, dmg 10, lance), spitter(f2, 90/20, 11, spray 5 bolts/1.1 rad), stinger(f3, 100/25, 12, burst 3 staggered-speed), hunter(f4, 110/30, 13, heat-seeking missile), gunner(f5, 120/40, 14, rapid cd 0.5), barrage(f6, 135/50, 15, ring 8), warden(f7, 150/60, 18+20, combo). Hull 80→90→100→110→120→135→150, shields 10→20→25→30→40→50→60, damage 10→11→12→13→14→15→18 — strictly monotonic, bumps ≤ +15 (no wall). Raider (frame 0) and `pirate_ambunch` untouched (diff confirms only comments/enemyTypes/combat_demo changed).\n\n**2. Weapons implemented on a shared path, missile genuinely new** — `js/combat/Weapons.js` `firePattern` dispatches all 7 patterns; `js/combat/Missile.js` is the only new projectile (canvas art + sprite), rest are bolt loops/config. `homingStep` (capped turn) lives in pure `js/combat/Combat.js`. Missile caps: turn 2.2/2.4 rad/s vs player rotSpeed 6.4 rad/s, speed 170/190 px/s vs player maxSpeed 560 — dodgeable, and the cap is asserted in tests. Both `CombatScene.fireEnemy` and `CombatSystem.fireEnemy` now delegate to `firePattern` (old inline single-bolt code removed), and both run `stepMissiles`/`missilesHitPlayer`.\n\n**3. ?combat rewired** — `GameScene:1050` `this.combat.startWaves('combat_demo')`; `spawnPack` demoted to a practice pack (no longer the boot). `combat_demo` = exactly 7 rolling waves, one single type each in difficulty order, each `count: 6, maxConcurrent: 3, replacePerKill: 1`.\n\n**4. Tests — I ran them** — `node dev/combat.test.mjs` → \"combat rules: all checks passed\" (0 failures), including pure-geometry, all-7 pattern dispatch, missile homing/fuse/consume, and a full 7-wave CombatSystem end-to-end (42 kills, 3-on-screen cap, replacement-per-kill, 7 starts/7 clears). `EnemyTypes.js`/`Waves.js` import only `config/Config.js` (no Phaser).\n\n**5. Browser verification — I re-ran both CDP harnesses** (headless Chromium on :9333, dev server :8080): `dev/combat-demo-check.mjs` → \"seven ships: PASS\" (range: all 7 volleys with correct shape incl. 5-bolt fan, 8-bolt even ring, staggered burst, homing missile; main: 7 waves in order, 3 on screen, replacement per kill, done at 42 kills) and `dev/combat.sfxcheck.mjs` → PASS (range 9/9, main 10/10 events incl. `missile_fire`). The range (`/combat`) shares the firing path and renders all 7 patterns — not broken.\n\nDiff scope is confined to the in-scope files (combat.json, js/combat/*, GameScene, dev tests); no out-of-scope files (XP curve, ship.json, sidequests) touched by this goal's changes.\n\n<approved/>","at":"2026-09-20T05:06:03.693Z"}
{"type":"goal_completed","goalId":"mu986lbo-140zqa","archivePath":".pi/goals/archived/goal_2026091923060370_mu986lbo-140zqa.md","at":"2026-09-20T05:06:03.753Z"}
{"type":"goal_archived","goalId":"mu986lbo-140zqa","archivePath":".pi/goals/archived/goal_2026091923060370_mu986lbo-140zqa.md","at":"2026-09-20T05:06:03.755Z"}

View File

@ -82,22 +82,158 @@
},
"enemyTypes": {
"_comment": "The hostile roster a WAVE (combat.waves.scripts) can mix — js/combat/EnemyTypes.js deep-merges a type's overrides onto the base `enemy` above, so a type declares only what differs. `raider` is the base craft under a named id (waves write it explicitly); `bomber` rides the same sheet on frame 1 — a slower, tougher, longer-reach striker. Add a craft here (a new `frame` or its own `texture` + stat overrides) and name it in a wave's roster; EnemyTypes.enemySheetList() is the preload seam for its textures. Each type's `xp` = what a kill of it is worth (default: the base enemy.xp — the rule of thumb is (hull+shields)/5, rounded, so a tougher craft is worth more of the XP bank).",
"_comment": "The hostile roster a WAVE (combat.waves.scripts) can mix — js/combat/EnemyTypes.js deep-merges a type's overrides onto the base `enemy` above, so a type declares only what differs. `raider` is the base craft under a named id (frame 0). Frames 1–7 are the SEVEN new hostiles, each a distinct craft with a distinct WEAPON PATTERN (weapon.pattern) and a MODERATE difficulty step-up: hull/shields (armor to soak) climb monotonically bomber → warden, so each is a little harder to defeat than the last. PATTERNS (js/combat/Weapons.js): 'lance' (the default — one aimed bolt, the base behavior), 'spray' (a FAN of `bolts` spread over `fan` rad), 'burst' (a TIGHT `bolts`-shot stinger — staggered speeds so it fans over distance), 'rapid' (single bolts on a short cooldown — a machine gun), 'ring' (`bolts` fired RADIAL around the craft — break the orbit), 'missile' (`missiles` HEAT-SEEKING shots that home with a CAPPED turn-rate (missileTurn rad/s) so the player can out-turn them), 'combo' (a heavy lance + a missile, the elite). Add a craft here (a new `frame` or its own `texture` + stat overrides) and name it in a wave's roster; EnemyTypes.enemySheetList() is the preload seam for its textures. Each type's `xp` = what a kill of it is worth (the rule of thumb is (hull+shields)/5, rounded, so a tougher craft is worth more of the XP bank).",
"raider": {
"frame": 0
},
"bomber": {
"_comment": "frame 1 — the LONG LANCE: slow, sits back, one heavy bolt on a long fuse. The easy end of the new ramp.",
"frame": 1,
"speed": 110,
"speed": 105,
"turn": 2.2,
"hull": 80,
"shields": 10,
"xp": 18,
"weapon": {
"pattern": "lance",
"range": 760,
"cooldown": 2.0,
"bulletSpeed": 250,
"damage": 10,
"spread": 0.04,
"bulletLife": 3.0
}
},
"spitter": {
"_comment": "frame 2 — the SPRAY: a fan of cheap bolts covering an arc; low damage per bolt, wide cone.",
"frame": 2,
"speed": 130,
"turn": 3.0,
"hull": 90,
"shields": 20,
"xp": 22,
"weapon": {
"pattern": "spray",
"range": 480,
"cooldown": 1.9,
"bulletSpeed": 300,
"damage": 11,
"spread": 0.03,
"bulletLife": 2.2,
"bolts": 5,
"fan": 1.1,
"color": "#ff7a3d"
}
},
"stinger": {
"_comment": "frame 3 — the BURST: a fast, tight 3-shot stinger at close range (staggered speeds fan it out over distance).",
"frame": 3,
"speed": 185,
"turn": 4.0,
"hull": 100,
"shields": 25,
"xp": 25,
"weapon": {
"range": 720,
"cooldown": 1.8,
"pattern": "burst",
"range": 400,
"cooldown": 1.5,
"bulletSpeed": 420,
"damage": 12,
"spread": 0.02,
"bulletLife": 1.8,
"bolts": 3,
"burstFan": 0.10,
"color": "#ffe14d"
}
},
"hunter": {
"_comment": "frame 4 — the HUNTER: launches a HEAT-SEEKING missile that homes with a capped turn-rate (missileTurn) — dodgeable by out-turning it.",
"frame": 4,
"speed": 150,
"turn": 3.2,
"hull": 110,
"shields": 30,
"xp": 28,
"weapon": {
"pattern": "missile",
"range": 620,
"cooldown": 2.4,
"missiles": 1,
"missileSpeed": 190,
"missileTurn": 2.2,
"missileDamage": 13,
"missileLife": 4.0,
"missileColor": "#ff5d2d",
"missileSize": 18,
"color": "#ff5d2d"
}
},
"gunner": {
"_comment": "frame 5 — the GUNNER: rapid single bolts on a short cooldown (a machine gun); solid per-bolt punch at a high rate.",
"frame": 5,
"speed": 190,
"turn": 4.2,
"hull": 120,
"shields": 40,
"xp": 32,
"weapon": {
"pattern": "rapid",
"range": 440,
"cooldown": 0.5,
"bulletSpeed": 380,
"damage": 14,
"spread": 0.06,
"bulletLife": 1.6,
"color": "#c8ff3d"
}
},
"barrage": {
"_comment": "frame 6 — the BARRAGE: a RADIAL ring of bolts (break the orbit); slow and armored, pokes a hole in the ring.",
"frame": 6,
"speed": 100,
"turn": 2.0,
"hull": 135,
"shields": 50,
"xp": 37,
"weapon": {
"pattern": "ring",
"range": 360,
"cooldown": 2.2,
"bulletSpeed": 260,
"damage": 12
"damage": 15,
"spread": 0.0,
"bulletLife": 2.6,
"bolts": 8,
"color": "#b44dff"
}
},
"warden": {
"_comment": "frame 7 — the WARDEN (elite): a heavy lance PLUS a homing missile on every volley; the hardest of the seven.",
"frame": 7,
"speed": 90,
"turn": 1.8,
"hull": 150,
"shields": 60,
"xp": 42,
"weapon": {
"pattern": "combo",
"range": 700,
"cooldown": 2.6,
"bulletSpeed": 240,
"damage": 18,
"spread": 0.02,
"bulletLife": 3.2,
"size": 20,
"boltLength": 64,
"boltWidth": 14,
"missiles": 1,
"missileSpeed": 170,
"missileTurn": 2.4,
"missileDamage": 20,
"missileLife": 4.2,
"missileColor": "#ff2d6f",
"missileSize": 20,
"color": "#ff2d6f"
}
}
},
@ -131,6 +267,22 @@
"maxConcurrent": 3,
"replacePerKill": 1
}
],
"combat_demo": [
{
"$comment": "?COMBAT DEMO (the tuning sandbox's boot — GameScene._wantsCombatDemo): a SEQUENCE of rolling waves, ONE per new hostile type in DIFFICULTY ORDER (bomber → warden, frames 1–7). Each wave is SIX of that single type, THREE on screen at a time (maxConcurrent), each kill sending in a replacement (replacePerKill) until the six are down — then the NEXT type's wave. This is the showcase for the seven new weapons (js/combat/Weapons.js).",
"kind": "rolling",
"type": "bomber",
"count": 6,
"maxConcurrent": 3,
"replacePerKill": 1
},
{ "kind": "rolling", "type": "spitter", "count": 6, "maxConcurrent": 3, "replacePerKill": 1 },
{ "kind": "rolling", "type": "stinger", "count": 6, "maxConcurrent": 3, "replacePerKill": 1 },
{ "kind": "rolling", "type": "hunter", "count": 6, "maxConcurrent": 3, "replacePerKill": 1 },
{ "kind": "rolling", "type": "gunner", "count": 6, "maxConcurrent": 3, "replacePerKill": 1 },
{ "kind": "rolling", "type": "barrage", "count": 6, "maxConcurrent": 3, "replacePerKill": 1 },
{ "kind": "rolling", "type": "warden", "count": 6, "maxConcurrent": 3, "replacePerKill": 1 }
]
}
},

353
dev/combat-demo-check.mjs Normal file
View File

@ -0,0 +1,353 @@
/**
* Dev-only: the SEVEN-SHIP VERIFICATION (headless, CDP) — the "manual
* playtest" on rails.
*
* node dev/combat-demo-check.mjs
*
* Two parts, both through the PRODUCTION code:
*
* A) THE RANGE (/combat) — every one of the seven new types
* (data/combat.json → enemyTypes, frames 1–7) is spawned via the
* real EnemyShip + enemyTypeConfig, fired once through the shared
* dispatch (CombatScene.fireEnemy → js/combat/Weapons.js →
* firePattern), and the volley's SHAPE is checked:
* bomber (lance) one aimed bolt
* spitter (spray) five bolts inside the ±fan/2 cone
* stinger (burst) three bolts, staggered speeds (the snap)
* hunter (missile) one heat-seeker, CAPPED turn (dodgeable)
* gunner (rapid) one bolt (its rapidity is the short cooldown)
* barrage (ring) eight bolts, evenly around 2π
* warden (combo) a bolt AND a heat-seeker
*
* B) THE MAIN GAME (index.html?combat) — the new boot path for real:
* the run starts on the menu, startNewGame() enters it, and the
* combat_demo script must land all SEVEN waves in difficulty order
* (bomber → warden), exactly THREE on screen at a time, one
* replacement per kill until the six-ship force is spent
* (3 → 3 → 3 → 2 → 1 → 0), with each wave's pattern firing through
* the shared path (the 'fire' / 'missile_fire' SFX beats), ending
* 'done' at 42 kills (7 × 6). The player is made unkillable for the
* run (a stray ring can't respawn it mid-wave and poison the counts)
* — the waves and the patterns are what's under test.
*
* Requires: the dev server on :8080 (node dev/server.mjs 8080) and a
* headless Chromium/Brave with CDP on 127.0.0.1:9333 (see
* dev/cdp-shot.mjs / dev/combat.sfxcheck.mjs).
*/
const CDP = process.env.CDP_PORT ? `127.0.0.1:${process.env.CDP_PORT}` : '127.0.0.1:9333';
const BASE = process.env.BASE_URL ?? 'http://127.0.0.1:8080';
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
function connect(target) {
const ws = new WebSocket(target.webSocketDebuggerUrl);
let id = 0;
const pending = new Map();
ws.onmessage = (x) => {
const m = JSON.parse(x.data);
if (m.id && pending.has(m.id)) {
const { res, rej } = pending.get(m.id);
pending.delete(m.id);
m.error ? rej(new Error(m.error.message)) : res(m.result);
}
};
const open = new Promise((r) => {
ws.onopen = r;
ws.onerror = () => r();
});
const send = (method, params = {}) =>
new Promise((res, rej) => {
const mid = ++id;
pending.set(mid, { res, rej });
ws.send(JSON.stringify({ id: mid, method, params }));
});
return { ws, send, open };
}
async function evalJs(c, expression, awaitPromise = true) {
const r = await c.send('Runtime.evaluate', { expression, returnByValue: true, awaitPromise });
if (r.exceptionDetails) throw new Error(JSON.stringify(r.exceptionDetails, null, 2));
return r.result?.value;
}
async function openPage(path) {
const url = `${BASE}${path}`;
let target;
try {
target = await (await fetch(`http://${CDP}/json/new?${encodeURIComponent(url)}`, { method: 'PUT' })).json();
} catch {
target = await (await fetch(`http://${CDP}/json/new?${encodeURIComponent(url)}`, { method: 'POST' })).json();
}
const c = connect(target);
await c.open;
await c.send('Runtime.enable');
return { c, target };
}
// ---------------------------------------------------------------- the plan
// (data/combat.json → enemyTypes, difficulty order — hulls are distinct
// per wave, so a wave is identifiable by maxHull + pattern.)
const ROT_SPEED = 6.4; // combat.player.rotSpeed — the dodge-rule reference
const PLAN = [
{ id: 'bomber', hull: 80, pattern: 'lance', bolts: 1, missiles: 0 },
{ id: 'spitter', hull: 90, pattern: 'spray', bolts: 5, missiles: 0 },
{ id: 'stinger', hull: 100, pattern: 'burst', bolts: 3, missiles: 0 },
{ id: 'hunter', hull: 110, pattern: 'missile', bolts: 0, missiles: 1 },
{ id: 'gunner', hull: 120, pattern: 'rapid', bolts: 1, missiles: 0 },
{ id: 'barrage', hull: 135, pattern: 'ring', bolts: 8, missiles: 0 },
{ id: 'warden', hull: 150, pattern: 'combo', bolts: 1, missiles: 1 },
];
const wrap = (a) => Math.atan2(Math.sin(a), Math.cos(a));
const dOf = (a, aim) => wrap(a - aim);
/** The shared shape check — the range's volley and the main game's, alike. */
function checkShape(exp, info, aim) {
if (info.pattern !== exp.pattern) return `pattern '${info.pattern}' != '${exp.pattern}'`;
if (info.bolts !== exp.bolts) return `bolts ${info.bolts} != ${exp.bolts}`;
if (info.missiles !== exp.missiles) return `missiles ${info.missiles} != ${exp.missiles}`;
if (exp.pattern === 'spray') {
const half = 1.1 / 2 + 0.06; // weapon.fan/2 + the aim jitter (0.03) + eps
if (info.angles.some((a) => Math.abs(dOf(a, aim)) > half)) return 'a spray bolt escaped the fan';
}
if (exp.pattern === 'ring') {
const ang = [...info.angles].sort((x, y) => x - y);
for (let i = 0; i < ang.length; i++) {
const gap = i === ang.length - 1 ? 2 * Math.PI + ang[0] - ang[i] : ang[i + 1] - ang[i];
if (Math.abs(gap - (2 * Math.PI / 8)) > 0.07) return `ring gap ${gap.toFixed(3)} != ${(2 * Math.PI / 8).toFixed(3)}`;
}
}
if (exp.pattern === 'burst') {
const s = (info.speeds || []).filter(Number.isFinite).sort((x, y) => x - y);
if (s.length !== 3 || s[2] - s[0] < 0.05 * s[1]) return 'the burst speeds are not staggered';
}
for (const t of info.turns || []) {
if (!(t > 0 && t < ROT_SPEED)) return `missile turn ${t} is not under the player's ${ROT_SPEED} rad/s (the dodge rule)`;
}
return null;
}
// ---------------------------------------------------------------- part A
const RANGE_CODE = `(async () => {
const scene = window.game && window.game.scene.getScene('CombatScene');
if (!scene || !scene.ship) return 'no CombatScene';
const [shipMod, typeMod] = await Promise.all([
import('/js/combat/EnemyShip.js'),
import('/js/combat/EnemyTypes.js'),
]);
const px = scene.ship.x, py = scene.ship.y;
const liveBolts = () => scene.bullets.filter((b) => !b.dead);
const liveMs = () => (scene.missiles || []).filter((m) => !m.dead);
const out = [];
const ids = ${JSON.stringify(PLAN.map((p) => p.id))};
for (const id of ids) {
const cfg = typeMod.enemyTypeConfig(id);
const e = new shipMod.EnemyShip(scene, px + 260, py, 9000, cfg);
e.setDepth(10);
e.orbitAngle = Math.PI / 2;
e.nextFireAt = 1e12; // never volunteer — this check drives the shot
scene.enemies.push(e);
const b0 = liveBolts().length;
const m0 = liveMs().length;
const aim = Math.atan2(py - e.y, px - e.x);
const pattern = scene.fireEnemy(e); // the shared dispatch (Weapons.js)
const bolts = liveBolts().slice(b0);
const ms = liveMs().slice(m0);
out.push({
id, pattern, aim,
bolts: bolts.length,
angles: bolts.map((b) => b.angle0),
speeds: bolts.map((b) => (b.body && b.body.velocity) ? Math.hypot(b.body.velocity.x, b.body.velocity.y) : null),
missiles: ms.length,
turns: ms.map((m) => m.turnRate),
hull: e.maxHull,
});
e.dead = true;
const ix = scene.enemies.indexOf(e);
if (ix >= 0) scene.enemies.splice(ix, 1);
}
return out;
})()`;
async function runRange() {
const { c, target } = await openPage('/combat');
try {
let ready = false;
for (let i = 0; i < 80; i++) {
await sleep(500);
try { ready = await evalJs(c, 'Boolean(window.game && window.game.scene.getScene("CombatScene") && window.game.scene.getScene("CombatScene").ship)', false); } catch { ready = false; }
if (ready) break;
}
if (!ready) throw new Error('range never booted');
await sleep(600);
const rows = await evalJs(c, RANGE_CODE);
if (!Array.isArray(rows)) throw new Error(`range drive failed: ${rows}`);
const bad = [];
for (const row of rows) {
const exp = PLAN.find((p) => p.id === row.id);
if (!exp) { bad.push(`${row.id}: not in the plan`); continue; }
if (row.hull !== exp.hull) bad.push(`${row.id}: hull ${row.hull} != ${exp.hull}`);
const shapeErr = checkShape(exp, row, row.aim);
if (shapeErr) bad.push(`${row.id}: ${shapeErr}`);
}
if (bad.length) throw new Error(bad.join(' · '));
console.log('range : all 7 types fire their pattern with the right shape (lance / spray / burst / missile / rapid / ring / combo)');
return true;
} catch (err) {
console.error(`range : FAIL — ${err.message}`);
return false;
} finally {
try { await fetch(`http://${CDP}/json/close/${target.id}`).catch(() => {}); } catch { /* ignore */ }
c.ws.close();
}
}
// ---------------------------------------------------------------- part B
const MAIN_CODE = `(async () => {
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const oc = window.__ORBIT_COMBAT__;
if (!oc) return 'no hook';
const sys = oc.system;
// Isolate the WAVE LOGIC under test: the main game AUTO-FIRES at the
// nearest hostile in range (CombatSystem.autoFire) — left on, the
// player's tracers kill the wave's ships on their own and the run
// races ahead of this scripted check. Off, the run is driven exactly
// as the Node suite drives it (kill → replacement → drain → next).
if (sys.autoFire) sys.autoFire.enabled = false;
// Unkillable for the run — the waves and the patterns are what's under
// test, and a respawn mid-wave would poison the on-screen counts.
sys.maxHull = 1e9; sys.hull = 1e9; sys.maxShields = 1e9; sys.shields = 1e9;
const live = () => sys.enemies.filter((e) => !e.dead);
// The ACK PAUSE CONTRACT (js/comms/CommsHub.js): an 'ack' comm — the
// fresh-save welcome lands seconds into a new run — holds its box open
// and FREEZES THE ACTION (GameScene gates combat.update on it) until
// the player presses ACKNOWLEDGE. This scripted check plays the part
// of the player: whenever the pause holds, press the button — the
// box's own onAck path (CommsHub._ack, the same call its button makes).
const gs = window.game && window.game.scene ? window.game.scene.getScene('GameScene') : null;
const ackIfPaused = () => {
try {
if (gs && gs.comms && gs.comms.paused) gs.comms._ack();
} catch { /* the box is gone — the pause is gone with it */ }
};
ackIfPaused(); // the welcome may already be holding the box at boot
const sfxLog = () => (window.__COMBAT_SFX__ && window.__COMBAT_SFX__.log) || [];
const out = { waves: [], state: null, kills: null };
const plan = ${JSON.stringify(PLAN)};
for (let i = 0; i < plan.length; i++) {
const exp = plan[i];
let deployed = false;
for (let t0 = Date.now(); Date.now() - t0 < 20000 && !deployed; await sleep(150)) {
ackIfPaused(); // a comm may land while we wait — answer it
const a = live();
deployed = a.length === 3 && a.every((e) => e.maxHull === exp.hull && ((e.wpn && e.wpn.pattern) || 'lance') === exp.pattern);
}
if (!deployed) { out.waves.push({ id: exp.id, fail: 'wave did not deploy (3 on screen, right type)' }); return out; }
out.waves.push({ id: exp.id, deployed: 3, onScreen: 3 }); // 3 on screen at the start
// Drive one shot through the production dispatch + read the shape.
const e = live()[0];
const logLen = sfxLog().length;
const b0 = sys.bullets.filter((b) => !b.dead).length;
const m0 = (sys.missiles || []).filter((m) => !m.dead).length;
const aim = Math.atan2(sys.ship.y - e.y, sys.ship.x - e.x);
const fired = sys.fireEnemy(e, sys.ship, sys._now());
const bolts = sys.bullets.filter((b) => !b.dead).slice(b0);
const ms = (sys.missiles || []).filter((m) => !m.dead).slice(m0);
const log = sfxLog().slice(logLen);
out.waves[out.waves.length - 1].shot = {
pattern: fired, aim,
bolts: bolts.length,
angles: bolts.map((b) => b.angle0),
speeds: bolts.map((b) => (b.body && b.body.velocity) ? Math.hypot(b.body.velocity.x, b.body.velocity.y) : null),
missiles: ms.length,
turns: ms.map((m) => m.turnRate),
sfx: [...new Set(log.map((x) => x.event))],
};
// Kill the wave's six: a replacement rides the first three kills, then
// the force drains (3 → 3 → 3 → 2 → 1 → 0).
const drains = [3, 3, 3, 2, 1, 0];
for (let k = 0; k < 6; k++) {
ackIfPaused(); // a comm may land mid-wave — answer it
const t = live().find((x) => x.maxHull === exp.hull);
if (!t) { out.waves[out.waves.length - 1].fail = 'no ship to kill at step ' + k; return out; }
t.damage(9999);
sys.killEnemy(t, sys._now());
await sleep(150);
const n = live().length;
if (n !== drains[k]) { out.waves[out.waves.length - 1].fail = 'after kill ' + (k + 1) + ': ' + n + ' on screen, expected ' + drains[k]; return out; }
out.waves[out.waves.length - 1].onScreen = n; // the cap holds, then the drain
}
}
for (let t0 = Date.now(); Date.now() - t0 < 10000; await sleep(200)) {
ackIfPaused();
const st = sys.waveStatus();
if (st && st.state === 'done') { out.state = st.state; break; }
}
out.kills = sys.kills;
return out;
})()`;
async function runMain() {
const { c, target } = await openPage('/index.html?combat');
try {
let ready = false;
for (let i = 0; i < 80; i++) {
await sleep(500);
try { ready = await evalJs(c, 'Boolean(window.game)', false); } catch { ready = false; }
if (ready) break;
}
if (!ready) throw new Error('game never booted');
// Enter the run (the main game boots on the menu).
const started = await evalJs(c, `(async () => {
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
for (let i = 0; i < 120; i++) {
const m = window.game && window.game.scene && window.game.scene.getScene('MenuScene');
if (m && typeof m.seedValue === 'string') { m.startNewGame(); return 'started'; }
await sleep(500);
}
return 'menu never ready';
})()`);
if (started !== 'started') throw new Error(`start: ${started}`);
let scoped = false;
for (let i = 0; i < 60; i++) {
await sleep(500);
try { scoped = await evalJs(c, 'Boolean(window.__ORBIT_COMBAT__)', false); } catch { scoped = false; }
if (scoped) break;
}
if (!scoped) throw new Error('combat scope never appeared');
await sleep(600);
const out = await evalJs(c, MAIN_CODE);
if (!out || out.state === undefined) throw new Error(`main drive failed: ${JSON.stringify(out)}`);
const bad = [];
for (const w of out.waves) {
const exp = PLAN.find((p) => p.id === w.id);
if (w.fail) { bad.push(`${w.id}: ${w.fail}`); continue; }
if (exp && w.shot) {
const shapeErr = checkShape(exp, w.shot, w.shot.aim);
if (shapeErr) bad.push(`${w.id}: ${shapeErr}`);
const wantSfx = exp.pattern === 'missile' || exp.pattern === 'combo' ? 'missile_fire' : 'fire';
if (!(w.shot.sfx || []).includes(wantSfx)) bad.push(`${w.id}: SFX beat '${wantSfx}' missing (got ${w.shot.sfx})`);
}
}
if (out.state !== 'done') bad.push(`run state '${out.state}' != 'done'`);
if (out.kills !== 42) bad.push(`kills ${out.kills} != 42`);
if (bad.length) throw new Error(bad.join(' · '));
console.log('main : 7 waves in difficulty order, 3 on screen, a replacement per kill, all patterns fired, done at 42 kills');
return true;
} catch (err) {
console.error(`main : FAIL — ${err.message}`);
return false;
} finally {
try { await fetch(`http://${CDP}/json/close/${target.id}`).catch(() => {}); } catch { /* ignore */ }
c.ws.close();
}
}
// ---------------------------------------------------------------- main
const results = [await runRange(), await runMain()];
if (results.every(Boolean)) {
console.log('seven ships: PASS (the range renders all seven patterns; the ?combat boot runs all seven waves)');
process.exit(0);
} else {
console.log('seven ships: FAIL');
process.exit(1);
}

View File

@ -75,6 +75,18 @@ function driveScript(scopeExpr, withLevelUp = false) {
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const scope = ${scopeExpr};
if (!scope) return 'no scope';
// Wait for a LIVE hostile before driving the enemy-dependent events.
// The main game's ?combat boot now runs the 7-wave demo script — the
// first wave lands after its lead-in, so "fire / hit / kill" can't be
// driven before a ship deploys. (The range packs instantly; live() is
// already true there.)
if (scope.live) {
const liveDeadline = Date.now() + 15000;
while (Date.now() < liveDeadline && !scope.live()) await sleep(200);
if (!scope.live()) return 'no live hostile after 15 s';
}
const driveLevelUp = ${Boolean(withLevelUp)}; // injected at build time
const logBefore = (window.__COMBAT_SFX__ && window.__COMBAT_SFX__.log || []).length;
@ -166,6 +178,7 @@ const scopeRange = `(() => {
const scene = window.game.scene.getScene('CombatScene');
const cfg = window.config;
return {
live: () => scene.enemies.some((e) => !e.dead),
fire: () => scene.firePlayer(0, cfg.section('combat.player.weapon', {})),
hitEnemy: () => {
const e = scene.enemies.find((x) => !x.dead);
@ -200,6 +213,7 @@ const scopeMain = `(() => {
if (!oc) return null;
const sys = oc.system;
return {
live: () => sys.enemies.some((e) => !e.dead),
fire: () => {
const t = sys.nearestEnemy(sys.ship.x, sys.ship.y);
if (t) sys.firePlayerAt(sys.ship, t, sys._now());

View File

@ -166,7 +166,10 @@ for (const f of fs.readdirSync(dataDir)) {
config.init(configData);
console.log('config loaded from data/:', Object.keys(configData).join(', '));
const { applyDamage, headingOf, orbitStep, handleFeel, pickTarget, feedPush, offscreenArrow, inView } = await import(
const {
applyDamage, headingOf, orbitStep, handleFeel, pickTarget, feedPush, offscreenArrow, inView,
wrapAngle, fanAngles, ringAngles, homingStep,
} = await import(
pathToFileURL(join(__dirname, '../js/combat/Combat.js')).href
);
const { EnemyShip } = await import(pathToFileURL(join(__dirname, '../js/combat/EnemyShip.js')).href);
@ -177,6 +180,10 @@ const { normalizeWaves, resolveRoster, WaveRunner } = await import(
pathToFileURL(join(__dirname, '../js/combat/Waves.js')).href
);
const { Bullet } = await import(pathToFileURL(join(__dirname, '../js/combat/Bullet.js')).href);
const { Missile } = await import(pathToFileURL(join(__dirname, '../js/combat/Missile.js')).href);
const { firePattern, patternOf, stepMissiles, missilesHitPlayer } = await import(
pathToFileURL(join(__dirname, '../js/combat/Weapons.js')).href
);
const { CombatSystem } = await import(pathToFileURL(join(__dirname, '../js/combat/CombatSystem.js')).href);
const { CombatHud } = await import(pathToFileURL(join(__dirname, '../js/combat/CombatHud.js')).href);
const {
@ -610,9 +617,9 @@ const E = (k, d) => config.get(`combat.enemy.${k}`, d);
};
const sfxNames = config.get('sfx') ?? {};
check('sfx: the ten combat events, each mapped',
check('sfx: the eleven combat events, each mapped',
Object.keys(COMBAT_SFX).sort().join(',') ===
'cannon_fire,cannon_hit,down,fire,hull,impact,kill,levelup,respawn,shield');
'cannon_fire,cannon_hit,down,fire,hull,impact,kill,levelup,missile_fire,respawn,shield');
check('sfx: every mapped voice exists in data/sfx.json',
Object.values(COMBAT_SFX).flat().every((n) => typeof sfxNames[n] === 'string'));
@ -785,17 +792,32 @@ const E = (k, d) => config.get(`combat.enemy.${k}`, d);
{
const base = enemyTypeConfig();
check('types: the base craft = combat.enemy (shipped)', base.hull === E('hull', 60) && base.frame === 0 && base.weapon.range === E('weapon.range', 560));
check('types: the shipped roster is raider + bomber', enemyTypeIds().join(',') === 'raider,bomber');
check('types: the shipped roster = raider + the seven new types (frames 0–7)',
enemyTypeIds().join(',') === 'raider,bomber,spitter,stinger,hunter,gunner,barrage,warden');
const rosterOrder = ['bomber', 'spitter', 'stinger', 'hunter', 'gunner', 'barrage', 'warden'];
check('types: frames 1–7 are distinct (one per sheet frame)',
rosterOrder.every((id, i) => enemyTypeConfig(id).frame === i + 1));
check('types: each new type declares a distinct weapon pattern',
JSON.stringify(rosterOrder.map((id) => enemyTypeConfig(id).weapon.pattern)) ===
JSON.stringify(['lance', 'spray', 'burst', 'missile', 'rapid', 'ring', 'combo']));
const shotDmg = (t) => Math.max(t.weapon.damage ?? 0, t.weapon.missileDamage ?? 0);
const climbs = (get) =>
rosterOrder.slice(1).every((id, i) => get(enemyTypeConfig(id)) > get(enemyTypeConfig(rosterOrder[i])));
check('types: difficulty climbs monotonically bomber → warden (hull, shields, per-shot damage)',
climbs((t) => t.hull) && climbs((t) => t.shields) && climbs(shotDmg));
const raider = enemyTypeConfig('raider');
check('types: raider = the base craft under a named id', raider.frame === 0 && raider.hull === base.hull && raider.weapon.range === base.weapon.range);
const bomber = enemyTypeConfig('bomber');
check('types: bomber overrides merge onto the base',
bomber.frame === 1 && bomber.speed === 110 && bomber.hull === 90 && bomber.shields === 20 &&
bomber.weapon.range === 720 && bomber.weapon.cooldown === 1.8 && bomber.weapon.damage === 12);
bomber.frame === 1 && bomber.speed === 105 && bomber.hull === 80 && bomber.shields === 10 &&
bomber.weapon.pattern === 'lance' && bomber.weapon.range === 760 &&
bomber.weapon.cooldown === 2.0 && bomber.weapon.damage === 10);
check('types: bomber inherits what it does not set',
bomber.weapon.spread === base.weapon.spread && bomber.weapon.bulletLife === base.weapon.bulletLife &&
bomber.weapon.color === base.weapon.color && bomber.weapon.size === base.weapon.size &&
bomber.weapon.boltLength === base.weapon.boltLength && bomber.weapon.boltWidth === base.weapon.boltWidth &&
bomber.ramDamage === base.ramDamage && bomber.hitRadius === base.hitRadius && bomber.texture === base.texture);
const unknown = enemyTypeConfig('nope');
@ -807,8 +829,8 @@ const E = (k, d) => config.get(`combat.enemy.${k}`, d);
const scene = makeScene({ withSheet: true });
const b = new EnemyShip(scene, 0, 0, 0, bomber);
check('enemy type: a bomber flies with its own stats (frame 1, hull 90, same scale)',
b.frame === 1 && b.maxHull === 90 && b.maxShields === 20 && approx(b.scale, E('size', 54) / 128));
check('enemy type: a bomber flies with its own stats (frame 1, hull 80, same scale)',
b.frame === 1 && b.maxHull === 80 && b.maxShields === 10 && approx(b.scale, E('size', 54) / 128));
}
// ------------------------------------------------------------------- waves
@ -953,7 +975,7 @@ const E = (k, d) => config.get(`combat.enemy.${k}`, d);
const bombers = combat.enemies.filter((e) => e.wave && !e.dead);
check('waves/system: wave 2 deploys whole (fixed: the force at once)', bombers.length === 2);
check('waves/system: the roster type flies (bomber stats, not the base)',
bombers.every((e) => e.maxHull === 90 && e.frame === 1));
bombers.every((e) => e.maxHull === 80 && e.frame === 1));
for (const e of [...bombers]) { e.damage(999); combat.killEnemy(e, t + 48); }
combat.update(t + 64, 16);
@ -1044,6 +1066,238 @@ const E = (k, d) => config.get(`combat.enemy.${k}`, d);
check('fx: the purge covers the roster (not just tracked flashes)', straggler.tintMode === 0);
}
// ------------------------------------------------- combat geometry (pure)
{
check('geometry: wrapAngle folds into (-π, π]',
Math.abs(wrapAngle(3 * Math.PI) + Math.PI) < 1e-9 &&
Math.abs(wrapAngle(-3 * Math.PI) + Math.PI) < 1e-9 &&
wrapAngle(0.5) === 0.5);
check('geometry: fanAngles(1 shot) is the aim itself',
fanAngles(0, 1, 1.0).length === 1 && fanAngles(0, 1, 1.0)[0] === 0);
const f5 = fanAngles(0, 5, 1.0);
check('geometry: fanAngles(5) spans the arc, ends inclusive, evenly',
f5.length === 5 && f5.every((a, i) => Math.abs(a - (-0.5 + i * 0.25)) < 1e-9));
const r8 = ringAngles(8, 0);
check('geometry: ringAngles(8) = 8 shots evenly around 2π',
r8.length === 8 && r8.every((a, i) => Math.abs(a - i * Math.PI / 4) < 1e-9));
check('geometry: homingStep with no turn budget holds the heading',
homingStep(0, 0, 0, 100, 0, 1, 0) === 0);
check('geometry: the homing turn is capped at turnRate×dt (the dodge rule)',
Math.abs(homingStep(0, 0, 0, 0, 100, 2.0, 0.05) - 0.1) < 1e-9);
check('geometry: a close target is reached exactly (no overshoot)',
homingStep(0, 0, 0, 10, 0.5, 2.0, 0.05) === Math.atan2(0.5, 10));
}
// ------------------------------------------------- weapons: the seven patterns
{
const scene = makeScene({ withSheet: true });
scene.sound = { play: () => {} };
scene.cache = { audio: { has: () => true } };
const mkHost = () => ({
scene,
fx: { muzzle: () => {}, flash: () => {}, explode: () => {} },
missiles: [],
bolts: [],
spawnBullet(x, y, a, wpn, owner) { this.bolts.push({ x, y, a, wpn, owner }); },
hitsSwept: () => false,
playerHits: [],
damagePlayer(d, o) { this.playerHits.push({ d, o }); },
});
const ship = { x: 0, y: 0, hitRadius: 20 };
const player = { x: 100, y: 0 }; // sits straight along +x — the aim is 0
check('weapons: patternOf defaults to the base lance',
patternOf(undefined) === 'lance' && patternOf({}) === 'lance' &&
patternOf({ pattern: 'spray' }) === 'spray');
{
const h = mkHost();
const kind = firePattern(h, ship, player, { spread: 0 });
check('weapons: lance = one bolt, aimed exactly at the player (zero spread)',
kind === 'lance' && h.bolts.length === 1 && h.bolts[0].owner === 'enemy' &&
Math.abs(h.bolts[0].a) < 1e-9 && h.missiles.length === 0);
}
{
const h = mkHost();
const wpn = enemyTypeConfig('spitter').weapon;
const kind = firePattern(h, ship, player, wpn);
const span = Math.max(...h.bolts.map((b) => b.a)) - Math.min(...h.bolts.map((b) => b.a));
check('weapons: spray = a fan of five bolts (spitter)',
kind === 'spray' && h.bolts.length === 5 && h.missiles.length === 0);
check('weapons: the fan holds its width (± the aim jitter)',
span >= wpn.fan - 0.065 && span <= wpn.fan + 0.065);
}
{
const h = mkHost();
const wpn = enemyTypeConfig('stinger').weapon;
const kind = firePattern(h, ship, player, wpn);
const speeds = h.bolts.map((b) => b.wpn.bulletSpeed);
const span = Math.max(...h.bolts.map((b) => b.a)) - Math.min(...h.bolts.map((b) => b.a));
check('weapons: burst = a tight 3-shot stinger, staggered speeds (stinger)',
kind === 'burst' && h.bolts.length === 3 && new Set(speeds).size === 3 &&
span <= (wpn.burstFan ?? wpn.fan ?? 0.08) + 0.05);
}
{
const h = mkHost();
const wpn = enemyTypeConfig('barrage').weapon;
const kind = firePattern(h, ship, player, wpn);
const as = h.bolts.map((b) => b.a).sort((x, y) => x - y);
const even = as.length === 8 && as.every((a, i) => {
const next = i === 7 ? as[0] + Math.PI * 2 : as[i + 1];
return Math.abs(next - a - Math.PI / 4) < 1e-9;
});
check('weapons: ring = eight bolts evenly around the craft (barrage)', kind === 'ring' && even);
}
{
const h = mkHost();
const wpn = enemyTypeConfig('gunner').weapon;
const kind = firePattern(h, ship, player, wpn);
check('weapons: rapid = one bolt per trigger on a short cooldown (gunner)',
kind === 'rapid' && h.bolts.length === 1 && h.missiles.length === 0 && wpn.cooldown < 0.75);
}
{
const h = mkHost();
const wpn = enemyTypeConfig('hunter').weapon;
const kind = firePattern(h, ship, player, wpn);
const m = h.missiles[0];
check('weapons: missile = a heat-seeker, no bolts (hunter)',
kind === 'missile' && h.bolts.length === 0 && h.missiles.length === 1 && m !== undefined);
check('weapons: the seeker carries the dodge caps (turn < the player\'s 6.4 rad/s)',
m !== undefined && m.turnRate === wpn.missileTurn && m.turnRate < 6.4 &&
m.speed === wpn.missileSpeed && m.speed < 250 && m.damage === wpn.missileDamage);
}
{
const h = mkHost();
const wpn = enemyTypeConfig('warden').weapon;
const kind = firePattern(h, ship, player, wpn);
check('weapons: combo = the heavy bolt AND the missile (warden)',
kind === 'combo' && h.bolts.length === 1 && h.missiles.length === 1);
}
}
// ------------------------------------------------- weapons: the missile itself
{
const scene = makeScene({ withSheet: true });
const m = new Missile(scene, {
x: 0, y: 0, angle: 0, speed: 200, turnRate: 2.2, damage: 14, life: 4,
color: '#ff5d2d', size: 18,
});
check('missile: launches along its heading, world-sized, with a hit radius',
Math.abs(m.body.velocity.x - 200) < 1e-9 && Math.abs(m.body.velocity.y) < 1e-9 &&
m.radius >= 4 && m.radius <= 20);
const target = { x: 0, y: 100 }; // straight "down" — the desired heading is +π/2
const h0 = m.heading;
m.update(50, target); // dt 0.05 s → the turn budget is 0.11 rad
check('missile: the homing turn per step is CAPPED (dodgeable)',
m.heading > h0 && m.heading - h0 <= 2.2 * 0.05 + 1e-9);
const h1 = m.heading;
m.update(50, null); // the player is down — the seeker flies true
check('missile: no target → flies true on its heading', Math.abs(m.heading - h1) < 1e-9);
let steps = 0;
while (!m.dead && steps < 200) { m.update(50, null); steps += 1; }
check('missile: the fuse ends it after a few seconds of flight', m.dead === true && steps < 200);
check('missile: consume() is one-shot', m.consume() === false);
}
// ------------------------------------------------- weapons: step + hit passes
{
const scene = makeScene({ withSheet: true });
scene.sound = { play: () => {} };
scene.cache = { audio: { has: () => true } };
{
let flashes = 0;
const h = { scene, missiles: [], fx: { flash: () => { flashes += 1; }, explode: () => {} } };
h.missiles.push(new Missile(scene, {
x: 5, y: 100, angle: 0, speed: 100, turnRate: 1, damage: 10, life: 4, size: 16,
}));
stepMissiles(h, 16, null, { inset: 10, w: 400, h: 400 });
check('missiles: the arena wall eats a rocket (the range)', h.missiles.length === 0 && flashes === 1);
}
{
let booms = 0;
const h = {
scene, missiles: [],
fx: { flash: () => {}, explode: () => { booms += 1; } },
hitsSwept: () => true,
playerHits: [],
damagePlayer(d, o) { this.playerHits.push({ d, o }); },
};
h.missiles.push(new Missile(scene, {
x: 10, y: 10, angle: 0, speed: 100, turnRate: 1, damage: 14, life: 4, size: 16,
}));
missilesHitPlayer(h, { x: 12, y: 12 }, 12, 16);
check('missiles: a hit deals the missile damage, blooms, consumes',
h.playerHits.length === 1 && h.playerHits[0].d === 14 && booms === 1 && h.missiles.length === 0);
check('missiles: the hit bearing = the incoming direction',
Math.abs(h.playerHits[0].o.bearing - Math.PI) < 1e-9);
}
}
// ------------------------------------------------- the ?combat demo script
{
const r = normalizeWaves('combat_demo');
check('waves: the combat_demo script normalizes (7 rolling single-type waves)',
r.ok && r.waves.length === 7 &&
r.waves.every((w) =>
w.kind === 'rolling' && w.total === 6 && w.maxConcurrent === 3 && w.replacePerKill === 1));
const order = ['bomber', 'spitter', 'stinger', 'hunter', 'gunner', 'barrage', 'warden'];
check('waves: combat_demo order = difficulty (bomber → warden)',
r.ok && r.waves.map((w) => Object.keys(w.roster).join()).join(',') === order.join(','));
}
// ------------------------------------------------- the ?combat demo, end-to-end
{
const scene = makeScene({ withSheet: true });
const ship = scene.physics.add.existing(
new PhaserStub.Physics.Arcade.Sprite(scene, 0, 0, '__ship', 0));
ship.radius = 12;
ship.stop = () => {};
const events = { start: 0, clear: 0, complete: null };
const combat = new CombatSystem(scene, { ship, onKill: () => {} });
combat.autoFire.enabled = false; // the test asserts the RUN, not the guns
combat.startWaves('combat_demo', {
onWaveStart: () => { events.start += 1; },
onWaveClear: () => { events.clear += 1; },
onComplete: (s) => { events.complete = s; },
});
check('waves/system: the demo boot starts the 7-wave run (lead in flight)',
combat.waveStatus().state === 'lead' && combat.active === true);
let t = 0;
let okAll = true;
const liveNow = () => combat.enemies.filter((e) => e.wave && !e.dead);
for (let wave = 0; wave < 7; wave++) {
const frame = wave + 1;
for (let tries = 0; tries < 40 && liveNow().length < 3; tries++) {
t += 200;
combat.update(t, 16);
}
okAll = okAll && liveNow().length === 3 && liveNow().every((e) => e.frame === frame);
// 6 ships per wave, 3 on screen: the 3 replacements ride the first 3
// kills (replacePerKill = 1), then the force drains to zero.
const expectLen = [3, 3, 3, 2, 1, 0];
for (let k = 0; k < 6; k++) {
const e = liveNow().find((x) => x.frame === frame);
if (!e) { okAll = false; break; }
e.damage(999); // the real path is a tracer sweep → damage() → killEnemy
combat.killEnemy(e, t);
if (k < 5) {
combat.update(t, 16);
okAll = okAll && liveNow().length === expectLen[k]; // cap holds, then drains
}
}
t += 16;
combat.update(t, 16); // the clear bookkeeping
okAll = okAll && liveNow().length === 0; // the wave is spent
t += 16;
combat.update(t, 16); // the clear bookkeeping
}
check('waves/system: the demo runs all 7 waves in order, 3 on screen, a replacement per kill', okAll);
check('waves/system: the demo completes (42 kills = 7 × 6)',
combat.kills === 42 && combat.waveStatus().state === 'done' && events.complete !== null);
check('waves/system: the demo fires 7 starts + 7 clears', events.start === 7 && events.clear === 7);
}
// ------------------------------------------------------------------ done
console.log(failures === 0 ? '\ncombat rules: all checks passed' : `\n${failures} check(s) FAILED`);

View File

@ -104,6 +104,84 @@ export function headingOf(ship) {
return ship.rotation - (ship.artOffset || 0);
}
// ------------------------------------------------------- weapon geometry
//
// The pure geometry behind the hostile WEAPON PATTERNS (js/combat/
// Weapons.js dispatches on data/combat.json → weapon.pattern): the fan
// and ring angle sets, and the HEAT-SEEKING turn step. Pure, so the
// missile's dodge rule (a capped turn-rate) is testable in bare Node.
/** Wrap an angle to [-π, π) (mirror of Phaser.Math.Angle.Wrap). */
export function wrapAngle(a) {
const min = -Math.PI;
const range = Math.PI * 2;
return (((a - min) % range) + range) % range + min;
}
/**
* The FAN of a spray/burst volley: `count` shot angles spread over a
* total arc of `fan` rad, centered on `base`. count 1 = just `base`
* (a single bolt); the ends of the fan are inclusive. The caller adds
* its own aim jitter (weapon.spread) to each.
*
* @returns {number[]} the angles (rad), length `count`
*/
export function fanAngles(base, count, fan = 0) {
const n = Math.max(1, Math.floor(Number(count) || 1));
const f = Math.max(0, Number(fan) || 0);
if (n === 1) return [base];
const out = [];
for (let i = 0; i < n; i++) {
const t = i / (n - 1); // 0 → 1 across the volley
out.push(base - f / 2 + f * t);
}
return out;
}
/**
* The RING of a radial volley: `count` shots evenly around 2π, with a
* random `phase` so successive rings are never identical. A ring is
* symmetric (no center to aim at) — the caller's spread jitter still
* applies per bolt.
*
* @returns {number[]} the angles (rad), length `count`
*/
export function ringAngles(count, phase = 0) {
const n = Math.max(3, Math.floor(Number(count) || 8));
const p = Number(phase) || 0;
const out = [];
for (let i = 0; i < n; i++) out.push(p + (i * Math.PI * 2) / n);
return out;
}
/**
* One HEAT-SEEKING step (the missile's dodge rule, pure): turn the
* flight heading toward the target at AT MOST `turnRate` rad/s × dt —
* the cap is what makes the missile dodgeable (the player's sustained
* turn is combat.player.rotSpeed, comfortably above the missiles'
* missileTurn, so a hard pull out-turns the shot). With no target
* (the player is down) the heading holds and the missile flies true.
* Frame-rate independent: the step is bounded by turnRate×dt, and the
* exact-target case lands on the bearing with no overshoot.
*
* @param {number} heading the missile's current flight heading (rad)
* @param {number} sx the missile's x (world px)
* @param {number} sy the missile's y (world px)
* @param {number} tx the target's x
* @param {number} ty the target's y
* @param {number} turnRate the CAP on the turn rate (rad/s)
* @param {number} dt seconds
* @returns {number} the new heading (rad)
*/
export function homingStep(heading, sx, sy, tx, ty, turnRate, dt) {
if (turnRate <= 0 || dt <= 0) return heading;
const desired = Math.atan2(ty - sy, tx - sx);
const delta = wrapAngle(desired - heading);
const maxTurn = turnRate * dt;
if (Math.abs(delta) <= maxTurn) return desired;
return heading + Math.sign(delta) * maxTurn;
}
/**
* One step of the standoff-ring AI: advance the craft's orbit angle and
* return the point on the ring it should steer to (pure — the craft

View File

@ -13,6 +13,7 @@ import { Bullet } from './Bullet.js';
import { Fx, FX_COLORS, settleCraftTint } from './Fx.js';
import { StarDrift } from './StarDrift.js';
import { applyDamage, handleFeel, pickTarget } from './Combat.js';
import { firePattern, stepMissiles, missilesHitPlayer } from './Weapons.js';
import { combatSfx, combatSfxEnemyHit, loadCombatSfx } from './CombatSfx.js';
import { combatShake, ensureUiCameras, assignWorld } from './CamShake.js';
import { CombatHud } from './CombatHud.js';
@ -142,6 +143,9 @@ export class CombatScene extends Phaser.Scene {
}
this.bullets = [];
// The heat-seeker roster (js/combat/Weapons.js steps + hits them; the
// missiles themselves live in js/combat/Missile.js).
this.missiles = [];
this.fx = new Fx(this);
// The whiteness-purge roster: the purge (Fx.purgeCraftTints, every
// ~250 ms) must cover the WHOLE pack — a craft that somehow ends up
@ -251,6 +255,10 @@ export class CombatScene extends Phaser.Scene {
this.updatePlayer(time, delta);
this.updateEnemies(time, delta);
this.updateBullets(delta);
// The heat-seekers (js/combat/Weapons.js): age the fuses + home on the
// player (null while it's down — the shots fly true). The arena walls
// eat them, like the tracers.
stepMissiles(this, delta, this.playerDead ? null : this.ship, { inset: this.inset, w: this.w, h: this.h });
this.collide(delta);
this.fx.update(delta);
@ -404,16 +412,14 @@ export class CombatScene extends Phaser.Scene {
}
}
/**
* A hostile's weapon volley — the SHARED pattern dispatch (js/combat/Weapons.js)
* both combat contexts run: the base craft's 'lance' plus the seven new
* types' patterns (spray / burst / rapid / ring / missile / combo —
* data/combat.json → enemyTypes, weapon.pattern).
*/
fireEnemy(e) {
const wpn = e.wpn ?? {};
const toPlayer = Math.atan2(this.ship.y - e.y, this.ship.x - e.x);
const angle = toPlayer + (Math.random() * 2 - 1) * (Math.max(0, Number(wpn.spread) || 0));
const nose = e.hitRadius + 10;
const mx = e.x + Math.cos(toPlayer) * nose;
const my = e.y + Math.sin(toPlayer) * nose;
this.spawnBullet(mx, my, angle, wpn, 'enemy');
this.fx.muzzle(mx, my, angle, wpn.color ?? 0xff2d6f, Number(wpn.muzzle) || 50);
combatSfx(this, 'fire'); // the laser voice, at full volume (the player's cannon has its own voice)
return firePattern(this, e, this.ship, e.wpn ?? {});
}
killEnemy(e) {
@ -553,6 +559,9 @@ export class CombatScene extends Phaser.Scene {
if (b.consume()) this.bullets.splice(i, 1);
}
}
// Heat-seekers × player (js/combat/Weapons.js): the missile's damage
// lands from its incoming bearing; the hit blooms and consumes it.
if (!this.playerDead) missilesHitPlayer(this, this.ship, this.ship.radius, delta);
// Rams (player × enemies) — damage both, bounce both.
if (!this.playerDead) {
for (const e of this.enemies) {

View File

@ -19,6 +19,8 @@ import { playSfxOn, playSfxOneOfOn } from '../utils/Sfx.js';
* combat-laser.mp3 — the player's cannon
* plays cannon_fire; the laser plays at
* the same volume)
* missile_fire solar_flare_02 the rocket launch whoosh (the heat-seeker's
* distinct voice — the bolts play fire)
* impact ui_click the light tick of a tracer striking (the
* player being hit, wall ticks — a hostile
* taking the player's shot plays cannon_hit)
@ -40,6 +42,7 @@ export const COMBAT_SFX = {
cannon_fire: ['mass_cannon'],
cannon_hit: ['mass_cannon_hit'],
fire: ['laser'],
missile_fire: ['solar_flare_02'],
impact: ['ui_click'],
shield: ['solar_buzz'],
hull: ['mining_split'],

View File

@ -4,6 +4,7 @@ import { enemyTypeConfig } from './EnemyTypes.js';
import { Bullet } from './Bullet.js';
import { Fx, FX_COLORS, settleCraftTint } from './Fx.js';
import { applyDamage, inView, pickTarget } from './Combat.js';
import { firePattern, stepMissiles, missilesHitPlayer } from './Weapons.js';
import { XpManager } from './XpManager.js';
import { combatSfx, combatSfxEnemyHit } from './CombatSfx.js';
import { combatShake } from './CamShake.js';
@ -53,11 +54,12 @@ const TAU = Math.PI * 2;
* update" contract GameScene already runs on (the engine steps the
* arcade world itself).
*
* Lifecycle: spawnPack(cx, cy) starts the fight (the ?combat boot does
* this around the ship when the player starts); active flips on the
* first hostile / back off when the pack is wiped and not reforming —
* the scene uses onActiveChange to swap the action deck for the
* combat bar.
* Lifecycle: startWaves(script) starts the fight (the ?combat boot runs
* the 'combat_demo' seven-type sequence; the quest ambush runs its own
* script); spawnPack(cx, cy) still drops a one-shot practice pack;
* active flips on the first hostile / back off when the pack is wiped
* and not reforming — the scene uses onActiveChange to swap the action
* deck for the combat bar.
*/
export class CombatSystem {
/**
@ -84,6 +86,9 @@ export class CombatSystem {
this.enemies = [];
this.bullets = [];
// The heat-seeker roster (js/combat/Weapons.js steps + hits them; the
// missiles themselves live in js/combat/Missile.js).
this.missiles = [];
this.kills = 0;
// The wave run in flight (Waves.js — null when no script is running).
@ -520,6 +525,11 @@ export class CombatSystem {
if (b.dead) this.bullets.splice(i, 1);
}
// 3b) The heat-seekers (js/combat/Weapons.js): age the fuses + home on
// the player while it stands (fly true after it falls); the fuses
// end them. No walls here (the range clips its own).
stepMissiles(this, delta, this.playerDown ? null : player);
// 4) Collisions: your tracers × the pack, their lances × you, rams.
this.collide(delta, player);
@ -622,17 +632,14 @@ export class CombatSystem {
combatSfx(this.scene, 'cannon_fire'); // the mass-cannon voice (the enemy lances keep the blaster ping)
}
/** A hostile's lance at the player (aimed at the ship, spread-jittered). */
/**
* A hostile's weapon volley — the SHARED pattern dispatch (js/combat/Weapons.js)
* both combat contexts run: the base 'lance' plus the new types' patterns
* (spray / burst / rapid / ring / missile / combo — data/combat.json →
* enemyTypes, weapon.pattern).
*/
fireEnemy(e, player, time) {
const wpn = e.wpn ?? {};
const toPlayer = Math.atan2(player.y - e.y, player.x - e.x);
const a = toPlayer + (Math.random() * 2 - 1) * (Math.max(0, Number(wpn.spread) || 0));
const nose = e.hitRadius + 10;
const mx = e.x + Math.cos(a) * nose;
const my = e.y + Math.sin(a) * nose;
this.spawnBullet(mx, my, a, wpn, 'enemy');
this.fx.muzzle(mx, my, a, wpn.color ?? '#ff2d6f', Number(wpn.muzzle) || 50);
combatSfx(this.scene, 'fire'); // the laser voice, at full volume (the player's cannon has its own voice)
return firePattern(this, e, player, e.wpn ?? {});
}
spawnBullet(x, y, angle, wpn, owner) {
@ -717,6 +724,9 @@ export class CombatSystem {
}
}
}
// 2b) Heat-seekers × you (js/combat/Weapons.js): the missile's damage
// lands from its incoming bearing; the hit blooms + consumes it.
if (player) missilesHitPlayer(this, player, Number(player.radius) || 12, delta);
// Rams (you × the pack) — push apart, bounce, damage both (grace-limited).
if (player) {
for (const e of this.enemies) {

164
js/combat/Missile.js Normal file
View File

@ -0,0 +1,164 @@
import Phaser from '../vendor/phaser.js';
import { toColor } from '../utils/Color.js';
import { assignWorld } from '../visuals/UiCameras.js';
import { canvasTexture } from '../utils/Textures.js';
import { homingStep } from './Combat.js';
const TEX_KEY = '__combat_missile';
const TEX_W = 64;
const TEX_H = 32;
const BODY_LEN = 53; // the missile's drawn extent in texture px (x ≈ 10 → 63) — the world length = scale × BODY_LEN
/**
* The missile's art (white alpha, so the sprite's tint reads as the
* weapon's color): an exhaust bloom at the tail, twin fins, a slim
* capsule body, and a pointed nose with a hot core dot. Laid along +x,
* nose to the right (x = TEX_W is the tip) — the sprite rotates with
* the flight heading, exactly like the bolt.
*/
function drawMissile(ctx, w, h) {
const c = h / 2;
// 1) The exhaust bloom — a soft flame at the tail (left).
let g = ctx.createRadialGradient(9, c, 0, 9, c, 15);
g.addColorStop(0.0, 'rgba(255,255,255,1.0)');
g.addColorStop(0.45, 'rgba(255,255,255,0.5)');
g.addColorStop(1.0, 'rgba(255,255,255,0.0)');
ctx.fillStyle = g;
ctx.fillRect(0, 0, 26, h);
// 2) Twin fins at the tail.
ctx.fillStyle = 'rgba(255,255,255,0.85)';
ctx.beginPath();
ctx.moveTo(22, c - 3);
ctx.lineTo(9, c - 11);
ctx.lineTo(28, c - 3);
ctx.moveTo(22, c + 3);
ctx.lineTo(9, c + 11);
ctx.lineTo(28, c + 3);
ctx.fill();
// 3) The body capsule (bright core, soft edges top/bottom).
g = ctx.createLinearGradient(0, 0, 0, h);
g.addColorStop(0.0, 'rgba(255,255,255,0.30)');
g.addColorStop(0.5, 'rgba(255,255,255,0.95)');
g.addColorStop(1.0, 'rgba(255,255,255,0.30)');
ctx.fillStyle = g;
ctx.beginPath();
if (typeof ctx.roundRect === 'function') ctx.roundRect(16, c - 5, 38, 10, 5);
else ctx.rect(16, c - 5, 38, 10);
ctx.fill();
// 4) The nose cone.
ctx.fillStyle = 'rgba(255,255,255,0.95)';
ctx.beginPath();
ctx.moveTo(54, c - 5);
ctx.lineTo(63, c);
ctx.lineTo(54, c + 5);
ctx.closePath();
ctx.fill();
// 5) The hot core dot at the nose.
g = ctx.createRadialGradient(57, c, 0, 57, c, 5);
g.addColorStop(0.0, 'rgba(255,255,255,1.0)');
g.addColorStop(1.0, 'rgba(255,255,255,0.0)');
ctx.fillStyle = g;
ctx.fillRect(52, c - 5, 12, 10);
}
/**
* A HEAT-SEEKING missile (data/combat.json → enemy.weapon, the
* `missile` / `combo` patterns — the `hunter` and `warden` hostiles):
* a slow-ish projectile that homes on the player with a CAPPED
* turn-rate (`turnRate` rad/s, from weapon.missileTurn). The cap is the
* DOGE RULE — the player's sustained turn (combat.player.rotSpeed) is
* comfortably above the missile's, so a hard pull out-turns the shot.
* The homing math is Combat.js → homingStep (pure, tested); this class
* only carries it as a sprite.
*
* Like the bolt (js/combat/Bullet.js) it is scene-stepped: the owning
* context (js/combat/CombatScene.js / CombatSystem.js) pushes it into
* its `missiles` roster and runs js/combat/Weapons.js's step + hit
* passes (the scene decides what it hits — the missile just reports its
* world radius, `this.radius`, and its flight heading, `this.heading`).
*/
export class Missile extends Phaser.Physics.Arcade.Sprite {
static TEXTURE_KEY = TEX_KEY;
/** Ensure the missile texture exists (canvas-generated). */
static ensureTexture(scene) {
if (scene.textures.exists(TEX_KEY)) return TEX_KEY;
if (typeof document === 'undefined') return TEX_KEY; // headless (the tests)
canvasTexture(scene, TEX_KEY, TEX_W, TEX_H, (ctx, w, h) => drawMissile(ctx, w, h));
return TEX_KEY;
}
/**
* @param {object} scene the combat scene
* @param {object} o { x, y, angle, speed, turnRate, damage, life, color, size, owner }
* angle rad (initial flight heading), speed px/s (constant),
* turnRate rad/s (the homing CAP — the dodge rule),
* size px (the missile's world length).
*/
constructor(scene, o) {
Missile.ensureTexture(scene);
super(scene, o.x, o.y, TEX_KEY);
scene.add.existing(this);
scene.physics.add.existing(this);
assignWorld(scene, this); // world pass (the UI pass must not double-draw)
this.owner = o.owner ?? 'enemy';
this.damage = Math.max(0, Number(o.damage) || 14);
this.life = Math.max(0.1, Number(o.life) || 4);
this.dead = false; // consumed (a hit or the end of life) — consume() is one-shot
// The flight state (Weapons.js / the scene steps it each frame).
this.heading = Number(o.angle) || 0;
this.speed = Math.max(10, Number(o.speed) || 200);
this.turnRate = Math.max(0, Number(o.turnRate) || 2.2); // rad/s cap
this.color = o.color ?? '#ff9d3d';
// World length = `size` px (the same contract as the ship's: length ×
// the art's footprint). The body fills BODY_LEN of TEX_W texture px.
const size = Math.max(8, Number(o.size) || 18);
this.setScale(size / BODY_LEN);
this.tint = toColor(o.color, 0xffb36b);
this.setDepth(20);
this.rotation = this.heading;
// The world-px radius for the context's circle checks.
this.radius = Math.max(4, size * 0.4);
const body = this.body;
body.setCircle(TEX_H / 2); // texture-space radius (auto-scales with the sprite)
body.setAllowGravity(false);
body.setVelocity(Math.cos(this.heading) * this.speed, Math.sin(this.heading) * this.speed);
}
/**
* One step (ms): age the fuse, and home on `target` (the player — or
* null when the player is down: the shot flies true on its last
* heading). The turn is CAPPED by turnRate×dt (the dodge rule).
*/
update(deltaMs, target = null) {
if (this.dead) return;
const dt = Math.min(deltaMs, 64) / 1000;
this.life -= dt;
if (this.life <= 0) {
this.consume();
return;
}
if (target && target.x != null) {
this.heading = homingStep(this.heading, this.x, this.y, target.x, target.y, this.turnRate, dt);
const body = this.body;
if (body) body.velocity.set(Math.cos(this.heading) * this.speed, Math.sin(this.heading) * this.speed);
this.rotation = this.heading;
}
}
/**
* Consume the missile (a hit, or the end of its fuse). One-shot: only
* the FIRST caller destroys it.
* @returns {boolean} true when THIS call consumed it
*/
consume() {
if (this.dead) return false;
this.dead = true;
this.destroy();
return true;
}
}

210
js/combat/Weapons.js Normal file
View File

@ -0,0 +1,210 @@
import { toColor } from '../utils/Color.js';
import { fanAngles, ringAngles } from './Combat.js';
import { Missile } from './Missile.js';
import { combatSfx } from './CombatSfx.js';
/**
* The hostile WEAPON PATTERNS — the shared dispatch behind the seven new
* ship types (data/combat.json → enemyTypes, weapon.pattern). One code
* path for BOTH combat contexts (the range: js/combat/CombatScene.js,
* the main game: js/combat/CombatSystem.js): each context's fireEnemy()
* hands its hostile over here, and its update()/collide() run the
* missile step + hit passes (stepMissiles / missilesHitPlayer) — so the
* two contexts can never drift.
*
* PATTERNS (weapon.pattern — 'lance' is the default, the base behavior):
* 'lance' one aimed bolt (the base craft's single shot)
* 'rapid' one bolt on a SHORT cooldown (the config's rate — a gun)
* 'spray' a FAN of weapon.bolts spread over weapon.fan rad
* 'burst' a TIGHT weapon.bolts-shot stinger — staggered speeds make
* the group fan out over distance (the close-range snap)
* 'ring' weapon.bolts fired RADIAL around the craft (random phase
* per volley — break the orbit)
* 'missile' weapon.missiles HEAT-SEEKERS — the Missile (js/combat/
* Missile.js) homes with a CAPPED turn-rate (weapon.missileTurn)
* so the player can out-turn them (the dodge rule)
* 'combo' a heavy lance PLUS a missile volley (the elite)
*
* The `ctx` host (either context) provides: .scene (the Phaser scene —
* or IS it), .fx (the Fx layer), .spawnBullet(x, y, a, wpn, owner),
* .hitsSwept(b, other, r, dtMs), .damagePlayer(dmg, o), and it owns the
* live-missile roster on .missiles (this module creates it on demand).
*/
/** The pattern a weapon config declares ('lance' when unset). */
export function patternOf(wpn) {
const p = wpn && typeof wpn === 'object' ? wpn.pattern : null;
return typeof p === 'string' && p !== '' ? p : 'lance';
}
const sceneOf = (ctx) => (ctx && ctx.textures ? ctx : ctx.scene || ctx); // CombatSystem wraps the scene; CombatScene IS it (its .scene is Phaser's SceneManager — not a scene)
const num = (v, fb) => (Number.isFinite(Number(v)) ? Number(v) : fb);
/**
* Fire a hostile's weapon pattern at the player.
*
* @param {object} ctx the owning context (CombatScene | CombatSystem)
* @param {object} ship the hostile (an EnemyShip — .x/.y/.hitRadius)
* @param {object} player the player ship (.x/.y)
* @param {object} wpn the hostile's weapon config (enemy.weapon deep-merged)
* @returns {string} the pattern fired (for the dev log / tests)
*/
export function firePattern(ctx, ship, player, wpn) {
const kind = patternOf(wpn);
const toPlayer = Math.atan2(player.y - ship.y, player.x - ship.x);
const spread = Math.max(0, num(wpn.spread, 0));
const nose = Math.max(8, num(ship.hitRadius, 20)) + 10;
const jitter = () => (Math.random() * 2 - 1) * spread;
const spawnBolt = (a, wp = wpn) => {
const mx = ship.x + Math.cos(a) * nose;
const my = ship.y + Math.sin(a) * nose;
ctx.spawnBullet(mx, my, a, wp, 'enemy');
};
if (kind === 'spray') {
// The FAN: weapon.bolts across weapon.fan rad, centered on the aim.
const angles = fanAngles(toPlayer, num(wpn.bolts, 5), num(wpn.fan, 0.9));
for (const a of angles) spawnBolt(a + jitter());
} else if (kind === 'burst') {
// The STINGER: a tight group whose speeds are staggered (the outer
// shots drift apart over distance — a snap that opens into a spread).
const n = Math.max(2, Math.floor(num(wpn.bolts, 3)));
const fan = Math.max(0, num(wpn.burstFan ?? wpn.fan, 0.08));
const base = num(wpn.bulletSpeed, 420);
for (let i = 0; i < n; i++) {
const t = i / (n - 1);
spawnBolt(toPlayer - fan / 2 + fan * t + jitter(), {
...wpn,
bulletSpeed: base * (1 + (t - 0.5) * 0.18),
});
}
} else if (kind === 'ring') {
// The RADIAL ring: evenly around 2π, a fresh random phase per volley.
const angles = ringAngles(num(wpn.bolts, 8), Math.random() * Math.PI * 2);
for (const a of angles) spawnBolt(a + jitter());
} else if (kind === 'missile') {
launchMissiles(ctx, ship, player, wpn);
} else if (kind === 'combo') {
// The elite: the heavy lance AND the missile volley on one trigger.
spawnBolt(toPlayer + jitter());
launchMissiles(ctx, ship, player, wpn);
} else {
// 'lance' (default) and 'rapid' — one aimed bolt (rapid's config just
// fires it on a shorter cooldown; the pattern is the same single shot).
spawnBolt(toPlayer + jitter());
}
// The muzzle beat — one per volley (per-bolt would rattle like a gun).
const nx = ship.x + Math.cos(toPlayer) * nose;
const ny = ship.y + Math.sin(toPlayer) * nose;
ctx.fx.muzzle(nx, ny, toPlayer, wpn.color ?? '#ff2d6f', num(wpn.muzzle, 50));
if (kind !== 'missile' && kind !== 'combo') combatSfx(sceneOf(ctx), 'fire');
return kind;
}
/**
* Launch the hostile's HEAT-SEEKING volley (the `missile`/`combo`
* patterns): weapon.missiles shots from the nose, fanned over
* weapon.missileSpread (default 0.35 rad when there's more than one).
* They home with the CAPPED turn-rate from weapon.missileTurn — the
* dodge rule (the player's combat.player.rotSpeed out-turns them).
*
* @returns {number} the missiles launched
*/
export function launchMissiles(ctx, ship, player, wpn) {
const scene = sceneOf(ctx);
const n = Math.max(1, Math.floor(num(wpn.missiles, 1)));
const toPlayer = Math.atan2(player.y - ship.y, player.x - ship.x);
const spread = n > 1 ? Math.max(0, num(wpn.missileSpread, 0.35)) : 0;
const nose = Math.max(8, num(ship.hitRadius, 20)) + 12;
const opts = {
speed: Math.max(30, num(wpn.missileSpeed, 200)),
turnRate: Math.max(0.2, num(wpn.missileTurn, 2.2)), // the cap (dodge rule)
damage: Math.max(1, num(wpn.missileDamage, 14)),
life: Math.max(0.5, num(wpn.missileLife, 4)),
color: wpn.missileColor ?? wpn.color ?? '#ff9d3d',
size: Math.max(10, num(wpn.missileSize, 18)),
owner: 'enemy',
};
if (!Array.isArray(ctx.missiles)) ctx.missiles = [];
for (let i = 0; i < n; i++) {
const t = n === 1 ? 0.5 : i / (n - 1);
const a = toPlayer - spread / 2 + spread * t;
ctx.missiles.push(
new Missile(scene, {
x: ship.x + Math.cos(a) * nose,
y: ship.y + Math.sin(a) * nose,
angle: a,
...opts,
}),
);
}
combatSfx(scene, 'missile_fire'); // the rocket voice (distinct from the laser)
return n;
}
/**
* Step the live missiles (age the fuses + home on the player — or fly
* true when the player is down, `player` = null). The range clips them
* on the arena walls (bounds = { inset, w, h }); the main game passes
* null (no walls there). Consumed missiles are culled from ctx.missiles.
*/
export function stepMissiles(ctx, delta, player, bounds = null) {
const ms = ctx.missiles;
if (!ms || ms.length === 0) return;
for (let i = ms.length - 1; i >= 0; i--) {
const m = ms[i];
m.update(delta, player);
if (m.dead) {
ms.splice(i, 1);
fizzleFx(ctx, m); // the fuse ran out — a small bloom
continue;
}
if (
bounds &&
(m.x < bounds.inset ||
m.x > bounds.w - bounds.inset ||
m.y < bounds.inset ||
m.y > bounds.h - bounds.inset)
) {
if (m.consume()) {
ms.splice(i, 1);
fizzleFx(ctx, m); // the wall eats the rocket (like the tracers)
}
}
}
}
/**
* The missile hit pass: live missiles × the player (the context's swept
* rule, same as the tracers). A hit deals the missile's damage from its
* incoming bearing, blooms, and consumes it. No player (down) = the
* shots keep flying (their fuses end them).
*/
export function missilesHitPlayer(ctx, player, playerRadius, delta) {
const ms = ctx.missiles;
if (!ms || ms.length === 0 || !player) return;
const r = Math.max(4, num(playerRadius, 12));
for (let i = ms.length - 1; i >= 0; i--) {
const m = ms[i];
if (m.dead) {
ms.splice(i, 1);
continue;
}
if (ctx.hitsSwept(m, player, r, delta)) {
// The shield is struck from the missile's incoming bearing.
ctx.damagePlayer(m.damage, { x: m.x, y: m.y, bearing: m.heading + Math.PI });
if (ctx.fx && typeof ctx.fx.explode === 'function') {
ctx.fx.explode(m.x, m.y, toColor(m.color, 0xffb36b));
}
if (m.consume()) ms.splice(i, 1);
}
}
}
/** The small death bloom (fuse expiry / the wall) — a soft flash, no boom. */
function fizzleFx(ctx, m) {
if (ctx.fx && typeof ctx.fx.flash === 'function') {
ctx.fx.flash(m.x, m.y, toColor(m.color, 0xffb36b), 16, 180);
}
}

View File

@ -1032,24 +1032,30 @@ export class GameScene extends Phaser.Scene {
// `active` — the same freeze contract as the comms' ack pause.
this.levelMarquee = new LevelUpMarquee(this);
this.levelMarquee.bind(this.combat.xp);
// ?combat boot (the tuning sandbox): the hostile pack around the
// ship. The main game's combat arrives with the quest's ambush
// (the wave run above) — the boot just adds the practice pack.
// ?combat boot (the tuning sandbox): the SEVEN-TYPE DEMO around the
// ship (data/combat.json → waves.scripts.combat_demo) — a sequence
// of rolling waves, one per new hostile type in difficulty order
// (bomber → warden, frames 1–7), six of each, three on screen at a
// time, each kill sending in a replacement (js/combat/Waves.js →
// WaveRunner, driven by CombatSystem._waveTick — wave 1 lands after
// the script's 1.5 s lead; the bar is up from the start).
// The main game's combat still arrives with the quest's ambush
// (its own wave run) — the boot just adds the showcase.
// NOTE — the player's home system is SAFE SPACE: enemies should
// NEVER be placed there. This dev boot is the one place they could
// land in it, so don't run ?combat at home, and keep that rule for
// any new enemy placement (the quest ambush already targets the
// Neutral Capital, never home).
if (this._wantsCombatDemo()) {
this.combat.spawnPack(this.ship.x, this.ship.y);
this.combat.startWaves('combat_demo');
// SETTLE WINDOW — the ship's start position is finalized AFTER
// create() (a fresh run's home rim comes from the tether barrier;
// a load's from the save), so the pack — spawned around the
// create-time position — is re-anchored around the ship for the
// a load's from the save), so the run ships — spawned around the
// create-time position — are re-anchored around the ship for the
// first few frames (update() → CombatSystem.resyncAroundShip).
this._combatSettleFrames = 30;
console.info(
'[orbit] ?combat — hostile pack live (data/combat.json, js/combat/CombatSystem.js)',
'[orbit] ?combat — the seven-type demo is live: 7 rolling waves, bomber → warden (data/combat.json → waves.scripts.combat_demo)',
);
}
// The READABILITY LAYER (shared with the range): the lock on the