A* Pathfinding guidance please =)

Firstly, hi everyone! This is my first post =D

Right. I’m writing a 3D Tower Defense game at the minute using Java and LWJGL/Slick, everything’s working well so far; I’ve got the map displaying, the tower placement sorted etc. but I’m now beginning to consider putting in some bad guys.

(project current state: http://img857.imageshack.us/img857/1959/loldefv10.png probably my biggest accomplishment with OpenGL to date, so be nice please ^^)

My map’s drawn using a 2D array of shorts (0 for gravel, 1 for grass etc.) but I have no idea how to implement A* Pathfinding using just this array.

Any help at all would be much appreciated!

Regards,

Ollie.

have a read of this article. It’ll run you through the main pathfinding techniques and how to implement them in java.

Wow, quick reply!

Cheers man, I’ll have a read.

Hi Kappa.

Thanks for the link, that definitely clarified some things.

I’ve read through that tutorial and I (by hand) wrote down the source code from page 3 (the AStarNode and AStarSearch classes), and I understand the theory behind A* now. However I still have no clue how to convert my 2D array into connected nodes, or even how to implement the abstract methods defined in AStarNode.

I’m sorry if this is a trivial problem but I’m genuinely stuck on how to convert my array to nodes (with neighbours ???)

Regards,

Ollie.

^ I have same question too >:D

You need to rethink the structure of your game and whether an array of short will work in this case (unlikely :)). There is no fixed way on how you should structure a game and it varies widely from genre.

Just of the top of my head, I say you could use a 2d array of custom objects to represent the map. So create your own object for example called MapTile. Each MapTile object will contain information on what type of tile it is and what Node it represents.

e.g.


class MapTile {
    int type;
    Node node;
}

MapTile[] map = new MapTile[10];

That’s a good idea, thank you! I’ll have a crack at it and get back to you.

Cheers for the assistance so far, you’re a gentleman and a scholar. =)

Ollie.

Heyy, I guess I can mark this thread as “solved” now!

The finished product (for now!) is here: http://www.youtube.com/watch?v=3q999sUC60o

Cheers for the help guys!