EDIT: see StraightEdge project at http://www.java-gaming.org/index.php/topic,23427.0.html
Hi,
I made some code which uses A* to find the quickest path through arbitrary 2D polygons. Here’s a little test program that you can try, just click/drag around the left and right mouse buttons:
http://keithphw.freehostia.com/PathFinder/AStarPathFinder.jnlp
source (note that clicking this link may not work, you may have to paste the link text into your browser window to actually download the zip file):
http://keithphw.freehostia.com/PathFinder/src.zip
dependency jar (Java Topology Suite):
http://keithphw.freehostia.com/PathFinder/jts-1.8.jar
There’s 2 things that the code does (or tries to :persecutioncomplex:):
- Links the corners of polygons together if they are straight-line reachable, to make a kind of mesh that the A* code can work on. This code is in NodeConnector .
- Does A* on the mesh, and tries to find the quickest path. This code is in PathFinder
You guys are the best source of info on this stuff that I have ever known, so if anyone’s got any tips for me on how to make it better, I’d really appreciate it. Also, if anyone would like to work on the code together to use in a 2d RPG style point-and-click game, let me know 8)
I suspect that my implementation of A* is very inefficient, so any help would be greatly appreciated - general tips, code, or even just saying hi! 8)
Thanks!
Keith
PS: Hmm, after profiling my code, it looks like I call ArrayList.contains too often…