13 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
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 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.
- 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
Testability (REQUIRED)
The game MUST expose its state for automated testing:
window.GAMEobject 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
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.