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:
- grid_size
Grid size
- bottom
Bottom of playing field
- top
Top of playing field
- left
Left border of playing field
- right
Right border of playing field
- moving_sprite
Sprite that will be moving
- blocking_sprites
Sprites that can block movement
- barrier_list
SpriteList of barriers to use in _AStarSearch,
None
if not recalculated
- arcade.astar_calculate_path(start_point: tuple[float | int, float | int] | Vec2, end_point: tuple[float | int, float | int] | Vec2, astar_barrier_list: AStarBarrierList, diagonal_movement: bool = True) list[tuple[float | int, float | int] | Vec2] | 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 boundaries 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] | Vec2, target: tuple[float | int, float | int] | Vec2, walls: SpriteList, max_distance: float = inf, check_resolution: int = 2) bool [source]
Determine if we have line of sight between two points.
Warning
Try to make sure spatial hashing is enabled on
walls
!If spatial hashing is not enabled, this function may run very slowly!
- 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.
- Returns:
Whether or not observer to target is blocked by any wall in walls