Class AStarPathFinder

java.lang.Object
de.gurkenlabs.litiengine.entities.behavior.PathFinder
de.gurkenlabs.litiengine.entities.behavior.AStarPathFinder

public class AStarPathFinder extends PathFinder
A pathfinder implementation based on the A* algorithm. The A* algorithm is used to find the shortest path between two points on a grid, taking into account obstacles and walkable areas.
  • Constructor Details

    • AStarPathFinder

      public AStarPathFinder(AStarGrid grid)
      Instantiates a new A* pathfinder with a predefined grid.
      Parameters:
      grid - the grid used for pathfinding
    • AStarPathFinder

      public AStarPathFinder(Dimension size, int gridNodeSize)
      Instantiates a new A* pathfinder with a grid of the specified size and node size.
      Parameters:
      size - the dimensions of the grid
      gridNodeSize - the size of each grid node
    • AStarPathFinder

      public AStarPathFinder(IMap map, int gridNodeSize)
      Instantiates a new A* pathfinder using the map's size and a specified grid node size.
      Parameters:
      map - the map used for pathfinding
      gridNodeSize - the size of each grid node
    • AStarPathFinder

      public AStarPathFinder(IMap map)
      Instantiates a new A* pathfinder using the map's size and the map's tile size as the grid node size.
      Parameters:
      map - the map used for pathfinding
  • Method Details

    • findPath

      public Path findPath(IMobileEntity entity, Point2D target)
      Finds a path from the entity's current position to the target using the A* algorithm. If no obstacles are present between the start and the target, a direct path is used.
      Specified by:
      findPath in class PathFinder
      Parameters:
      entity - the mobile entity for which the path is calculated
      target - the target point of the path
      Returns:
      the calculated path, or null if no path can be found
    • getGrid

      public AStarGrid getGrid()
      Gets the grid used by this A* pathfinder.
      Returns:
      the grid used for pathfinding