Pathfinding#
- class arcade.AStarBarrierList(moving_sprite: Sprite, blocking_sprites: SpriteList, grid_size: int, left: int, right: int, bottom: int, top: int)[source]#
Bases:
Class that manages a list of barriers that can be encountered during A* path finding.
- Parameters:
moving_sprite – Sprite that will be moving
blocking_sprites – Sprites that can block movement
grid_size – Size of the grid, in pixels
left – Left border of playing field
right – Right border of playing field
bottom – Bottom of playing field
top – Top of playing field
barrier_list – SpriteList of barriers to use in _AStarSearch, None if not recalculated
- arcade.astar_calculate_path(start_point: Tuple[float | int, float | int], end_point: Tuple[float | int, float | int], astar_barrier_list: AStarBarrierList, diagonal_movement: bool = True) List[Tuple[float | int, float | int]] | None [source]#
Calculates the path using AStarSearch Algorithm and returns the path
- Parameters:
start_point – Where it starts
end_point – Where it ends
astar_barrier_list – AStarBarrierList with the boundries to use in the AStarSearch Algorithm
diagonal_movement – Whether of not to use diagonals in the AStarSearch Algorithm
- Returns:
List of points(the path), or None if no path is found
- arcade.has_line_of_sight(observer: Tuple[float | int, float | int], target: Tuple[float | int, float | int], walls: SpriteList, max_distance: float = inf, check_resolution: int = 2) bool [source]#
Determine if we have line of sight between two points.
- Parameters:
observer – Start position
target – End position position
walls – List of all blocking sprites
max_distance – Max distance point 1 can see
check_resolution – Check every x pixels for a sprite. Trade-off between accuracy and speed.
Warning
Try to make sure spatial hashing is enabled on
walls
!If spatial hashing is not enabled, this function may run very slowly!
- Returns:
Whether or not oberver to target is blocked by any wall in walls