Game: Tower Defense
Theme: Cyberpunk
Map: Single Path
Date: 2026-04-18

## Prompt

Create a complete single-file 3D cyberpunk tower defense game using Three.js. The game is called "FIREWALL: The Grid Defends Itself." One HTML file, no external assets, all 3D geometry built programmatically.

### Theme & Visual Style

**Palette:** Night black (#0a0a14), neon pink (#ff00aa), electric cyan (#00ffee), warning amber (#ffaa00), grid purple (#8800ff)

**Terrain:** Dark city blocks forming a grid. The enemy path is a glowing neon-lit street. Ground plane uses dark grey material (#0a0a14) with faint grid lines. Path is emissive material (#00ffee at 0.3 intensity). Add subtle holographic billboard planes (flat vertical planes with emissive materials) at the edges. Include a light rain particle system for atmosphere.

**Lighting:** Ambient light at 0.3 intensity, directional light with shadows from above at 45 degrees. Add pink and cyan point lights near towers for atmosphere. Scene fog for depth (color #050510, density 0.02).

**Skybox:** Dark gradient from #0a0a14 (top) to #1a1a2e (bottom).

### Map Layout (Single Path)

Grid: 15x12 tiles, each tile 2.0 units.

Path coordinates (tile x, tile y starting from bottom-left):
(0,6), (1,6), (2,6), (3,6), (4,6), (5,6), (6,6), (6,7), (6,8), (7,8), (8,8), (9,8), (9,7), (9,6), (9,5), (9,4), (10,4), (11,4), (12,4), (13,4), (14,4)

Entry: Left edge at (0,6). Base/Exit: Right edge at (14,4).

Path makes 4 turns: starts heading east, turns north at (6,6), turns east at (6,8), turns south at (9,8), turns east at (9,4) to exit.

Buildable tiles: All tiles adjacent to the path (Manhattan distance <= 1) except path tiles themselves.

### Tower Types (6 types)

**1. Turret Node (Basic)**
- Cost: 100 gold
- Damage: 15
- Range: 12 units
- Fire Rate: 1.0 shots/sec
- Visual: Angular box base (1.5x1.5x1.0) + rotating top cylinder (0.8 diameter, 0.5 height) with small cube barrel
- Color: Dark grey (#2a2a3a) base, neon pink (#ff00aa) accents
- Projectile: Small pink sphere (0.15 radius), travels at 20 units/sec

**Upgrade Path:**
- Level 2 (150 gold): +40% damage (21), +10% range (13.2). Visual: Larger rotating top, additional pink glow ring.
- Level 3 (250 gold): +100% damage (30), +25% range (15). Ability: Piercing shots (hits 2 enemies in a line). Visual: Dramatic change - spire rises from center with rotating holographic ring.

**2. Railgun Spike (Sniper)**
- Cost: 200 gold
- Damage: 60
- Range: 22 units
- Fire Rate: 0.4 shots/sec
- Visual: Tall thin spire (0.5x0.5 base, 3.5 height) with horizontal barrel at top
- Color: Dark grey with electric cyan (#00ffee) energy lines
- Projectile: Cyan beam (raycaster line), instant hit with 0.3s beam duration

**Upgrade Path:**
- Level 2 (300 gold): +40% damage (84), +10% range (24.2). Visual: Additional horizontal stabilizers.
- Level 3 (500 gold): +100% damage (120), +25% range (27.5). Ability: Critical hits (30% chance for 2.5x damage). Visual: Massive energy crystal at top, beam widens.

**3. EMP Bomb (Splash)**
- Cost: 175 gold
- Damage: 25 (area damage)
- Range: 10 units
- Fire Rate: 0.7 shots/sec
- Splash Radius: 4 units
- Visual: Dome structure (sphere 1.2 radius, bottom half cut off) with purple pulses
- Color: Grid purple (#8800ff) with pulse animation
- Projectile: Purple sphere that arcs to target, explodes with expanding ring

**Upgrade Path:**
- Level 2 (260 gold): +40% damage (35), +10% range (11), +25% splash radius (5). Visual: Dome grows spikes.
- Level 3 (440 gold): +100% damage (50), +25% range (12.5), +50% splash radius (6). Ability: Burn DOT (10 damage/sec for 3 sec). Visual: Dome becomes spiky crystalline structure with inner glow.

**4. Firewall (Slow)**
- Cost: 150 gold
- Damage: 5
- Range: 8 units
- Fire Rate: 0.5 shots/sec
- Slow Effect: -40% speed for 3 seconds
- Visual: Wall of 5 vertical neon lines (cylinders 0.1 diameter, 2.0 height) arranged in semicircle
- Color: Warning amber (#ffaa00) neon lines
- Projectile: Amber energy wave that spreads

**Upgrade Path:**
- Level 2 (225 gold): +40% damage (7), +10% range (8.8), -50% slow. Visual: 7 lines, taller.
- Level 3 (375 gold): +100% damage (10), +25% range (10). Ability: Freeze (complete stop for 1.5s). Visual: Double wall of lines with crackling energy between them.

**5. Bit Storm (Rapid)**
- Cost: 125 gold
- Damage: 4
- Range: 10 units
- Fire Rate: 4.0 shots/sec
- Visual: Hovering cube (1.0 size) that rotates, with 4 small barrels on corners
- Color: Dark grey with cyan (#00ffee) barrel tips
- Projectile: Tiny cyan cubes fired rapidly

**Upgrade Path:**
- Level 2 (190 gold): +40% damage (5.6), +10% range (11). Visual: Cube gains orbital rings.
- Level 3 (310 gold): +100% damage (8), +25% range (12.5). Ability: Double barrel (2 projectiles per shot). Visual: Complex geometric shape with 8 barrels, glows intensely.

**6. Blackout (Special)**
- Cost: 300 gold
- Damage: 20
- Range: 15 units
- Fire Rate: 0.5 shots/sec
- Special: Disables all enemies in range for 2 seconds every 8 seconds
- Visual: Large antenna array (2.5 height) with dish and rotating radar
- Color: Black with purple (#8800ff) pulse rings
- Projectile: Purple energy pulse

**Upgrade Path:**
- Level 2 (450 gold): +40% damage (28), +10% range (16.5), disable 2.5s. Visual: Second dish added.
- Level 3 (750 gold): +100% damage (40), +25% range (18.75), disable 3s + damage boost aura (+15% damage to nearby towers). Visual: Massive antenna complex with energy dome.

### Enemy Types (6 types)

**1. Malware Drone (Scout)**
- HP: 30
- Speed: 4 units/sec
- Armor: None
- Gold: 5
- Visual: Small cube (0.6 size) with glitching shader effect, floating
- Color: Neon pink (#ff00aa)
- Special: Appears in swarms (15-20 per wave)

**2. Trojan Walker (Soldier)**
- HP: 80
- Speed: 2.5 units/sec
- Armor: Light (10% damage reduction)
- Gold: 10
- Visual: Capsule shape (0.8 diameter, 1.5 height), upright
- Color: Dark grey with red circuits
- Special: Standard balanced threat

**3. Worm Swarm (Sprinter)**
- HP: 25
- Speed: 6 units/sec
- Armor: None
- Gold: 8
- Visual: Chain of 3 small spheres (0.4 radius each), moves like a snake
- Color: Grid purple (#8800ff)
- Special: Very fast, rushes through defenses

**4. Ransomware Tank**
- HP: 250
- Speed: 1.5 units/sec
- Armor: Heavy (25% damage reduction)
- Gold: 25
- Visual: Large box (1.2 size) with skull icon texture on front
- Color: Dark grey with amber warning stripes
- Special: Encrypts/disables towers it passes for 3 seconds

**5. Healer Bot**
- HP: 100
- Speed: 2 units/sec
- Armor: None
- Gold: 15
- Visual: Sphere (0.7 radius) with rotating ring
- Color: Cyan (#00ffee)
- Special: Heals nearby enemies 5 HP/sec within 5 units

**6. AI Core Boss**
- HP: 2000 (wave 5), scales +15% per boss wave
- Speed: 1 unit/sec
- Armor: Heavy (30% damage reduction)
- Gold: 100
- Visual: Massive glowing polyhedron (2.5 size icosahedron) with rotating rings
- Color: Shifts between pink, cyan, and purple
- Special: Spawns malware drones every 10 seconds, immune to slow

### Wave System (20 waves)

Wave composition is predefined, not random. HP and speed scale +15% and +5% per wave respectively, capped at 8x and 2.5x base values.

Wave 1: 10 Malware Drones (tutorial wave - simple)
Wave 2: 15 Malware Drones
Wave 3: 8 Malware Drones, 5 Trojan Walkers
Wave 4: 12 Trojan Walkers, 3 Worm Swarms
Wave 5: AI Core Boss (wave boss), 10 Malware Drones
Wave 6: 20 Worm Swarms (swarm wave)
Wave 7: 5 Trojan Walkers, 2 Ransomware Tanks
Wave 8: 15 Malware Drones, 8 Trojan Walkers, 5 Worm Swarms
Wave 9: 3 Ransomware Tanks, 2 Healer Bots
Wave 10: AI Core Boss, 15 Malware Drones, 5 Trojan Walkers (boss wave)
Wave 11: 25 Worm Swarms, 10 Malware Drones
Wave 12: 8 Trojan Walkers, 4 Ransomware Tanks, 1 Healer Bot
Wave 13: 30 Malware Drones (swarm)
Wave 14: 10 Trojan Walkers, 6 Ransomware Tanks, 2 Healer Bots
Wave 15: AI Core Boss x2, 20 Malware Drones (boss wave)
Wave 16: 15 Worm Swarms, 10 Trojan Walkers, 5 Ransomware Tanks
Wave 17: 5 Ransomware Tanks, 3 Healer Bots
Wave 18: 40 Malware Drones (major swarm)
Wave 19: 20 Trojan Walkers, 8 Ransomware Tanks, 4 Healer Bots
Wave 20: AI Core Boss x3, 30 Malware Drones, 10 Trojan Walkers (final boss wave)

Boss waves (5, 10, 15, 20): Show "BOSS INCOMING" warning 3 seconds before spawn.
Inter-wave break: 15 seconds (skip button available).

### Economy

- Starting gold: 400 (enough for 4 basic towers or 2 advanced)
- Interest: 2% per wave on unspent gold
- Sell refund: 60% of total investment

Gold per kill:
- Malware Drone: 5
- Trojan Walker: 10
- Worm Swarm: 8
- Ransomware Tank: 25
- Healer Bot: 15
- AI Core Boss: 100

### Base / Lives

- Base HP: 20 lives
- Malware Drone: -1 life
- Trojan Walker: -1 life
- Worm Swarm: -1 life
- Ransomware Tank: -2 life
- Healer Bot: -1 life
- AI Core Boss: -5 life

Game over at 0 lives. Victory at surviving wave 20.

### 3D Rendering Requirements

**Camera:** Perspective camera at position (15, 20, 25) looking at (15, 0, 6). Zoom range: 10-40 units. Pan limits: x[-5, 35], z[-10, 20]. Reset button (R key) returns to default.

**Controls:** Mouse wheel zoom, right-click drag to pan. Touch: pinch zoom, two-finger pan.

**Tower rotation:** Towers rotate to face their current target. Lerp rotation for smoothness.

**Projectiles:** Visible travel from tower to target with lerp. Speed: 20-30 units/sec depending on tower.

**Enemy health bars:** Billboard sprites above each enemy showing HP as colored bar (green > 60%, yellow 30-60%, red < 30%).

**Effects:**
- Particle burst on enemy death (themed to killer tower type)
- Range indicator: Semi-transparent circle when placing towers or selecting existing
- Grid overlay: Faint lines on buildable tiles
- Tower placement: Tower rises from ground with build animation (0.5s)

### UI (DOM Overlay)

**HUD (always visible, top bar):**
- Gold counter with coin icon
- Lives counter with heart icon
- Wave counter: "Wave 3 / 20"
- Wave timer: Countdown to next wave
- Speed controls: 1x / 2x / 3x buttons
- Pause button

**Tower Panel (bottom bar, 6 tower buttons):**
- Each button: Icon, name, cost
- Greyed out if unaffordable
- Selected state highlight
- Click to select tower type, then click map to place

**Tower Info (appears when clicking existing tower):**
- Tower name and level
- Stats: Damage, range, fire rate
- Upgrade button (if not max level, shows cost)
- Sell button (shows refund amount)
- Targeting priority: First / Strongest / Weakest / Fastest (cycles on click)

**Game State Screens:**
- Start: Title "FIREWALL", subtitle "The Grid Defends Itself", "Start Game" button
- Pause: Semi-transparent overlay, "PAUSED", Resume/Restart/Quit buttons
- Game Over: "SYSTEM FAILURE", stats, "Try Again" button
- Victory: "GRID SECURED", stats, "Play Again" / "Endless Mode" buttons

**Wave Preview:** Before each wave, show upcoming enemy types and counts in a small panel.

### Performance Requirements

- Target: 60fps with 30 enemies and 15 towers
- Use object pooling for projectiles and particles
- Frustum culling via Three.js
- Cap active enemies at 50 (queue spawns if exceeded)
- Cap active projectiles at 100
- Cap particles at 500

### Technical Implementation

Single HTML file structure:
1. HTML head with meta tags, title, SEO metadata
2. CSS styles for UI overlay (flexbox layout, cyberpunk theme colors)
3. Three.js CDN import
4. Game code:
   - Game state management
   - Three.js scene setup
   - Map generation (grid, path, buildable tiles)
   - Tower class with upgrade system
   - Enemy class with path following
   - Projectile system
   - Wave management
   - Economy system
   - UI event handlers
   - Game loop with delta time

No external images or models. All geometry built with Three.js primitives (BoxGeometry, SphereGeometry, CylinderGeometry, etc.).

### Game Loop Structure

```javascript
// Fixed time step game loop
deltaTime = clock.getDelta() * gameSpeed;

// Update towers (targeting, firing)
// Update enemies (path following, health, effects)
// Update projectiles (movement, collision)
// Update particles
// Check wave completion
// Update UI

// Rendering
renderer.render(scene, camera);
```

Tower targeting priorities:
- First: Closest to base (default)
- Strongest: Highest HP
- Weakest: Lowest HP
- Fastest: Highest speed

### Audio (Optional - Web Audio API)

Procedural sounds using oscillators:
- Tower fire: Short beep/burst (different tone per tower type)
- Enemy death: Pop sound
- Wave start: Alert chord
- Boss incoming: Low rumble
- Game over: Descending tones
- Victory: Ascending chord

Mute button in HUD.

### SEO & Social Metadata

```html
<meta name="description" content="FIREWALL: A cyberpunk 3D tower defense game. Build neon turrets, defend the grid against rogue AI.">
<meta property="og:title" content="FIREWALL - Cyberpunk Tower Defense">
<meta property="og:description" content="Build neon turrets, defend the grid against rogue AI in this 3D tower defense game.">
<meta property="og:type" content="website">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="FIREWALL - Cyberpunk Tower Defense">
<meta name="twitter:description" content="Build neon turrets, defend the grid against rogue AI.">
```

## Notes

**Balance Rationale:**
- Basic towers are cost-effective early game, fall off late without upgrades
- Sniper towers essential for high-HP enemies but poor against swarms
- Splash towers dominate clustered areas but have limited range
- Slow towers enable other towers to fire more shots
- Rapid towers scale well with damage upgrades
- Special tower (Blackout) provides crowd control but expensive

**Visual Theme Decisions:**
- Neon pink = damage/turrets, cyan = tech/energy, purple = special/magic, amber = warnings
- Glitch effects on malware drones emphasize the "bug" concept
- Rotating elements on towers show activity
- Rain particles add atmosphere without hurting performance
- Boss polyhedron shape evokes "AI core" aesthetic

**Difficulty Curve:**
- Wave 1-4: Introduce basic enemies, let player learn placement
- Wave 5: First boss teaches importance of upgrades
- Wave 6-9: Mix enemy types requires diverse tower composition
- Wave 10: Boss tests build quality
- Wave 11-19: Increasing pressure, economy management critical
- Wave 20: Final test with multiple bosses

**Path Design:**
- The S-curve creates 4 natural chokepoints for splash towers
- Long straight sections reward snipers
- Interior pocket at (7-8, 6-7) is premium real estate
- Path length of 21 tiles gives towers multiple shots per enemy
