244 lines
12 KiB
Markdown
Executable File
244 lines
12 KiB
Markdown
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 — 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.
|