(Body Snatcher) Prepare for Pass 3

This commit is contained in:
AlexKucera committed 2026-08-12 22:52:27 +02:00
1 parent 96c01fa218
commit d819146009
4 files changed
-1982

No files matched your search

-145
View File
@@ -1,145 +0,0 @@
#!/usr/bin/env bash
# Body Snatcher — self-orchestrating build factory.
# Each phase runs in a FRESH `pi -p` context (reads AGENTS.md + verify.js),
# gated by `node verify.js <phase>`, retried up to MAX_RETRIES, then a targeted
# fix attempt, then an adversarial review, then a full final gate.
set -euo pipefail
cd "$(dirname "$0")"
MAX_RETRIES=3
COMMON="@AGENTS.md @verify.js"
# Pitfalls learned from prior sessions — every phase must respect these.
PITFALLS="
HARD PITFALLS (non-negotiable, learned the hard way):
- Keep the player SPAWN AREA clear: carve an open room around the spawn and do NOT
place procedural enemies within ~5 tiles of it (movement/possession checks depend on it).
- tick(n) must be DETERMINISTIC and advance BOTH enemy AI and the ghost timer by n steps.
Do NOT rely on wall-clock time for game-state logic; use tick steps. Visual interpolation
and audio may use real time, but state must be tick-driven.
- Canvas getContext('2d') and AudioContext may be no-op mocks; guard every call so the game
never throws when they are absent or return no-ops.
- When a host dies DURING tick and ejects the ghost, reset the 15s/20s timer and SKIP the rest
of that tick so the freshly-reset timer is not immediately decremented.
- Movement must enforce grid bounds and wall collision for ghost AND every enemy (including
charging/dashing enemies — check occupancy before entering a tile).
- Save/load: store the possessed host separately; on load, re-link player.host and player.body
to the SAME object. Treat localStorage as UNTRUSTED: validate grid/fog dimensions, normalize
entities and stats, and never leave partial state after a failed load.
- Single index.html, zero external dependencies, no ES import/require, no <script src>.
- Expose the full DEBUG API CONTRACT documented at the top of verify.js on window.GAME.
- The title screen must visibly contain the literal tokens WASD, SPACE, ENTER, ESC/PAUSE, Q, E."
run_phase() {
local phase=$1
local prompt=$2
local attempt=1
while [ "$attempt" -le "$MAX_RETRIES" ]; do
echo "=== Phase $phase (attempt $attempt/$MAX_RETRIES) ==="
# Fresh isolated context per attempt.
pi -p "${prompt}${PITFALLS}" $COMMON || true
if node verify.js "$phase"; then
echo "=== Phase $phase PASSED ==="
return 0
else
echo "=== Phase $phase FAILED (attempt $attempt) ==="
if [ "$attempt" -eq "$MAX_RETRIES" ]; then
echo "=== Phase $phase exhausted retries -> targeted fix ==="
local errs
errs="$(node verify.js "$phase" 2>&1 || true)"
pi -p "Phase $phase of Body Snatcher failed its verification gate. Read AGENTS.md and verify.js, then read the CURRENT index.html in full. Do NOT rewrite from scratch — make the MINIMAL targeted fixes for these specific failures:
${errs}
After fixing, run 'node verify.js ${phase}' yourself and keep fixing until it exits 0. Preserve all working features from earlier phases.${PITFALLS}" $COMMON || true
if node verify.js "$phase"; then
echo "=== Phase $phase PASSED after fix ==="
return 0
fi
fi
fi
attempt=$((attempt + 1))
done
echo "=== Phase $phase FAILED after all retries ==="
return 1
}
# ---------------------------------------------------------------- PHASE 1
run_phase 1 "Read AGENTS.md (the full game spec) and verify.js (the test harness + DEBUG API CONTRACT at its top). Implement PHASE 1 ONLY:
- Single index.html: HTML5 Canvas (800x576 + HUD bar), inline CSS, inline vanilla JS, zero dependencies.
- 25x18 tile grid, tile types floor/wall/door/exit/shop/chest, grid lines, dark dungeon look.
- Game loop + a DETERMINISTIC tick(n) stepping function.
- Ghost player (white translucent circle): WASD/arrows move one tile/turn, wall + bounds collision.
- Base ghost timer = 15 seconds, exposed as player.timer and decremented by tick().
- Fog of war: visible radius around player, explored-but-unseen tiles dimmed.
- HUD: body HP (or ghost HP=1), ghost timer, essence, floor, abilities; plus a contextual SPACE hint.
- Title screen (state 'title') shown on load and by start(); MUST visibly explain WASD/arrows, SPACE (possess while ghost / attack while possessed), Q/E (rotate facing), ENTER (start/confirm), ESC (pause). Do NOT auto-start play.
- A small static hand-built test dungeon (walls + floor + an exit tile) so movement checks pass; procgen comes in phase 4.
- Expose window.GAME = {state, player, enemies, grid, floor, essence, upgrades, achievements, projectiles, log, start(), input(key), tick(n), spawn(type,x,y), setFloor(n), newRun(), save(), load(), openShop(), buy(i)} — at least stub the later-phase methods so they exist without throwing (spawn/place enemy, etc.), but movement/grid/timer/title must be REAL now.
Run 'node verify.js 1' yourself repeatedly and fix every failure until it exits 0."
# ---------------------------------------------------------------- PHASE 2
run_phase 2 "Read AGENTS.md and verify.js. Implement PHASE 2 ONLY, preserving all phase-1 work:
- Possession: while ghost, SPACE on an adjacent enemy transitions state to 'possessed' and sets player.host to that enemy; the player then uses the host's stats/attack/movement.
- Brute (red square): enemy AI slow chase every 2 turns via A*/BFS toward player, 2 dmg melee adjacent. Player kit: HP 8, move every 2 turns, 3 dmg.
- Skitterer (orange triangle): enemy AI fast (every turn), swarms/flanks, 1 dmg. Player kit: HP 2, fast, 1 dmg/turn.
- Sentinel (purple hexagon): enemy AI keeps ~4 tile range, shoots projectiles toward player, kites away if close, NO melee. Player kit: HP 4, shoots projectiles in facing dir, cannot melee.
- A* or BFS pathfinding: enemies navigate around walls toward the player (never enter wall tiles, never leave the grid).
- Essence drops on kill (Brute=3, Skitterer=1, Sentinel=3) and accumulates in GAME.essence.
- Killing the current host (hp->0) ejects the ghost with timer reset to 15 (>0) and state back to playing/ghost.
- Ghost Tree T1 (timer 15->20) is progression; reserve the hook but the base timer stays 15.
- HUD contextual hint names the current SPACE action for the possessed body.
Run 'node verify.js 2' yourself repeatedly and fix every failure until it exits 0."
# ---------------------------------------------------------------- PHASE 3
run_phase 3 "Read AGENTS.md and verify.js. Implement PHASE 3 ONLY, preserving all prior work:
- The remaining 9 enemy types, each with BOTH an enemy AI and a player kit, matching AGENTS.md exactly:
Shielder (blue square, frontal shield blocks facing-direction damage; player rotates with Q/E), Bomber (dark red circle, explodes 3x3 on death/adjacent; player SPACE detonates suicide 3x3 then ejects ghost), Healer (green cross, heals nearby enemies +1/turn within 3, flees; player SPACE AoE heal pulse self+2 allies+1), Phaser (cyan diamond, teleports toward player every 3 turns; player SPACE blinks 5 tiles through walls, 2-turn cooldown), Turret (gray octagon, stationary 360 fire 1 shot/turn; player rooted, SPACE fires facing dir, Q/E rotate), Charger (yellow arrow, telegraph 1 turn then charges straight line 3 dmg, stuns 2 turns on wall; player SPACE dash-charge 4 tiles, 2 dmg/enemy in path), Siren (pink circle, pull field drags player 1 tile/turn within 5; player SPACE pulls all enemies within 4 one tile toward you), Mimic (brown chest disguise, reveals + 2 dmg cross burst when player adjacent; player passive no-aggro while disguised, SPACE surprise burst 2 dmg 3x3 cross), Leech (dark purple teardrop, drains 1 hp on hit healing self +1; player every hit 1 dmg + heal 1).
- Each enemy object exposes distinct {hp/maxHp, damage, speed} so no two share the same tuple.
- Every special ability must execute without error when triggered (including on cooldown / out of resources).
- Ensure pathfinding still respects walls for all melee chasers; ranged/charger/siren may use their own movement but must never enter walls or leave the grid.
- Add GAME.projectiles support if not present; Sentinel/Turret/Siren/Charger effects route through it as needed.
Run 'node verify.js 3' yourself repeatedly and fix every failure until it exits 0."
# ---------------------------------------------------------------- PHASE 4
run_phase 4 "Read AGENTS.md and verify.js. Implement PHASE 4 ONLY, preserving all prior work:
- Procedural dungeon generation: random walk + room carving. All walls to start, carve 5-8 rooms (4x4 to 8x6) connected by 1-tile L-shaped corridors (never diagonal). Place exit stairs in the farthest room from spawn. Place 1-2 chests. Each call to newRun()/setFloor() must produce a DIFFERENT random layout.
- 10 floors with escalating difficulty: floors 1-3 Brutes/Skitterers/Sentinels; 4-6 add Shielders/Bombers/Chargers; 7-9 add Healers/Phasers/Sirens/Turrets; 10 all types incl Mimics/Leeches, higher density. Enemy count = 4 + floor.
- Shop pad logic: shop appears BETWEEN floors (after exit, before next floor) on the transition. Provide openShop() (debug) and a real between-floor shop state with exactly 3 random upgrade choices.
- All 11 upgrades across 3 trees with prerequisites (tier N requires tier N-1 in same tree): Ghost (T1 15->20s cost5, T2 possess range +1 cost8, T3 phase walls 1s/5s cd cost12, T4 ghost dash 3 tiles/3s cd cost15); Body (T1 retain one prev ability cost10, T2 overclock +50% stats 5 turns cost12, T3 dual-wield cost18); Meta (T1 start each floor in a random body cost8, T2 see enemy types through fog cost10, T3 30% shop discount cost6). Buying must change GAME.upgrades and respect prerequisites/cost/essence.
- Save/load via localStorage key 'bodysnatcher_save'. Auto-save on floor transition, shop purchase, possession change. Save data: floor, essence, upgrades, player state, current floor layout. load() restores floor + essence + upgrades + layout exactly. Treat the stored blob as untrusted.
- Ghost T1 must actually raise the base timer from 15 to 20 when purchased.
Run 'node verify.js 4' yourself repeatedly and fix every failure until it exits 0 (run it several times — procgen is randomized)."
# ---------------------------------------------------------------- PHASE 5
run_phase 5 "Read AGENTS.md and verify.js. Implement PHASE 5 ONLY, preserving all prior work:
- Web Audio API procedural sounds (no files): hit, possess, death, pickup, explosion. Initialize lazily; tolerate mock AudioContext. Must actually call AudioContext methods on gameplay events.
- Game feel: screen shake on explosions/big hits, particle effects on death/possession/essence pickup, hit flash (white 100ms), smooth 150ms movement interpolation between tiles.
- All 8 achievements (localStorage-tracked): First Possession, Body Hopper (5 different enemy types one run), Pacifist Ghost (reach floor 3 with no host damage), Essence Hoarder (30 essence), Deep Diver (floor 7), Escape Artist (win), Bomberman (3 kills one Bomber detonation), Dual Wield (Body T3). At least 3 must be triggerable through normal play; expose GAME.achievements.
- Win state: reach floor 10 exit -> 'won' victory screen with stats. Lose state: ghost timer hits 0 -> 'lost' game-over screen with stats.
- Pause menu (ESC) with Save + Quit; resume. Shop and pause overlays show their confirm/back controls. HUD keeps the contextual SPACE hint. Title screen already explains all controls.
Run 'node verify.js 5' yourself repeatedly and fix every failure until it exits 0."
# ---------------------------------------------------------------- ADVERSARIAL REVIEW
echo "=== ADVERSARIAL REVIEW ==="
pi -p "You are a ruthless QA reviewer for the game Body Snatcher. Read AGENTS.md (full spec) and the COMPLETE index.html, then read verify.js. Hunt for bugs, crashes, spec violations, and missing features. For EACH issue you find, fix it directly in index.html (minimal targeted edits, never a rewrite). Focus especially on: crashes during play; enemies that don't work or share stats; save/load edge cases and corrupted/missing fields; missing or non-triggering achievements; fog-of-war bugs; base ghost timer not being at least 15s (and 20s with Ghost T1); procgen that can trap the player or place the exit unreachable; controls not readable in-game before play plus contextual hints during play; the page must NOT auto-start and must stay on title until start()/keypress. After fixing, run 'node verify.js 1', 'node verify.js 2', 'node verify.js 3', 'node verify.js 4', 'node verify.js 5' and fix anything that fails.${PITFALLS}" $COMMON || true
# ---------------------------------------------------------------- FINAL GATE
echo "=== FINAL VERIFICATION (all phases) ==="
all_pass=1
for p in 1 2 3 4 5; do
if node verify.js "$p"; then
echo "--- Phase $p OK ---"
else
echo "--- Phase $p FAILED ---"
all_pass=0
fi
done
if [ "$all_pass" -eq 1 ]; then
echo "ALL GATES PASSED"
else
echo "FINAL GATE FAILED"
exit 1
fi
echo "=== BUILD COMPLETE ==="