A 3D tower defense game rendered entirely with CSS 3D transforms and vanilla JavaScript.
No Canvas, no WebGL, no game engine — just pure CSS and DOM elements in a 45-degree isometric world.
Themed around Maori mythology with cloud saves, leaderboards, and daily challenges.
Tech Stack
Share This Project
Important
Every tower, enemy, projectile, and particle in this game is a DOM element styled with CSS 3D transforms. There is no <canvas>, no WebGL, and no game engine — the entire 3D isometric world is rendered by the browser's CSS engine. The game features Maori mythology theming, a full cloud backend, daily challenges, crafting, and progression systems.
Table of Contents
- Introduction
- Key Features
- Tech Stack
- Architecture
- Getting Started
- How to Play
- Game Guide
- Deployment
- API Reference
- Contributing
- License
- Author
|
Te Pa Tiaki (The Protective Fortress) is a tower defense game where the entire 3D world is rendered using CSS 3D transforms. Every game object — towers, enemies, projectiles, explosions, weather particles — is a real DOM element positioned and rotated in 3D space using The game is themed around Maori mythology and culture of Aotearoa (New Zealand). Towers are named after Maori weapons and atua (deities) — Taiaha, Mere, Tangaroa, Tohunga, Tawhiri, Mahuika. Enemies draw from Maori legends — Kehua (spirits), Patupaiarehe (fairy folk), Toa (warriors), Wairua (ethereal ghosts), Tipua (supernatural giants), and the mighty Taniwha (water guardians). Materials are taonga (treasures) — Pipi, Koiwi, and Pounamu. Beyond the core tower defense gameplay, the project includes a full cloud backend powered by Cloudflare Workers with authentication, leaderboards, cloud saves, daily challenges, and progression sync — while preserving a fully functional guest mode that works without an account. |
Note
- Chrome recommended (hardware acceleration for best CSS 3D performance)
- Works in Firefox, Safari, and Edge
- No account required — guest mode is fully supported
Every visual element is a styled DOM node — no Canvas, no WebGL. The game uses CSS 3D transforms to create a full isometric 3D world with a Comic / Pop-Art visual style.
- Pure CSS 3D — All objects rendered with
transform-style: preserve-3d, 45-degree isometric perspective at 1200px - Comic / Pop-Art Style — Halftone dot patterns, hard-offset pop shadows, thick comic borders, warm palette (#FFF8F0)
- Object Pooling — DOM element reuse via
Pool.acquire()/Pool.release()for smooth 60fps performance - Dynamic Theming — CSS custom properties driven by JavaScript for day/night, weather, and seasonal palette transitions
- All CSS Shapes — Towers, enemies, and icons built with
clip-path,border-radius, and pseudo-elements — no emoji, no images
Towers, enemies, materials, and abilities all draw from te reo Maori and Maori mythology, creating an authentic cultural experience.
6 Towers named after Maori weapons and atua:
| Tower | Meaning | Role |
|---|---|---|
| Taiaha | Traditional fighting staff | Fast single-target archer |
| Mere | Pounamu greenstone club | Splash damage cannon |
| Tangaroa | Ocean deity | Slowing ice tower |
| Tohunga | Spiritual leader | Armor-piercing magic |
| Tawhiri | Storm god | Chain lightning |
| Mahuika | Fire goddess | Damage-over-time flames |
6 Enemies from Maori mythology:
| Enemy | Meaning | Special |
|---|---|---|
| Kehua | Wandering spirits | Basic |
| Patupaiarehe | Fairy folk | Fast |
| Toa | Warriors | Armored |
| Wairua | Ethereal spirits | Stealth phases |
| Tipua | Supernatural giants | Trample stun |
| Taniwha | Water guardians | Boss with 3 skills |
3 Maps: Te Awa (The River), Te Maunga (The Mountain), Te Moana (The Ocean)
- Boss Skills — Taniwha boss uses Karanga (summon minions), Kaitiaki (shield), Te Riri (enrage)
- Tower Synergies — Adjacent tower combos: Freeze Lightning, Fire Blast, Blessing, Array
- Reforging — Terraria-inspired random prefixes from Common to Legendary rarity
- Combo System — Chain kills within 1.5s for escalating gold bonuses
- Mana Abilities — Active ability system with cooldowns
- Critical Hits — Chance-based bonus damage with visual feedback
- 4 Enemy Variants — Rangatira (elite), Pakanga (armored), Tere (swift), Mate (deadly)
- 10 Progressive Waves with 3 difficulty modes (Normal, Hard, Expert)
- Endless Mode to keep playing beyond wave 10
- Day/Night Cycle tied to waves with weather and seasonal effects
- Blood Moon night events with escalating probability
- XP and Tech Tree with 10 upgrades and skill points
- Inventory and Loot — Terraria-inspired material drops (Pipi, Koiwi, Pounamu)
- Crafting System — 6 consumable recipes from gathered materials
- Daily Challenges — 20+ templates across 6 categories with score bonuses
- Achievement System — Combat, progression, and challenge categories with gold rewards
- Cloud Backend — Auth, leaderboard, cloud saves (3 slots), stats tracking
- Anti-Cheat — Server-side score validation
- Interactive Tutorial — 4-step onboarding with spotlight highlights for new players
- Dynamic Music — Music adapts to game state (menu, playing, boss, victory, defeat)
- Synthesized Audio — Web Audio API synth effects + Howler.js for music and samples
- Keyboard Shortcuts — 1-6 for tower selection, Space for wave, Esc for pause
- Settings Panel — Volume control persisted to localStorage
| Layer | Technology | Purpose |
|---|---|---|
| Rendering | CSS 3D Transforms | Isometric 3D game world, all visual elements |
| Logic | Vanilla JavaScript (ES6) | Game loop, AI, physics — IIFE modules with event-driven communication |
| Styling | LESS | Variables, mixins, dynamic theming (13 stylesheets) |
| Build | Gulp 4 | Script concatenation, LESS compilation, minification |
| Audio | Web Audio API + Howler.js | Synthesized SFX + music/sample playback |
| Backend | Cloudflare Workers | Serverless edge compute |
| Framework | Hono | Lightweight HTTP router for Workers |
| Database | Neon DB (PostgreSQL) | Serverless PostgreSQL via @neondatabase/serverless |
| ORM | Drizzle ORM | Type-safe database queries and migrations |
| Auth | Better Auth | Session cookie authentication |
| Validation | Zod | Runtime schema validation |
| CI/CD | GitHub Actions | Automatic deployment on push to main |
System Architecturegraph TB
subgraph "Browser Client"
HTML["index.html"]
CSS["CSS 3D Engine<br/>13 LESS Stylesheets"]
JS["23 JS Modules<br/>IIFE Pattern"]
AUDIO["Web Audio API<br/>+ Howler.js"]
end
subgraph "Build Pipeline"
GULP["Gulp 4"]
LESS_C["LESS Compiler"]
UGLIFY["UglifyJS + CleanCSS"]
end
subgraph "Cloud Backend"
CF["Cloudflare Workers"]
HONO["Hono Framework"]
AUTH["Better Auth<br/>Session Cookies"]
DRIZZLE["Drizzle ORM"]
NEON["Neon PostgreSQL<br/>10 Tables"]
AC["Anti-Cheat<br/>Score Validation"]
end
GULP --> HTML
LESS_C --> CSS
UGLIFY --> JS
JS -->|"API.silentRequest()"| CF
CF --> HONO
HONO --> AUTH
HONO --> DRIZZLE
HONO --> AC
DRIZZLE --> NEON
|
Event-Driven Game LoopAll game systems communicate via flowchart LR
Controller -->|init| Game
Game -->|"tick(dt)"| Tower
Game -->|"tick(dt)"| Enemy
Game -->|"tick(dt)"| Projectile
Game -->|"tick(dt)"| Weather
Tower -->|towerFired| Projectile
Projectile -->|enemyKilled| Game
Game -->|enemyKilled| Progression
Game -->|enemyKilled| Inventory
Game -->|enemyKilled| Achievements
Game -->|comboKill| Display
Wave -->|waveStarted| Seasons
Wave -->|waveStarted| Weather
Wave -->|waveComplete| Game
Enemy -->|bossSpawned| Display
Enemy -->|enemyReachedEnd| Game
Key events: |
Project Structure |
Important
Ensure you have the following installed:
- Node.js 18.0+ (Download)
- npm (included with Node.js)
# Clone the repository
git clone https://github.com/ChanMeng666/css-tower-defense.git
cd css-tower-defense
# Install dependencies
npm install
# Build the project
npm run buildOpen index.html in a modern browser, or use a local server:
python -m http.server 8080
# or
npx servenpm run watch # Watch mode (auto-rebuild on file changes)
npm run build # Development build (unminified)
npm run compile # Production build (minified output in dist/)
npm run dev # Concurrent frontend watch + backend dev server# Set up Wrangler secrets
cd worker && npx wrangler secret put DATABASE_URL
cd worker && npx wrangler secret put BETTER_AUTH_SECRET
# Database commands
npm run db:generate # Generate Drizzle migrations
npm run db:migrate # Run migrations
npm run db:studio # Open Drizzle Studio
# Deploy backend + frontend
npm run deploy # Compiles frontend + deploys worker- Choose Map and Difficulty — Select from 3 maps and 3 difficulty modes on the start screen
- Select a Tower — Click a tower type in the shop panel (or press
1-6) - Place Tower — Click on a grass cell to place it
- Start Wave — Press
Spaceor click "Start Wave" - Defend — Towers automatically attack enemies in range
- Upgrade and Reforge — Click placed towers to upgrade (3 levels) or reforge for random prefixes
- Collect Loot — Enemies drop Pipi, Koiwi, and Pounamu materials
- Craft Consumables — Use materials to craft buffs and shields
- Earn XP — Level up and spend skill points in the tech tree
- Save Progress — Press
F5to quick-save,F9to quick-load (3 cloud slots when logged in) - Survive — Don't let enemies reach the end of the path!
| Key | Action |
|---|---|
1-6 |
Quick-select tower types |
Space |
Start next wave |
Esc |
Deselect tower / Close panels / Pause |
Click |
Place tower / Select placed tower |
F5 |
Quick save |
F9 |
Quick load |
Tip
First-time players will see an interactive 4-step tutorial with spotlight highlights guiding them through tower placement and wave management.
Tower Guide
Upgrades: Each tower can be upgraded to level 3 (+50% damage, +10% range, -10% cooldown per level). Upgrade cost: Reforging: Towers can be reforged for random prefixes at 50% base cost:
Synergies: Place towers adjacent to each other for combo bonuses:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Enemy Bestiary
Taniwha Boss Skills:
Enemy Variants (Maori terms):
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Environmental SystemsDay / Night Cycle:
Tied to waves — odd waves are daytime (sun at 90 degrees), even waves are nighttime (270 degrees). Night uses warm navy Seasons:
Each season changes the map's color palette (grass, path, sky) via CSS custom properties and provides tower/gold modifiers. Weather: Randomly selected each wave based on seasonal weights: Clear, Rain, Fog, Wind, Snow, Heat Wave. Each type applies gameplay modifiers to tower range, enemy speed, and gold income. Blood Moon:
Night-only event (even waves) with probability = |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Progression and EconomyTech Tree — Earn XP from kills (
Materials (Terraria-inspired drops):
Variant enemies have increased drop rates (1.2x-2.0x multipliers). Crafting Recipes:
Difficulty Modes:
Starting Resources: 100 gold (+ Progression bonus), 20 lives (+ Progression bonus) Combo System: 1.5s timeout between kills. Minimum 3 kills for bonus. 10% extra gold per kill in combo + |
The frontend is deployed to GitHub Pages via GitHub Actions. On every push to main, the CI pipeline compiles the production build and deploys dist/ automatically.
The backend runs on Cloudflare Workers and deploys via Wrangler:
# Set secrets (one-time)
cd worker && npx wrangler secret put DATABASE_URL
cd worker && npx wrangler secret put BETTER_AUTH_SECRET
# Deploy (compiles frontend + deploys worker)
npm run deploy| Variable | Required | Purpose |
|---|---|---|
DATABASE_URL |
Yes | Neon PostgreSQL connection string |
BETTER_AUTH_SECRET |
Yes | Auth session encryption key |
10 tables managed by Drizzle ORM: user, session, account, verification (Better Auth), profiles, leaderboard_entries, game_saves, progression, achievements, game_history.
npm run db:generate # Generate migration files
npm run db:migrate # Apply migrations to database
npm run db:studio # Visual database browserNote
Guest mode is fully preserved — API calls silently return null when not logged in.
| Method | Path | Auth | Description |
|---|---|---|---|
GET |
/api/health |
No | Health check |
ALL |
/api/auth/* |
No | Better Auth (sign-up, sign-in, sign-out) |
GET |
/api/leaderboard |
No | Public leaderboard (filterable by difficulty) |
GET |
/api/leaderboard/me |
Yes | My rank and nearby entries |
POST |
/api/leaderboard |
Yes | Submit score (anti-cheat validated) |
GET |
/api/saves |
Yes | Get all 3 save slots |
PUT |
/api/saves/:slot |
Yes | Save to slot 0-2 |
DELETE |
/api/saves/:slot |
Yes | Delete save slot |
GET |
/api/progression |
Yes | Get progression data |
PUT |
/api/progression |
Yes | Save progression |
POST |
/api/progression/sync |
Yes | Merge local + server data |
POST |
/api/stats/game |
Yes | Record completed game |
GET |
/api/stats/me |
Yes | My stats and recent games |
POST |
/api/stats/achievements |
Yes | Unlock achievement |
GET |
/api/stats/achievements |
Yes | My achievements |
GET |
/api/stats/achievements/global |
No | Global achievement percentages |
POST |
/api/challenges |
Yes | Submit daily challenge score |
Contributions are welcome! Here's how you can help:
1. Fork & Clone:
git clone https://github.com/ChanMeng666/css-tower-defense.git
cd css-tower-defense2. Create Branch:
git checkout -b feature/your-feature-name3. Make Changes and Submit PR:
- Follow the existing IIFE module pattern for JavaScript
- Use LESS variables and mixins from
vars.lessfor styling - Test in Chrome with hardware acceleration enabled
- Provide clear PR description
Ways to Contribute:
- Report bugs via GitHub Issues
- Suggest new tower types, enemies, or game mechanics
- Improve CSS 3D models and visual effects
- Help with accessibility and browser compatibility
- Submit pull requests
This project is licensed under the MIT License — feel free to use it for learning and experimentation.
- Commercial use allowed
- Modification allowed
- Distribution allowed
- Private use allowed
Chan Meng Creator & Lead Developer |
Stargazers
Forkers