18 KiB
Executable File
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 — move next to 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 generous 15-second 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
- Before play starts, the title screen MUST show a concise controls panel explaining movement, possession/attack, facing, confirm, and pause.
- During play, the HUD MUST show a short contextual hint for SPACE (possess while ghost; current body attack/special while possessed).
- The pause and shop screens MUST show the controls needed to leave or confirm those screens.
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: 15s real-time countdown (20s 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
- Abandon host (X): press X to voluntarily leave your current host and return to ghost form. The host SURVIVES at its current HP — it is left behind, stunned/pacified for 2 turns, and cannot be re-possessed for 2 turns (lockout) so you cannot i-frame spam one enemy. The ghost timer resumes from where it paused (it is NOT reset to 15 — only a host death resets the timer). This lets you swap to a better body or escape a doomed one without dying.
Pacing & Combat Rules (calm by default)
The default feel must be EXPLORATORY, not a swarm. Honor ALL of these — they are completion criteria:
- No friendly fire between enemies. Enemy melee, AoE explosions, charges, and projectiles ONLY ever damage the PLAYER (the ghost or your current host). Enemies never reduce each other's HP. (Your possessed host's attacks and your host's AoE still damage enemies normally, and you still get essence for those kills.) This is the single most important rule — without it, Bombers/Chargers/Turrets wipe the floor in seconds and there is no game.
- Aggro radius, not global hate. Every enemy starts DOCILE: it idles, wanders slowly, or holds position. It only begins to chase/attack when the player enters its aggro radius (about 6 tiles, gated by line of sight). Leave the aggro radius and it returns to idle after a short grace. The whole floor must NOT beeline at you on spawn.
- Slow baseline. Most melee chasers move every 2 turns (some every 3). Fast swarms and rapid fire are the exception, tuned per enemy below. The player should usually get to choose engagements.
- Ranged enemies overheat. Sentinel and Turret fire in short bursts, then OVERHEAT into a forced downtime during which they cannot shoot (and Turret is fully vulnerable). This guarantees a window to close the distance and reach them — no infinite-fire enemies you can never approach.
- Forgiving sightlines. Enemies do not aggro through walls; aggro requires a clear path or line of sight.
- Spawn safety. Keep the area around the player's spawn clear of enemies (at least 5 tiles) so a fresh floor or respawn is never an instant death.
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: Moves every 2 turns. Loose swarm — drifts toward other Skitterers and flanks the player once aggroed. 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). Fires a BURST of 3 shots (1 per turn) toward the player, then OVERHEATS for 3 turns — it cannot fire while overheated and only repositions slowly, giving the player a clear window to close or possess. Moves away if the player gets close. Projectiles hit the player only, never other enemies.
- Player kit: Medium HP (4). Shoot projectiles in facing direction. Cannot melee. Same burst/overheat rhythm as the enemy (3 shots, then a short cooldown) so it cannot infinitely stunlock.
- 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 when aggroed. On death or when adjacent, explodes (3x3 AoE, 3 damage to the player only — never other enemies).
- 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° fire at an aggroed player in a BURST (3 shots, 1 every 2 turns), then OVERHEATS for 3 turns — fully silenced and vulnerable during overheat, the window to rush it. Projectiles hit the player only, never other enemies.
- Player kit: Medium HP (4). Rooted — cannot move. Press SPACE to fire in facing direction (Q/E to rotate). High DPS in bursts, with the same overheat cooldown so it cannot fire forever.
- Color: Gray. Shape: Octagon.
9. Charger
- Enemy AI: When aggroed, telegraphs (flashes for 1 turn), then charges in a straight line toward the player's position at telegraph time. Collision with the player = 3 damage. Hits walls = stunned 2 turns. The charge does NOT damage other enemies.
- 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.
Enemy Legend (in-game bestiary)
The game MUST include a readable in-game legend that explains every enemy — both how it behaves as an opponent AND what you get when you possess it. Requirements:
- Reachable from the TITLE SCREEN before play starts (e.g. a "Legend" / "Bestiary" panel or a key such as L), and openable again during play (e.g. from the pause menu).
- One concise entry per enemy: name, color + shape, its enemy behavior, and its possessed player kit (HP / damage / special).
- Plain text is fine (canvas-drawn or a DOM overlay). Keep it scannable — a short table or list, not a wall of prose.
- This is in addition to the controls panel; do not omit it.
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 15s → 20s (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
localStoragekey: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
These controls must be explained on the title screen before the run starts, not only documented here:
- WASD / Arrow Keys: Move one tile per turn.
- SPACE while ghost: Possess an enemy within range. Explain that the ghost cannot attack.
- SPACE while possessed: Use the current host's attack or special ability. Show the current action in the HUD.
- X while possessed: Abandon your current host — eject as a ghost (the host survives, briefly pacified; see Possessed State). Show this in the contextual HUD hint while possessed.
- Q / E: Rotate facing for directional bodies such as Shielder and Turret; activate relevant ghost upgrades when incorporeal.
- ENTER: Start the game and confirm a highlighted shop/menu choice.
- ESC: Pause or resume. The pause menu includes Save + Quit.
Keep the explanation concise and readable. This is an instructions overlay, not a separate tutorial level.
Completion Criteria
The game MUST meet ALL of these. Do not consider yourself done until every one passes:
index.htmlexists, opens in a browser with zero errors in console- No external dependencies (check: no CDN links, no npm imports, no script src tags pointing externally)
- Can move as ghost with WASD/arrows
- Can possess at least 3 different enemy types
- Each possessed enemy type has distinct stats and attacks
- Procedural dungeon generates different layouts each new run
- At least 6 of the 12 enemy types are implemented and functional
- A* or BFS pathfinding works — enemies navigate around walls toward player
- Essence drops from kills and accumulates
- Shop appears between floors with 3 upgrade choices
- Upgrade choices affect gameplay (ghost timer, abilities, etc.)
- Save/load works — refresh page, select Continue, state persists
- 10 floors with escalating difficulty and enemy variety
- Win state: reach floor 10 exit → victory screen
- Lose state: ghost timer expires → game over screen with stats
- No crashes during a 5-minute continuous play session
- Fog of war renders correctly (unexplored tiles hidden, explored dimmed)
- Audio plays (procedural tones via Web Audio API)
- At least 3 achievements track and unlock
- Title screen explains all controls, and gameplay/shop/pause screens show relevant contextual controls
- Base ghost timer is 15 seconds; Ghost T1 increases it to 20 seconds
- Enemies do not damage each other (no friendly fire): enemy melee, AoE, charges, and projectiles only ever hit the player
- Enemies idle until the player enters their aggro radius (≈6 tiles, line of sight); the whole floor does not swarm the player on spawn
- An in-game enemy legend (bestiary) is reachable before play and explains each enemy's behavior + possessed kit
- The ghost can voluntarily abandon a host (press X while possessed): returns to ghost form with the timer resumed (>0), the former host survives in the enemy list, and that host cannot be immediately re-possessed (short lockout)
Testability (REQUIRED)
The game MUST expose its state for automated testing. Expose ALL of this on window.GAME:
- Properties:
state, player, enemies, grid, floor, essence, upgrades, achievements, projectiles, log stateis one of:title, playing, possessed, shop, paused, won, loststart()— initialize to the TITLE screen (do NOT auto-start play)input(key)— handle one key token; acceptArrowUp/Down/Left/Right,w a s d,andSpace,q e,x(abandon host),Enter,Escape(and a legend key such aslif used)tick(n)— advance the loop n times. It MUST be DETERMINISTIC: it advances enemy AI AND decrements the ghost timer by n steps. Do NOT tie core game state to wall-clock time (visuals/audio may use real time).spawn(type, tx, ty)— create an enemy oftypeat tile coords; returns itsetFloor(n)— debug jump: generate floor n, place the player (ghost) at spawn, stateplayingnewRun()— start a fresh floor-1 run with a NEW random layoutsave()/load()— localStorage persistence (keybodysnatcher_save)openShop()— debug: enter shop state with 3 choices;buy(index)— purchase choice at indexplayer = {x, y, ghost, timer, host, facing};enemy = {type, hp, maxHp, damage, speed, x, y, ...}grid[y][x]tile = number (0 floor, 1 wall, 2 door, 3 exit, 4 shop, 5 chest) OR object{type, solid}- The game MUST NOT crash if Canvas
getContext('2d')returns a mock object with no-op methods - The game MUST NOT crash if
AudioContextis 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 hide controls in documentation only. They must be readable in-game before play starts.
- 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.