Projects Documents ClassMaker Animation Links & tools Home

PathFinder

This class is used for pathfinding in games

The constructor accepts a map of int values, (a double array) that represents the movementcosts for the squares. The created instance of PathFinder stores this map so you can call findPath() repeatedly, to find the cheapest path. You only need to provide findPath() with start and finish points, and the Vector where you want the right path stored.
findPath() runs in a Thread, so you only have to check for when your Vector stops having zero elements, and suddenly contains the path.

Click the applet to make sure it has keyboard focus
Then draw some obstacles for the PathFinder to find its way through.

black squares ("X") have a movecost of 100,000
This means that the applet will move through these if there are no alternatives.

SHIFT - to show path
LEFTCLICK to draw 100.000 point squares
RIGHTCLICK to erase obstacles
CTRL + LEFTCLICK to draw 5 point squares
ALT + LEFTCLICK to increase movecost of square by 5 points
C to Clear the map
R to fill map with Random values

Download complete


Projects Documents ClassMaker Animation Links & tools Home