(Body Snatcher) Initial Plan

This commit is contained in:
AlexKucera committed 2026-08-12 14:45:07 +02:00
1 parent dce898841d
commit 5cc9920181
3 files changed
+512

No files matched your search

+243
View File
@@ -0,0 +1,243 @@
# CLAUDE.md — Body Snatcher
You are building a browser-based roguelike game called **Body Snatcher**. Read this file completely before writing any code. Refer back to it at every phase.
## The Game
You are a ghost. 1 HP. No attack. You explore a procedurally generated dungeon. To survive, you must **possess** enemies — walk into them and hold SPACE. Once inside, you control their body: their stats, their attack, their movement speed. When your host dies, you're ejected as a ghost with a countdown timer. Find a new body or die. Descend 10 floors, spend essence in shops, upgrade your abilities, reach the exit.
## Tech Constraints
- **Single `index.html`** — HTML5 Canvas + vanilla JavaScript
- **Zero dependencies** — no npm, no CDN, no external libraries
- **Zero build step** — open the file in a browser, it plays
- Everything inline in one file. No external CSS, no external JS.
## Visual Style
- Top-down 2D grid, tile-based (each tile = 32px)
- Dark dungeon background, grid lines visible
- Entities are colored shapes with distinct silhouettes (no sprites needed):
- Ghost: white translucent circle with eyes
- Brute: large red square
- Skitterer: small orange triangle
- Sentinel: purple hexagon
- Shielder: blue square with front line
- Bomber: dark red circle with fuse
- Healer: green cross
- Phaser: cyan diamond
- Turret: gray octagon
- Charger: yellow arrow shape
- Siren: pink circle with rings
- Mimic: looks like a chest until provoked
- Leech: dark purple teardrop
- Minimal but readable. Color + shape communicates everything.
## Grid + Rendering
- 25x18 tile grid (800x576px canvas) + HUD bar at top
- Tile types: floor, wall, door, exit-stairs, shop-pad, chest
- Fog of war: visible radius around player, explored-but-unseen dimmed
- HUD shows: current body HP, ghost timer (when ghost), essence count, floor number, abilities
## Player States
### Ghost State
- 1 HP, no attack
- Movement: arrow keys / WASD, one tile per turn
- Cannot walk through walls (unless Ghost Tree T3 unlocked)
- Hold SPACE adjacent to enemy → possession (takes 1 turn)
- Ghost timer: 5s real-time countdown (8s with Ghost T1)
- Timer pauses while possessing
- When timer hits 0 → game over
### Possessed State
- Use host's HP, attack, movement speed, abilities
- SPACE = host's attack
- Movement = host's movement pattern (some enemies move differently)
- When host HP hits 0 → ejected as ghost, timer starts
## Enemy Roster
Each enemy is a **dual system**: it behaves one way as an opponent and differently when you possess it. Define each as a data object with both AI behavior and player kit.
### 1. Brute
- **Enemy AI:** Slow chase (moves every 2 turns). A* pathfinding toward player. Heavy melee (2 damage) on adjacent tile.
- **Player kit:** High HP (8), slow movement (every 2 turns), high damage (3 per hit).
- **Color:** Red. **Shape:** Large square (28px).
### 2. Skitterer
- **Enemy AI:** Fast (moves every turn). Swarm behavior — attracted to other Skitterers. Flanks player. Weak melee (1 damage).
- **Player kit:** Low HP (2), fast movement, rapid weak hits (1 damage per turn).
- **Color:** Orange. **Shape:** Small triangle (16px).
### 3. Sentinel
- **Enemy AI:** Keeps distance (maintains 4-tile range). Shoots projectiles toward player. Moves away if player gets close.
- **Player kit:** Medium HP (4). Shoot projectiles in facing direction. Cannot melee.
- **Color:** Purple. **Shape:** Hexagon.
### 4. Shielder
- **Enemy AI:** Slow chase. Frontal shield blocks all damage from the direction it's facing. Takes damage from sides/back.
- **Player kit:** Medium HP (5). Frontal shield active. Must rotate (Q/E keys) to face threats.
- **Color:** Blue. **Shape:** Square with front line indicator.
### 5. Bomber
- **Enemy AI:** Chase player. On death or when adjacent, explodes (3x3 AoE, 3 damage).
- **Player kit:** Low HP (3). Press SPACE to detonate (suicide, 3x3 AoE, 4 damage). Ejects you as ghost.
- **Color:** Dark red. **Shape:** Circle with fuse indicator.
### 6. Healer
- **Enemy AI:** Stays near other enemies. Heals nearby enemies (+1 HP per turn within 3 tiles). Fleees from player.
- **Player kit:** Low HP (3). Press SPACE for AoE heal pulse (heal self +2, all allies +1 within 3 tiles). Low offensive capability.
- **Color:** Green. **Shape:** Cross.
### 7. Phaser
- **Enemy AI:** Teleports toward player every 3 turns (within line of sight). Materializes, attacks, dematerializes.
- **Player kit:** Medium HP (4). Press SPACE to blink 5 tiles in facing direction (through walls). 2-turn cooldown.
- **Color:** Cyan. **Shape:** Diamond.
### 8. Turret
- **Enemy AI:** Stationary. 360° rapid fire (1 shot per turn). Tracks player.
- **Player kit:** Medium HP (4). Rooted — cannot move. Press SPACE to fire in facing direction (Q/E to rotate). High DPS.
- **Color:** Gray. **Shape:** Octagon.
### 9. Charger
- **Enemy AI:** Telegraphs (flashes for 1 turn), then charges in a straight line toward player's position at telegraph time. Collision = 3 damage. Hits walls = stunned 2 turns.
- **Player kit:** Medium HP (5). Press SPACE to dash-charge 4 tiles in facing direction. Damages enemies in path (2 per enemy hit).
- **Color:** Yellow. **Shape:** Arrow.
### 10. Siren
- **Enemy AI:** Stationary or slow drift. Emits pull field (drags player 1 tile toward it per turn if within 5 tiles). Weak melee.
- **Player kit:** Low HP (3). Press SPACE to pull all enemies within 4 tiles one tile toward you. Useful for grouping.
- **Color:** Pink. **Shape:** Circle with ring animation.
### 11. Mimic
- **Enemy AI:** Disguised as a chest. When player is adjacent, reveals true form and bursts (2 damage in cross pattern).
- **Player kit:** Medium HP (4). Passive: enemies don't aggro you while disguised. Press SPACE for surprise burst (2 damage 3x3 cross).
- **Color:** Brown (disguised) / dark gold (revealed). **Shape:** Chest → reveal.
### 12. Leech
- **Enemy AI:** Slow chase. On hit, drains 1 HP from player and heals self +1.
- **Player kit:** Medium HP (4). Every hit deals 1 damage and heals you +1. Sustain machine.
- **Color:** Dark purple. **Shape:** Teardrop.
## Essence + Economy
- Enemies drop essence on death (value by type: Brute=3, Skitterer=1, Sentinel=3, Shielder=4, Bomber=2, Healer=5, Phaser=4, Turret=5, Charger=4, Siren=3, Mimic=4, Leech=4)
- Essence persists across the run
- Shop appears between floors (after floor exit, before next floor)
## Shop (Between Floors)
Present 3 random upgrades from the pool below. Player picks one or skips.
### Ghost Tree
- T1: Ghost time 5s → 8s (cost: 5 essence)
- T2: Possession range +1 tile, can possess from 2 tiles away (cost: 8)
- T3: Phase through walls — 1s burst, 5s cooldown (cost: 12)
- T4: Ghost Dash — quick 3-tile dash while incorporeal, 3s cooldown (cost: 15)
### Body Tree
- T1: Retain — keep one ability from previous host after switching bodies (cost: 10)
- T2: Overclock — +50% stats for 5 turns on fresh possession (cost: 12)
- T3: Dual-wield — carry two abilities simultaneously (cost: 18)
### Meta Tree
- T1: Start each floor with a random body (cost: 8)
- T2: See enemy types through fog of war (cost: 10)
- T3: Shop discounts — 30% off all prices (cost: 6)
**Upgrade prerequisites:** Each tier requires the previous tier in the same tree. T1 → T2 → T3 → T4.
## Procedural Dungeon Generation
- **Algorithm:** Random walk + room carving. Start with all walls. Carve rooms connected by corridors.
- **Per floor:**
- 5-8 rooms of varying size (4x4 to 8x6 tiles)
- Rooms connected by 1-tile-wide corridors (L-shaped, never diagonal)
- Place exit stairs in the farthest room from spawn
- Place shop pad on floors 3, 5, 7, 9 (before the floor, not during)
- Place enemies: scale count with floor (floor N = 4 + N enemies)
- Place 1-2 chests with random essence or item
- **Difficulty scaling:** Floors 1-3: Brutes, Skitterers, Sentinels. Floors 4-6: add Shielders, Bombers, Chargers. Floors 7-9: add Healers, Phasers, Sirens, Turrets. Floor 10: all types including Mimics and Leeches, higher density.
## Save/Load
- `localStorage` key: `bodysnatcher_save`
- Auto-save on: floor transition, shop purchase, possession change
- Save data: floor number, essence, upgrades, player state, current floor layout (for reload mid-floor)
- On page load: if save exists, prompt "Continue run? Y/N"
- Must work with browser refresh (quit + reload demonstration)
## Game Feel
- Screen shake on explosions and big hits
- Particle effects on death, possession, essence pickup
- Hit flash (entity flashes white for 100ms on damage)
- Smooth movement interpolation between tiles (150ms ease)
- Sound: use Web Audio API to generate simple tones (no audio files needed). Hit sound, possess sound, death sound, pickup sound, explosion sound. Procedural beeps.
## Achievements (localStorage-tracked)
- First Possession — possess your first enemy
- Body Hopper — possess 5 different enemy types in one run
- Pacifist Ghost — reach floor 3 without taking any host damage
- Essence Hoarder — accumulate 30 essence
- Deep Diver — reach floor 7
- Escape Artist — win the game (reach floor 10 exit)
- Bomberman — kill 3 enemies with one Bomber detonation
- Dual Wield — unlock Body Tree T3
## Controls
- **WASD / Arrow Keys:** Move (one tile per turn)
- **SPACE:** Possess (ghost) / Attack (possessed) / Special (possessed)
- **Q / E:** Rotate facing (for Shielder, Turret)
- **ENTER:** Confirm in menus/shop
- **ESC:** Pause menu (Save + Quit option)
## Completion Criteria
The game MUST meet ALL of these. Do not consider yourself done until every one passes:
1. `index.html` exists, opens in a browser with zero errors in console
2. No external dependencies (check: no CDN links, no npm imports, no script src tags pointing externally)
3. Can move as ghost with WASD/arrows
4. Can possess at least 3 different enemy types
5. Each possessed enemy type has distinct stats and attacks
6. Procedural dungeon generates different layouts each new run
7. At least 6 of the 12 enemy types are implemented and functional
8. A* or BFS pathfinding works — enemies navigate around walls toward player
9. Essence drops from kills and accumulates
10. Shop appears between floors with 3 upgrade choices
11. Upgrade choices affect gameplay (ghost timer, abilities, etc.)
12. Save/load works — refresh page, select Continue, state persists
13. 10 floors with escalating difficulty and enemy variety
14. Win state: reach floor 10 exit → victory screen
15. Lose state: ghost timer expires → game over screen with stats
16. No crashes during a 5-minute continuous play session
17. Fog of war renders correctly (unexplored tiles hidden, explored dimmed)
18. Audio plays (procedural tones via Web Audio API)
19. At least 3 achievements track and unlock
## Testability (REQUIRED)
The game MUST expose its state for automated testing:
- `window.GAME` object with at minimum: `{ state, player, enemies, grid, floor, essence, upgrades, log }`
- `window.GAME.input(key)` — simulate a keypress programmatically (for headless testing)
- `window.GAME.tick(n)` — advance the game loop n times (for headless testing)
- The game MUST NOT crash if Canvas `getContext('2d')` returns a mock object with no-op methods
- The game MUST NOT crash if `AudioContext` is a mock constructor
- The game MUST NOT auto-start on load — wait for a keypress or explicit `start()` call, so headless tests can set up before starting
## Anti-Patterns (DO NOT DO THESE)
- DO NOT split into multiple files. Single `index.html`.
- DO NOT add external dependencies, libraries, or frameworks.
- DO NOT use ES modules (import/export) — inline script only.
- DO NOT add a tutorial level. Start on floor 1 immediately.
- DO NOT write more code than needed. Bloat is penalized.
- DO NOT skip the fog of war, audio, or save/load — they are completion criteria.
- DO NOT use placeholder art or "TODO" comments. Everything must work.
- DO NOT add multiplayer, online features, or any server component.
- DO NOT stop until all completion criteria pass.
+187
View File
@@ -0,0 +1,187 @@
# PROMPT.md — Body Snatcher
This is the one-prompt entry for the Agentic Labs One-Prompt Challenge.
Paste the section between the ===== lines into Pi as your first and only message.
The AGENTS.md file in this directory is part of your prompt (rules 2.2 and 3.1).
Do not delete or modify AGENTS.md.
## How to use this file
1. Copy everything between the ===== markers below
2. Open Pi in an empty directory containing ONLY AGENTS.md
3. Paste as your first message
4. Hands off. Let it run.
5. Save the session jsonl when done (rule 6.2)
=====================================================================
Read AGENTS.md. That is the full game spec for "Body Snatcher" — a browser-based possession roguelike. Read it entirely before doing anything.
Your task: Build the complete game as a single index.html file. Follow the spec exactly.
## ARCHITECTURE: You are building a self-orchestrating software factory.
Do NOT write the game directly in this conversation. Instead, write two scripts — `build.sh` and `verify.js` — then run `build.sh` and let it orchestrate the entire build using `pi -p` as the primitive. This gives you subagent isolation, mechanical verification gates, and retry loops.
## STEP 1: Write verify.js (do this first, before any game code)
`verify.js` is your automated test harness. It uses Node.js to:
1. Read `index.html`, extract the `<script>` content, and eval it in a sandboxed context with DOM mocks
2. Mock `document`, `window`, `canvas.getContext`, `AudioContext`, `localStorage`, and `requestAnimationFrame` as no-ops / simple stubs
3. Call `GAME.start()` to initialize
4. Simulate input sequences and assert on game state via `window.GAME`
It must run without external packages — only Node.js builtins (`fs`, `vm`, `path`).
`verify.js` takes a phase number as argument: `node verify.js 1` runs phase 1 checks.
### Phase 1 checks: Engine exists and runs
- index.html exists, contains `<canvas` and `<script`
- No external src= attributes or import statements
- GAME.start() runs without throwing
- GAME.state is one of the valid states
- Grid exists and has wall + floor tiles
- GAME.input('ArrowRight') moves the ghost without error
- Ghost cannot move into walls
### Phase 2 checks: Possession + first 3 enemies
- Spawn an enemy next to the player via GAME.spawn or debug setup
- GAME.input('Space') on adjacent enemy → state transitions to "possessed"
- Brute: HP 8, damage 3, slow movement
- Skitterer: HP 2, damage 1, fast movement
- Sentinel: HP 4, shoots projectiles, no melee
- Each enemy pathfinds toward the ghost when not possessed
- Killing a host ejects ghost with timer > 0
- Essence increases on kill
### Phase 3 checks: All 12 enemy types
- All 12 enemy types can be instantiated
- Each has distinct stats (no two share HP + damage + speed)
- Each special ability executes without error when triggered
- Pathfinder navigates around walls (not through them)
### Phase 4 checks: Procgen + shop + save/load
- Generate 3 dungeons, assert all 3 layouts differ (compare wall positions)
- Exit tile exists on each floor
- Shop appears on floor transition
- Purchasing an upgrade changes GAME.upgrades
- localStorage.setItem is called on save
- After mock save/load round-trip, floor + essence + upgrades persist
### Phase 5 checks: Polish + completeness
- GAME.state can reach 'won' (reach floor 10 exit)
- GAME.state can reach 'lost' (ghost timer hits 0)
- At least 3 achievements can trigger
- Audio context methods are called (sound system initialized)
- No JS errors during a 200-tick stress test (move, possess, attack, descend 3 floors)
**Run verify.js after EVERY build phase. Exit 0 = pass. Exit 1 = fail with specific assertion. This is your gate.**
## STEP 2: Write build.sh
`build.sh` orchestrates the entire build in phases using `pi -p` as the primitive. Each phase gets:
- Fresh pi context (reads AGENTS.md, no drift from previous phases)
- A specific scope (only the systems for that phase)
- A mechanical gate (`node verify.js N`)
- Retry on failure (max 3 attempts per phase)
Structure:
```bash
#!/usr/bin/env bash
set -euo pipefail
MAX_RETRIES=3
run_phase() {
local phase=$1
local prompt=$2
local attempt=1
while [ $attempt -le $MAX_RETRIES ]; do
echo "=== Phase $phase (attempt $attempt/$MAX_RETRIES) ==="
pi -p "$prompt" || true # pi may exit non-zero, that's fine
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 ==="
# Feed failure details into a fix attempt
pi -p "Phase $phase of Body Snatcher failed verification. Read AGENTS.md and the current index.html. The verify.js output was: $(node verify.js "$phase" 2>&1). Fix ALL issues. Do not rewrite from scratch — fix the specific failures." || 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: Core engine
run_phase 1 "Read AGENTS.md. Implement Phase 1 ONLY: HTML5 Canvas skeleton, game loop, grid system, tile rendering, wall collision, ghost movement (WASD/arrows), fog of war, HUD, and a static test dungeon. Expose window.GAME with {state, player, grid, input(key), start(), tick(n)} as specified in the Testability section. Do NOT implement enemies, possession, or procgen yet. Run node verify.js 1 yourself and fix any failures before finishing."
# Phase 2: Possession + first 3 enemies
run_phase 2 "Read AGENTS.md. Implement Phase 2 ONLY: possession mechanic (SPACE on adjacent enemy), Brute/Skitterer/Sentinel with dual AI+player-kit, A* pathfinding, ghost timer, essence drops. Preserve everything from Phase 1. Run node verify.js 2 yourself and fix any failures before finishing."
# Phase 3: Remaining 9 enemies
run_phase 3 "Read AGENTS.md. Implement Phase 3 ONLY: the remaining 9 enemy types (Shielder, Bomber, Healer, Phaser, Turret, Charger, Siren, Mimic, Leech). Each needs full enemy AI + player kit. Preserve everything from previous phases. Run node verify.js 3 yourself and fix any failures before finishing."
# Phase 4: Procgen + progression + shop + save/load
run_phase 4 "Read AGENTS.md. Implement Phase 4 ONLY: procedural dungeon generation (random walk + room carving), 10 floors with escalating enemies, between-floor shop with 3 upgrade choices, all 11 upgrades across 3 trees, save/load via localStorage. Preserve everything. Run node verify.js 4 yourself and fix any failures before finishing."
# Phase 5: Polish + audio + achievements + win/lose
run_phase 5 "Read AGENTS.md. Implement Phase 5 ONLY: Web Audio API procedural sounds, screen shake, particles, hit flashes, movement interpolation, all 8 achievements, win state (floor 10 exit), lose state (ghost timer expires), pause menu (ESC). Preserve everything. Run node verify.js 5 yourself and fix any failures before finishing."
# Final adversarial review
echo "=== ADVERSARIAL REVIEW ==="
pi -p "You are a QA reviewer. Read AGENTS.md and the complete index.html. Find bugs, missing features, and spec violations. For each issue found, fix it directly. Focus on: crashes, enemies that don't work, save/load edge cases, missing achievements, fog of war bugs. Run node verify.js 5 after fixes." || true
# Final verification
echo "=== FINAL VERIFICATION ==="
node verify.js 5 && echo "ALL GATES PASSED" || echo "FINAL GATE FAILED"
echo "=== BUILD COMPLETE ==="
```
Adapt the phase prompts as needed for your environment, but keep this structure:
1. Fresh `pi -p` per phase (isolated context)
2. `node verify.js N` as mechanical gate after each
3. Max 3 retries, then a targeted fix attempt
4. Adversarial review pass at the end
5. Final gate check
## STEP 3: Run it
```bash
chmod +x build.sh
bash build.sh
```
Then sit back. The factory runs itself.
## Rules
- Single index.html. Zero external dependencies.
- verify.js uses only Node.js builtins — no npm packages.
- build.sh uses `pi -p` as the only LLM primitive.
- If something in the spec is ambiguous, make a reasonable choice. Don't stop to ask.
- Write less code, not more. Bloat is penalized.
- No stubs, no TODOs, no placeholders. Everything works.
- Do not stop until all verify.js gates pass and the adversarial review completes.
Now: write verify.js, then build.sh, then run build.sh.
=====================================================================
## Notes
- The directory should contain ONLY AGENTS.md when you start the Pi session
- AGENTS.md is allowed by rule 2.2 ("Human-authored instruction text is allowed")
- AGENTS.md must be disclosed in your submission repo (rule 3.1)
- The session jsonl proves it was one prompt — save it
- verify.js and build.sh are generated BY the agent during the run — they don't violate the "empty directory" rule because they're produced as output, not pre-staged
@@ -0,0 +1,82 @@
# Body Snatcher — Game Design
## Core Concept
Browser-based roguelike. You are a ghost with 1 HP and no attack. Possess enemies to fight. When your host dies, you're ejected with a countdown timer — find a new body or die.
**Win:** Reach the exit on floor 10.
**Lose:** Ghost timer expires with no body available.
## Core Loop
1. Spawn as ghost on procgen dungeon floor
2. Enemies roam with distinct AI patterns
3. Walk into enemy + hold Space to possess
4. Control body: stats, attack, movement
5. Host dies → ejected as ghost, 5s timer
6. Find new body or die
7. Collect essence from kills
8. Descend → shop between floors → upgrade
## Enemy Roster (12 types — dual system: enemy AI + player kit)
| Enemy | As Enemy | As Player (possessed) |
|-------|----------|----------------------|
| Brute | Slow chase, heavy melee | High HP, slow, big damage |
| Skitterer | Fast swarm, flanks | Fast, low HP, rapid weak hits |
| Sentinel | Ranged shots, keeps distance | Shoot projectiles, can't melee |
| Shielder | Blocks frontal damage | Frontal shield, must turn to hit |
| Bomber | Explodes on death | Detonate on command (suicide) |
| Healer | Heals other enemies | Heal self, AoE heal pulse |
| Phaser | Teleports toward you | Blink through walls |
| Turret | Stationary, rapid fire | Rooted, high DPS, 360° aim |
| Charger | Telegraphed charge attack | Dash-charge through enemies |
| Siren | Pulls you toward it | Pull enemies into melee range |
| Mimic | Disguised as chest/item | Surprise burst from disguise |
| Leech | Drains HP on hit | Lifesteal on every hit |
## Progression: Three Ability Tracks
### Ghost Tree (enhance incorporeal form)
- T1: Ghost time 5s → 8s
- T2: Possession range +1 tile
- T3: Phase through walls (1s burst, cooldown)
- T4: Ghost Dash (quick movement while incorporeal)
### Body Tree (enhance possession)
- T1: Retain one ability from previous host
- T2: Overclock — temporary stat boost on possession
- T3: Dual-wield — carry two abilities simultaneously
### Meta Tree (run-level benefits)
- T1: Start each floor with a random body
- T2: See enemy types through fog of war
- T3: Shop discounts
### Shop
Between floors. Spend essence (dropped by kills, scaled by rarity). Choose one upgrade from random selection of 3.
## Systems Checklist
| Criterion | How |
|-----------|-----|
| Enemy AI + pathfinding | 12 distinct AI behaviors, A* pathfinding |
| Physics | Knockback, projectile arcs, charge, gravity pull |
| Procgen | Dungeon layout, enemy placement, item drops, shop |
| Save/load | localStorage — save on floor transition |
| Economy/progression | Essence currency, 3-track tree, shop |
| Content pipeline | 12 enemies, 10 floors, escalating difficulty, achievements |
## Tech Stack
- Single `index.html` (HTML5 Canvas + vanilla JS)
- Zero dependencies, zero build step
- Open file → play
## Competition Constraints
- One-prompt challenge (Roman Coleman / Agentic Labs)
- Harness: Pi Coding Agent
- Deadline: Aug 17, 11:59pm MDT
- Must include: public git repo, uncut gameplay video
- Floor: playable start to finish, win/lose state, 10 floors, no crashes during video take