the-world-engine
Version:
three.js based, unity like game engine for browser
53 lines (52 loc) • 2.28 kB
TypeScript
import { Vector2 } from "three/src/Three";
import type { ReadonlyVector2 } from "../../../math/ReadonlyVector2";
import type { IGridCollidable } from "../../grid_physics2d/IGridCollidable";
/**
* Pathfinder that uses the A* algorithm to find the shortest path between two points.
* it works in grid coordinates.
* it has iteration limits to prevent infinite loops.
*/
export declare class Pathfinder {
private readonly _checkCollisionWidth;
private readonly _checkCollisionHeight;
private readonly _iterationLimit;
private readonly _collideMaps;
/**
*
* @param collideMaps collide maps to use for collision detection
* @param checkCollisioWidth width of the collision check,
* this value should be set to "gridCellWidth / 2",
* if character is bigger than one grid cell you can increase the value accordingly.
* @param checkCollisionHeight height of the collision check,
* this value should be set to "gridCellHeight / 2",
* if character is bigger than one grid cell you can increase the value accordingly.
* @param iterationLimit maximum number of pathfinding iterations, If you want to passfind further, you need to increase the value
*/
constructor(collideMaps?: IGridCollidable[], checkCollisionWidth?: number, checkCollisionHeight?: number, iterationLimit?: number);
/**
* adds a new collide map to the list of collide maps
* @param collideMap
*/
addCollideMap(collideMap: IGridCollidable): void;
/**
* removes a collide map from the list of collide maps
* @param collideMap
*/
removeCollideMap(collideMap: IGridCollidable): void;
/**
* removes all collide maps
*/
removeAllCollideMaps(): void;
/**
* finds the shortest path between two points
* @param startGridPosition start position in grid coordinates (integers value)
* @param endGridPosition end position in grid coordinates (integers value)
* @returns the shortest path between the two points
*/
findPath(startGridPosition: ReadonlyVector2, endGridPosition: ReadonlyVector2): Vector2[] | null;
private getNeighbors;
private calculatePath;
private calculateDistanceCost;
private getLowestFcostNode;
private checkCollision;
}