Class PathFinder
java.lang.Object
de.gurkenlabs.litiengine.entities.behavior.PathFinder
- Direct Known Subclasses:
AStarPathFinder
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Rectangle2D
applyPathMargin
(ICollisionEntity entity, Rectangle2D rectangle) Applies a margin to a collision entity's bounding box.protected Path
findDirectPath
(Point2D start, Point2D target) Finds a direct path from the starting point to the target point.abstract Path
findPath
(IMobileEntity start, Point2D target) Gets the path for a mobile entity from the start to the target.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.
-
Constructor Details
-
PathFinder
public PathFinder()
-
-
Method Details
-
findPath
Gets the path for a mobile entity from the start to the target.- Parameters:
start
- the mobile entity from which the pathfinding originatestarget
- the target point to which the entity should move- Returns:
- the path to the target
-
findDirectPath
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 pathtarget
- the target point of the path- Returns:
- a direct path from the start to the target, represented as a
Path
-
applyPathMargin
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 appliedrectangle
- 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 calculatedstart
- the starting point of the pathtarget
- the target point of the path- Returns:
- true if the path intersects with any collision box, false otherwise
-