Monday, March 31, 2008

A* Pathfinding

In the process of making a Silverlight Tower Defense app a while back I made a simple sample application of the A* pathfinding algorithm that could be useful for anyone else  working on Silverlight games (or games in general I suppose).

image

I won't do an entire explanation of the A* algorithm, there are tons of great resources out there already (http://www.google.com/search?q=A*+path+finding). The one I referenced most was probably http://www.policyalmanac.org/games/aStarTutorial.htm. This sample contains a bunch of debugging info along the lines of what you'll see at the policyalmanac site, just to make it a bit easier to customize.

The app contains the logic for a couple of different pathfinding routines, notably:

  • Standard: run-of-the-mill pathfinding
  • Drunken: I found that my tower defense critters were too predictable, so I added a bit of randomness in to the standard pathfinding
  • Roundabout: just having fun, critter takes a very long route. Not really useful
  • Worst: critter tries to find the absolute longest path available without going over the same tile twice.
  • Speed Bump: critter tries to avoid certain tiles (can weigh the expense of going through a tile). I used this for little bomber-men in my tower defense game- they try to just go through the map but if there's a good shortcut by going through some towers then they'll try to blast a hole and go through :)
  • Escape: inspired by Chat Noir (a great game on it's own), it's actually Dijkstra's algorithm where the critter just tries to get to the edge.

 

In case you're wondering, the tower defense app is working, but it's no fun to play at all. Balancing the game turns out to be much more difficult than I expected and everytime I sit down to make some progress I just end up creating new weapons like flamethrowers and nukes or Raiden-style plasma beams.

The sample can be run here.

The source is here.

3 Comments:

Anonymous Ralph Trickey said...

When you get a chance, can you update to Beta 2 (Or the release version once it's out?)

Also, is your source under some type of copyright? I'm looking at whether WPF is a viable otpion, and what it would take to convert.

Thanks,
RalphTrickey@operationalWarfare.com

4:59 PM  
Anonymous Anonymous said...

Unbelievable! It's just what I've been looking for!!! Thank you so much!!!

6:43 AM  
Anonymous Anonymous said...

Great! Please, post more on creating various weapons and game effects, like explosions and all!

6:51 AM  

Post a Comment

<< Home