File size: 1,985 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Browser tower-defense prototype

Build a simple 2D tower-defense game that runs offline from the root `index.html`. Render a map with a path, enemies that travel along it, and a tower type the player can place. A tower damages enemies within range. An enemy that reaches the end without being defeated costs one life and does not count as a kill.

## Simulation interface

Expose `window.gameTest` with `reset()`, `spawnEnemy(options?)`, `placeTower(x, y, options?)`, `step(milliseconds)`, and `state()`. Use the same movement, combat and rendering as the game. After `reset()`, only explicit steps advance the deterministic scenario, and the page reflects those updates.

Return `{path, enemies, towers, lives, kills}`. The path contains at least two distinct `{x, y}` points in scene pixels. An enemy exposes `{seg, t, hp, speed, position}`; `t` is progress from 0 to 1 along segment `seg`, and `position` is `{x, y}` or `null`. A new enemy starts on segment 0 at progress 0 with 3 HP. `spawnEnemy({speed: 0})` keeps it at the start; no options uses normal speed. A tower exposes `{x, y, range}`. `placeTower(x, y, {range})` uses the supplied finite, nonnegative range; otherwise use the default.

Advance movement and combat in 16 ms steps, carrying a remainder into the next call. `step(0)` does not advance the simulation. A newly placed tower damages an enemy that remains within range within 2,048 ms; it deals no damage outside range.

## Acceptance Checklist

- The offline entry renders the map and spawned enemies. Enemy progress and position stay consistent with the path; an escaped enemy is removed, costs one life and does not award a kill.
- Zero or sub-step time advances do not move an enemy. Accumulated time triggers the next fixed step, and the scene reflects simulation updates.
- A zero-speed enemy stays in place. Towers honor range overrides and damage or defeat continuously in-range enemies within the specified time without damaging out-of-range enemies.