README
Tower Defense — Isometric Overhaul (P022)
A 10-wave tower defense game with isometric 2.5D rendering, 5 tower types, 6 enemy types, and a boss Dragon encounter. Built with TypeScript and PixiJS 8 for WebGL rendering.
This is a view-layer transformation of P019's tower defense game. The engine logic is unchanged; all modifications are in src/view/, a new src/view/iso-transform.ts module, and minor config refactoring.
Quick Start
bash
cd projects/022-tower-defense-iso/3-development
npm install
npm run dev
Open the URL shown by Vite (usually http://localhost:5173).
Installation
Prerequisites: Node.js 20+, npm
bash
npm install
Commands
| Command | Action |
|---|---|
npm run dev | Start Vite dev server with hot reload |
npm run build | Production build to dist/ |
npm test | Run all tests (engine + view) |
npm run typecheck | TypeScript strict mode check |
How to Play
Tower Types
| Tower | Cost | Damage | Special | Unlocks |
|---|---|---|---|---|
| Arrow | 50g | 15 | Fast fire rate | Wave 1 |
| Cannon | 100g | 60 | Splash damage (50px) | Wave 4 |
| Ice | 75g | 0 | Slows enemies 50% for 2s | Wave 5 |
| Lightning | 150g | 30 | Chains to 3 nearby enemies | Wave 7 |
| Sniper | 200g | 120 | Long range, targets strongest | Wave 9 |
Upgrades
Available from Wave 4. Click a placed tower to see upgrade/sell options.
- Tier 2: 1x base cost. 1.5x damage, 1.15x range, 1.2x fire rate
- Tier 3: 1.5x base cost. 2x damage, 1.3x range, 1.4x fire rate
- Sell: Refunds 50% of total investment
Speed Controls
Use the 1x, 2x, 3x buttons to change game speed.
Enemy Types
| Enemy | HP | Speed | Special |
|---|---|---|---|
| Goblin | 50 | 40 | — |
| Skeleton Archer | 40 | 80 | Fast |
| Orc | 120 | 55 | Tanky |
| Armored Knight | 400 | 35 | 50% damage reduction |
| Dark Wolf | 100 | 100 | Very fast |
| Dragon (Boss) | 1000 | 50 | Disables nearby towers, costs 3 lives |
Isometric View Features
Coordinate System
- Grid space: Integer tile positions (0,0)-(19,14)
- Engine world: Continuous pixel coords (48px per cell)
- Screen space: Isometric projection onto 1152x672 canvas
Visual Enhancements
- Diamond-shaped tiles with grass shade variants, water shimmer, entry/base markers
- Isometric 3/4-angle tower sprites with tier-specific detail and shadows
- Isometric enemy sprites with direction facing and slow-effect tinting
- Trajectory-aware projectiles (arrow rotation, cannonball arc, ice spin, lightning chain, sniper tracer)
- RenderTexture caching for GPU-efficient sprite rendering
- Depth-sorted entity rendering (Y-sort with enemy/tower ordering)
- Elliptical range previews projected onto isometric ground plane
- Glass-effect health bars (green/amber/red by HP ratio)
Effects
- Per-tower fire effects (muzzle flash, cannon smoke, frost burst, lightning flash, sniper tracer)
- Type-specific enemy death particles
- Floating damage numbers (white=normal, blue=ice, gold=kill)
- Upgrade spiral sparkles
- Cannon splash shockwave rings (isometric ellipse)
- Lightning chain zigzag arcs
- Screen shake on cannon fire, dragon death, base damage
- Final-wave-kill slow-motion flash
- Environmental dust motes
- Day/night tint shift across waves
- Vignette overlay for cinematic feel
- Wave announcement text
Audio
- Per-enemy death sounds with generic fallback
- Ambient audio (calm/battle) with crossfade
- UI hover/click sounds
- Extended music track preference (long tracks when available)
Architecture
The game uses a strict engine/view separation:
- Engine (
src/engine/): Pure TypeScript, zero browser dependencies. All game logic, math, and state management. Fully testable in Node.js. Unchanged from P019 (except minor config.ts refactoring). - View (
src/view/): PixiJS 8 WebGL rendering, DOM-based UI, Web Audio API audio. Reads engine state each frame viaengine.getState(), fires engine actions on user input. - Iso-Transform (
src/view/iso-transform.ts): Pure math module for coordinate transforms between grid, world, and screen spaces. Zero browser dependencies.
8-Layer Rendering Architecture
| Layer | Description |
|---|---|
mapLayer | Diamond tiles (grass, path, water, entry, base) |
shadowLayer | Ground shadows for towers and enemies |
buildSpotLayer | Empty build spot diamond indicators |
entityLayer | Towers + enemies (Y-sorted together) |
projectileLayer | Projectiles in flight |
effectLayer | Range preview, frost effects, sniper tracers |
particleLayer | Particles, floating text, dust motes |
uiEffectLayer | Vignette, day/night tint, screen shake offset |
Engine API
typescript
const engine = new GameEngine();
engine.placeTower(spotId, TowerType.Arrow);
engine.upgradeTower(towerId);
engine.sellTower(towerId);
engine.startNextWave();
engine.setSpeed(2);
engine.update(dt);
const state = engine.getState();
Build Output
npm run build produces a dist/ folder that can be served with any static HTTP server.