Class PathFinder

java.lang.Object
de.gurkenlabs.litiengine.entities.behavior.PathFinder
Direct Known Subclasses:
AStarPathFinder

public abstract class PathFinder extends Object
Abstract class representing a path finder. This class provides the basic structure for implementing pathfinding algorithms for mobile entities. Subclasses are expected to implement the findPath(IMobileEntity, Point2D) method.
  • Constructor Details

    • PathFinder

      public PathFinder()
  • Method Details

    • findPath

      public abstract Path findPath(IMobileEntity start, Point2D target)
      Gets the path for a mobile entity from the start to the target.
      Parameters:
      start - the mobile entity from which the pathfinding originates
      target - the target point to which the entity should move
      Returns:
      the path to the target
    • findDirectPath

      protected Path findDirectPath(Point2D start, Point2D target)
      Finds a direct path from the starting point to the target point. This path is simply a straight line between the two points.
      Parameters:
      start - the starting point of the path
      target - the target point of the path
      Returns:
      a direct path from the start to the target, represented as a Path
    • applyPathMargin

      protected Rectangle2D applyPathMargin(ICollisionEntity entity, Rectangle2D rectangle)
      Applies a margin to a collision entity's bounding box. This margin is used to prevent collisions when calculating paths, ensuring that entities have enough space to move around obstacles.
      Parameters:
      entity - the entity whose path margin should be applied
      rectangle - the bounding box of the entity
      Returns:
      a new Rectangle2D with a margin applied around the original bounding box
    • intersectsWithAnyCollisionBox

      protected boolean intersectsWithAnyCollisionBox(ICollisionEntity entity, Point2D start, Point2D target)
      Checks whether the direct path between two points intersects with any collision boxes in the game world. This method is used to ensure that entities do not pass through obstacles.
      Parameters:
      entity - the entity for which the path is being calculated
      start - the starting point of the path
      target - the target point of the path
      Returns:
      true if the path intersects with any collision box, false otherwise