Coding Flash Tower Defence Games - Pathfinding or Waypoints?
When it comes to programming a tower defence game, you have a choice to make (Well, you have loads of choices, but this is a pretty big one) - Should I use a pathfinding algorithm to give the enemies their sense of direction, or pre-program in a set of Waypoints? Let’s see what the good and bad points of each method are…
Pathfinding
Pathfinding algorithms will mean that the enemy can dynamically change its path depending on the level layout - for example, if you build a wall then it will go around it, meaning some more interesting tactical gameplay can be created! Take Xeno Tactic for an example - this game involves making mazes of towers to maximise damage done to enemies, something that would only be possible with a pathfinding algorithm!
However, it’s not all peaches and cream. The pathfinding algorithm is costly processor-wise. Running the algorithm each time the map is updated on every enemy on screen can cause a LOT of slowdown. And with a game genre such as tower defence, it can get busy on screen!
Waypoints
Waypoints mean pre-defining where the enemies will go - following a set path from the start to the finish. Games such as Flash Element td and Protector use this method, and it allows you to do things like make the enemies go in circles around an area more than once instead of straight to the exit. It is also a lot less processing - the enemies have a set path and do not veer off it. Sorted. More processing time for some pretty particle graphics =D
…But means that nothing can be placed in their way, else they’re just going to walk into it and the game would be a little bit easier than intended! The gameplay will undoubtedly be simpler than if you can alter the path the enemies go.
Overall
It comes down to what you want. If you want a strategic game with tactical choices and dynamic, intelligent senemies then pathfinding is the way to go. If you want a simple start-to-finish Tower Defense game that runs fast, then waypoints are the future for you. Maybe a combination of both is possible in larger levels, where the enemy finds the path between certain waypoints only, meaning less processing and more tactical choice (and more coding for you, you lucky ducky!)
Any other advice when it comes to coding tower defence games? Share it with us in a comment below!
Posted
on
Thursday, October 30th, 2008 at 6:27 pm under

