# AStar Pathfinding Class (Example)

**URL:** <https://forum.kirupa.com/t/astar-pathfinding-class-example/311457>\
**Category:** open source\
**Created:** [July 7, 2010, 3:16am UTC](https://forum.kirupa.com/t/astar-pathfinding-class-example/311457 "2010-07-07T03:16:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaToMaStEr](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@MaToMaStEr](https://forum.kirupa.com/u/MaToMaStEr)\
**Post date:** [July 7, 2010, 3:16am UTC](https://forum.kirupa.com/t/astar-pathfinding-class-example/311457/1 "2010-07-07T03:16:50Z")

</div>

Hi!

I started working on a Class (in AS2) which implements the AStar algorithm for pathfinding in tile-based games and stuff.  
It takes a map (2D Array) as an argument and then calling the function

```auto
findPath(p1:Point, p2:Point)

```

it returns an array holding in order the points to follow.

It supports Horizontal/Vertical movement and Diagonal (allowed by a Boolean variable). You can also set the index in the map array from which it is counted as a non-walkeable tile.

* * *

It is now an ITERATIVE algorithm, cause it was, in some cases, exceeding the maximum level of recursion allowed. Now it WILL work with problematic map configurations posted here…

* * *

It still needs some adjustements but you can check an example [HERE](http://megaswf.com/serve/22381/)

INSTRUCTIONS:

- Click a tile to change from walk to non-walkeable and viceversa.
- Press SPACE to switch allowDiagonal (true/false)

- It always check for the path between the top/left and bottom/right corners
- It starts now with a blank map so its easier to edit

Tell me what you think !!

* * *

PS: Heres the previous example in case you want to check it out, when it was Recursive: [HERE](http://www.swfcabin.com/open/1278470245)
