BrainBlitz.org

April 25, 2010

AS3 Pathfinding and Game Source

Filed under: Programming — Tags: , , , , — Anthony @ 9:11 am

Here is the somewhat-polished version of my pathfinding/game application, all heavily commented in tutorial format for your analyzing pleasure. New to the demo is graphics displaying the internal workings of the pathfinding and collision detection, less brain-dead AI and the ability to add stuff to the map. 

Here is the application: 
Create a few “guys,” click to select, click elsewhere to move. Or add a tower near the guys.
Ctrl+Click to add multiple units; Escape to cancel character selection or drop the current “tool.”
 

Here is the code. 

A few observations: 

  • I  have dubbed my primitive A* pathfinder “AStarOrthogonal” to make it clear: this pathfinder does not work diagonally.
  • I’m still working out some glitches in the “dynamic” collision handling (between mobile units, mainly on head-on collisions). Sometimes the movement isn’t quite right, and sometimes characters end up coinciding. This isn’t a problem with the pathfinder, it’s with the “game” code–specifically the Character “state machine.”
  • The first red cell leading character movement is the square currently tracked by the pathfinder. The leading-leading square is not used at the moment, but I’m experimenting with better collision avoidance by utilizing that future location.
  • If you’re going for something along the lines of the typical, ubiquitous “Tower Defense” game, I’ve already written half the code for you. : )

A couple of technical notes: 

  • This is a learning process for me; keep that in mind. I am but a lowly game programming “hobbyist.” So, if you’re learning from this, don’t assume that everything I’ve done was done the “best” way.
  • If you’re using Flash, CS4 is required by the POLYGONAL data structures library. If you don’t use another IDE (i.e. Flex) and you don’t have CS4, I have at this point only used Singly Linked Lists and Doubly Linked Lists from the library, so it should be easy to find another library that does the trick.

Resources: 

  • The code download includes the POLYGONAL data structure library from http://code.google.com/p/polygonal/wiki/DataStructures. I’ve included the library for convenience, but you might want to check the project home to be sure and have the latest version.
  • As in all my demos, the non-original graphics are from, or are derived from, the work of Azure Flame.
  • Print this article!
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Yahoo! Bookmarks

1 Comment »

  1. [...] that I’ve reached a bit of a milestone with the pathfinding stuff, I’m taking a break to play with some other items on my to-do list. One of those items is [...]

    Pingback by Getting started with FlashDevelop and haXe | BrainBlitz.org — April 26, 2010 @ 9:37 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Spam Protection by WP-SpamFree

Powered by WordPress