Tower Defense — Design & Contribution Guide

This document describes the current Tower Defense implementation (see levels/towerDefense/towerDefense.js), how the core Game class works, and how to add towers, enemies, and features.

For this project, keep gameplay code in the same file for now. When adding new behavior, add new classes in towerDefense.js rather than creating new folders.

Overview

The Game class manages board state (grid, path), rendering, and input. The board is a grid of boardHeight × boardWidth cells. The path for enemies is generated by drawEnemyPath() and stored in this.path as an array of [row, col] coordinates. Towers and enemies are plain objects stored in this.towers and this.enemies.

Key responsibilities in Game:

Coordinate system

Rendering notes

Data shapes (conventions)

Tower (example shape)

{
	id: 'basic-1',        // unique id
	row: 4,               // integer board row
	col: 2,               // integer board col
	range: 2.5,           // in cells (floating OK)
	fireRate: 1.0,        // shots per second
	damage: 1,            // damage per shot
	update: function(game, dt) { ... } // optional per-tower update method
}

Enemy (example shape)

{
	id: 'goblin-1',       // unique id
	hp: 3,                // hit points
	speed: 1.0,           // cells per second (recommended)
	pathIndex: 0,         // index into game.path (which cell the enemy is moving toward)
	progress: 0.0,        // 0..1 progress between path[pathIndex] and path[pathIndex+1]
	update: function(game, dt) { ... } // advance along path, handle death
}

How enemies should work (recommended)

How towers should work (recommended)

Where to implement behaviors

Best practices and conventions

Planned features and notes (ideas to implement next)

Testing locally

Contact & ownership


If you’d like, I can also: