Skip to content

Repository files navigation

Tower Defense Game ๐Ÿฐ

A modern tower defense game built entirely by Claude Code - demonstrating AI-powered game development with clean architecture and engaging gameplay.

Game Screenshot

Play the Game โ†’

About

This is a complete tower defense game featuring:

  • ๐ŸŽฎ Wave-based enemy spawning with progressively harder enemies
  • ๐Ÿ’ฐ Economic system with upgrades and permanent progression
  • โšก Active abilities and kill streak bonuses
  • ๐ŸŽจ Smooth animations and visual effects
  • ๐Ÿ“Š Simulator for testing game balance
  • ๐Ÿ’พ Persistent progress with essence-based meta-progression

Built with AI

This entire game was created by Claude Code, showcasing how AI can build production-ready applications with:

  • Clean, modular architecture
  • Type-safe TypeScript implementation
  • Performance-optimized rendering
  • Comprehensive game systems

Getting Started

Prerequisites

  • Node.js 18+ and npm
  • Modern web browser with WebGL support

Installation

# Clone the repository
git clone https://github.com/mdkess/claude-game.git
cd claude-game

# Install dependencies
npm install

# Run development server
npm run dev

# Build for production
npm run build

# Run tests/simulator
./test-simulator.sh balanced 120 summary

Debug Mode

Access debug features by adding ?debug=true to the URL:

http://localhost:3000/?debug=true

Debug mode enables:

  • DEBUG: -100 HP - Deal 100 damage to your tower
  • DEBUG: +1000 Gold - Add 1000 gold instantly
  • DEBUG: +100 Essence - Add 100 essence instantly

Architecture Overview

The game uses a clean, decoupled architecture with clear separation of concerns:

Core Systems (/src/game/)

game/
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ GameCore.ts      # Core game logic (no rendering)
โ”‚   โ”œโ”€โ”€ EventEmitter.ts  # Event system for loose coupling
โ”‚   โ””โ”€โ”€ constants.ts     # Game configuration
โ”œโ”€โ”€ entities/
โ”‚   โ”œโ”€โ”€ Enemy.ts         # Enemy logic (no graphics)
โ”‚   โ”œโ”€โ”€ Tower.ts         # Tower defense logic
โ”‚   โ””โ”€โ”€ Projectile.ts    # Projectile physics
โ”œโ”€โ”€ systems/
โ”‚   โ”œโ”€โ”€ WaveSystem.ts    # Wave spawning logic
โ”‚   โ”œโ”€โ”€ CombatSystem.ts  # Combat calculations
โ”‚   โ””โ”€โ”€ UpgradeSystem.ts # Upgrade progression
โ”œโ”€โ”€ renderers/
โ”‚   โ”œโ”€โ”€ EnemyRenderer.ts # PIXI rendering for enemies
โ”‚   โ”œโ”€โ”€ TowerRenderer.ts # Tower visuals
โ”‚   โ””โ”€โ”€ ProjectileRenderer.ts
โ””โ”€โ”€ Game.ts              # Main game class (extends GameCore with rendering)

Key Design Principles

  1. Separation of Logic and Rendering

    • GameCore contains all game logic without any graphics
    • Renderers handle all visual representation
    • Enables headless simulation for testing
  2. Entity Component System

    • Entities (Enemy, Tower, Projectile) contain only data and logic
    • Renderers manage the visual representation
    • Clean separation allows for easy testing and different render targets
  3. Event-Driven Architecture

    • Systems communicate through events
    • Loose coupling between components
    • Easy to extend with new features
  4. Object Pooling

    • Enemies and projectiles are pooled for performance
    • Reduces garbage collection pressure
    • Smooth performance even with many entities

Frontend (/src/components/)

  • GameCanvas.tsx: Main React component that initializes the game
  • GameUI.tsx: HUD and upgrade interface
  • EssenceMenu.tsx: Permanent upgrade shop

Simulator (/src/simulator/)

  • HeadlessGame.ts: Extends GameCore for simulation without graphics
  • Simulator.ts: Runs automated gameplay with different strategies
  • strategies.ts: AI strategies for testing game balance

Game Features

Combat System

  • Tower automatically targets nearest enemy
  • Projectile physics with collision detection
  • Multi-shot and bounce mechanics for upgraded towers

Wave System

  • Hand-crafted early waves for balanced difficulty curve
  • Procedural generation after wave 10
  • Multiple enemy types:
    • Basic: Standard enemies
    • Swarm: Fast, weak enemies that spawn in groups
    • Tank: Slow, high-health enemies
    • Splitter: Enemies that split into swarms when killed

Upgrade System

In-Game Upgrades

  • Offensive: Damage, Fire Rate, Range
  • Defensive: Max Health, Health Regeneration
  • Economic: Gold per Round, Interest

Permanent Upgrades (Essence)

  • Starting stats boosts
  • Economic multipliers
  • Special abilities (multi-shot, bounce)

Special Features

  • Speed Boost: Active ability with cooldown
  • Kill Streaks: Chain kills for damage bonuses
  • Perfect Waves: Bonus gold for taking no damage
  • Interest System: Earn percentage of current gold per second

Development

File Structure

src/
โ”œโ”€โ”€ app/              # Next.js app directory
โ”œโ”€โ”€ components/       # React components
โ”œโ”€โ”€ game/            # Game logic and rendering
โ”‚   โ”œโ”€โ”€ core/        # Core game systems
โ”‚   โ”œโ”€โ”€ entities/    # Game objects
โ”‚   โ”œโ”€โ”€ systems/     # Game mechanics
โ”‚   โ”œโ”€โ”€ renderers/   # Visual components
โ”‚   โ””โ”€โ”€ effects/     # Visual effects
โ””โ”€โ”€ simulator/       # Balance testing tools

Key Technologies

  • React + Next.js: Modern web framework
  • TypeScript: Full type safety
  • PixiJS v8: High-performance 2D rendering
  • Tailwind CSS: Utility-first styling

Testing & Balance

Run the simulator to test different strategies:

# Test balanced strategy for 2 minutes
./test-simulator.sh balanced 120 summary

# Test with permanent upgrades
./test-simulator.sh balanced 120 summary 5 2 3 1 1 0.5 0.5

# Test all strategies
for strategy in cheapest damage balanced tank adaptive greedy economic; do
  echo "Testing $strategy..."
  ./test-simulator.sh $strategy 60 summary | grep "Survived:"
done

Contributing

This project was created as a demonstration of AI-powered development. Feel free to:

  • Report bugs or suggest features
  • Fork and create your own variations
  • Use as a template for your own games

License

MIT License - feel free to use this code for any purpose!

Acknowledgments

Created entirely by Claude Code (Anthropic's Claude) - demonstrating the capabilities of AI-assisted software development for complex, production-ready applications.

Special thanks to the open-source libraries that made this possible:

  • PixiJS for rendering
  • Next.js for the framework
  • TypeScript for type safety

Releases

Packages

Contributors

Languages