Final Project: Finish Your Tower Defense Game
Every system is built: a grid-based map, A* pathfinding with path reconstruction, enemies that follow waypoints, towers that shoot and legally block the path, waves, gold, and lives. Combine them into one complete, playable tower defense game.
Requirements
- Build a grid with a fixed start and goal, and at least a few permanent wall cells laid out to force an interesting initial path.
- Let the player click an empty cell to place a tower, using
tryPlaceTower's block-then-findPath-then-maybe-undo check, invalid placements (no gold, or would fully seal the path) must be rejected. - When a tower placement succeeds, recompute waypoints from the new path and reset every current enemy's
currentWaypointto0, so they visibly reroute around the new tower instead of walking through it. - Spawn enemies in a timed wave, deal damage from towers in range, remove dead or goal-reached enemies with the erase-remove idiom, and track gold and lives correctly.
- Show a clear game-over state once
livesreaches0, and a clear "wave cleared" state once a wave is fully spawned and empty.
Stretch goals
- Support multiple waves, with enemies that get tougher (more health, more speed) each round, and a short pause between waves for the player to place more towers.
- Add a second tower type with a different range/damage/fireRate tradeoff, and let the player choose which to place.
- Draw each tower's range as a
DrawCircleLinesoutline while the player is choosing where to place it, so the tradeoff is visible before committing gold to it. - Visualize the A* open and closed sets briefly after each
findPathcall (a faint overlay color per explored cell), so you can see the search reaching outward, exactly like the diagram from the "Why A*?" lesson.
Submit a link to your finished project (a repo or gist) below, an instructor will review it before you can mark this lesson complete. Good luck! 🚀