A* Pathfinding in an isometric world with Flex

I’m having way too much fun with Flex.. It didn’t take me more than a few nights to put together a small test of an isometric world and implement an A* algorithm for pathfinding. It’s not nearly done yet, particularly the motion is bad, but you can check it out here:

isopathfinder11.png

http://www.topholt.com/Flex/bin-release/IsoPathfinder.html

Perhaps I could spend some time this holiday season making it into a small game or something. Who knows.

If anyone are interested in the implementation details, let me know. The screen-to-tile-space conversion took me a while to figure out, and A* can be tricky as well.

Edit: I’ve added the ability to fire small pieces of cheese at the cursor, to test collision with walls. Just press ‘A’ and you’ll see it in action!

Edit: View Source is now available.

23 Responses to “A* Pathfinding in an isometric world with Flex”

  1. Samuel R Says:

    Is it possible to view the source? I struggle with picking diamond-shapes using mouse coordinates.

  2. claustopholt Says:

    Sure thing - I just need to clean it up a bit :) I’ll post an updated version of the isometric pathfinder demo in a few days with View Source enabled!

  3. Bat Says:

    Hey ! I’m also interested in the source code. Nice work anyway !
    You will see parts of your algorithm in my next game for sure !

  4. Bat Says:

    Did you have the time to clean your source code ?
    :-)

  5. claustopholt Says:

    Yup, finally did - at least some of it. More refactoring to do, but this should give you guys a fair chance of copy&pasting for your own projects. Let me know if anything is unclear :)

  6. claustopholt Says:

    Dang! I just noticed that View Source craps up the ‘ characters all over the place - probably a beta 2 bug. At the bottom left of the View Source window you can download the source as a zip file. Do that instead, the chars are fine there.

  7. Game AI Roundup Week #50 2007: 1 Demo, 1 Video, 9 Stories, 1 Job — AiGameDev.com Says:

    [...] A* Pathfinding in an Isometric World with Flex [...]

  8. aron sogor Says:

    This is is pretty cool!!!

    I used the source and reworked it into a maven2 build if you wish to see, I can give it to you in any form.

    I only had problem with the KeyCodec (Flex2 could not find the import) to capture the key ‘A’ but I just replaced the line with
    // Fire cheese when the user presses ‘A’.
    if (event.keyCode == 65)
    {

    Are you planing to tweak this more?
    I would be open to contribute my changes…

  9. Claus Topholt Says:

    Aron, thanks for the comment! I’d sure like to see your build, although I have no experience with Maven. But then again, this would be a great time to learn :)

    I’m not currently continuing development on the pathfinding, but may do so at a later time for a game I’m considering doing. If/when I do that, I’ll post the code.

    One thing that you should be sure to try out is giving certain areas/tiles higher or lower movement costs; For instance, walking through tall grass is slower than walking on a road, but not impossible! This is extremely easy to implement with A* (just change movement costs), and the result looks and feels quite impressive!

  10. Danger Says:

    Hi,

    My prblem is:
    ///—

    1 error found
    F:\Pathfiles\IsoPathfinder.as:206
    ERROR : Llamada a un método stop posiblemente no definido mediante una referencia con tipo estático mx.effects:Move.

    205 // Stop the effect.
    206 Move(event.target).stop();
    207 }

    ///—

    help plis, thanks for answers!

  11. Claus Topholt Says:

    Hi Danger,

    My Spanish is … well, non-existant, but I think it may have to do with the version of Flex you are using. I built this using Flex 3 beta 3. Did you do that as well?

  12. Danger Says:

    Hi Claus…

    thanks for you answer…

    My English is poor… jejeje, Im use flex builder 2… Be with flex 3?

    pd: I found an excellent example in flex…

  13. Danger Says:

    Hi Claus,

    Unistall flex builder 2, and install FB 3 beta 3… nice! thanks…

  14. PeteHH Says:

    Hi Claus,
    where can I view or download the source code?
    Maybe I am getting old, but I didn’t find the link ;)

  15. PeteHH Says:

    I started to create a simcity like game in Flash but having difficulties to convert it into Flex.
    I hope that your example helps me to do that.

  16. PeteHH Says:

    SORRY I found it! :P

  17. Mielno Says:

    Hmm - I think about it and write something more later - Hi…

  18. Claus Topholt Says:

    Pete, if you need the source code, right-click and “View Source” (you already figured this out) - and THEN click on “Download Source ZIP” in the lower left corner, which gives you the entire source correctly. Flex 3 beta 3 still has issues with View Source and the ‘ character.

    Mielno, looking forward to any comments :)

  19. ArneO Says:

    The Resources are missing. It doesn´t matter for the images, but the xml was nice to have …

  20. Zack Says:

    Hey Claus,
    Very nice work indeed - the code will assist me well in the iso- tile based game im building….
    Can you by any chance add the resources \ xml file , or explain how to implement it?

    Thanks!

    Zacks

  21. Claus Topholt Says:

    It took me a little while to dig out the old source code and remove unnecessary parts (such as the xml files in Resources, which was a work-in-progress). But now it’s done, so go ahead and grab the source!

  22. Zack Says:

    Hey Claus,
    Awesome job!
    Thanks for the well working demo , it will help me alot , im sure :)

    Zack

  23. SOG knives Says:

    SOG knives…

    Interesting ideas… I wonder how the Hollywood media would portray this?…

Leave a Reply