Build a Tower Defense Game using C++, Raylib & A* Pathfinding

Lesson 8 of 8

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

  1. 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.
  2. 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.
  3. When a tower placement succeeds, recompute waypoints from the new path and reset every current enemy's currentWaypoint to 0, so they visibly reroute around the new tower instead of walking through it.
  4. 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.
  5. Show a clear game-over state once lives reaches 0, 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 DrawCircleLines outline 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 findPath call (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! 🚀

This lesson ends in a project. Build it on your own machine, there's nowhere to submit it here, but the brief above is everything you need.