Monday, March 31, 2008

Fun

That last post was a bit too developer centric, time to balance it out with something more fun. I recycled an old WPF project and converted it over to Silverlight. Lots of fun to play with though it doesn't appear to run all that well on Firefox or Safari (if your browser appears to hang just wait a few seconds).

image

The source can be found here.

The app can be run here.

Enjoy!

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.

Quick tip-
The background color of the default Silverlight preloader can be changed by changing the 'background' parameter in the object tag in HTML. Making the preloader and HTML backgrounds match your Silverlight app's background is an easy way to make the loading sequence just that much nicer.
html, body {
height: 100%;
overflow: auto;
background: #4F818A;
}

<object ... >
<param name="background" value="#7F2727" />
</
object>