player following the path wip

This commit is contained in:
Hanusiak Piotr 2022-01-17 14:36:00 +01:00
parent 77ee39110f
commit e557e8ea72
5 changed files with 108 additions and 41 deletions

View file

@ -9,28 +9,30 @@ export class PathfindingManager {
this.scene = scene;
this.easyStar = new EasyStar.js();
this.easyStar.disableDiagonals();
this.setGrid(collisionsGrid);
}
public findPath(start: { x: number; y: number }, end: { x: number; y: number }): void {
console.log("TRY TO FIND PATH");
this.easyStar.findPath(start.x, start.y, end.x, end.y, (path) => {
if (path === null) {
console.warn("Path was not found.");
} else {
console.log("path was found");
console.log(path);
}
public async findPath(
start: { x: number; y: number },
end: { x: number; y: number }
): Promise<{ x: number; y: number }[]> {
return new Promise((resolve, reject) => {
this.easyStar.findPath(start.x, start.y, end.x, end.y, (path) => {
if (path === null) {
reject("Path was not found");
} else {
resolve(path);
}
});
this.easyStar.calculate();
});
this.easyStar.calculate();
}
private setGrid(grid: number[][]): void {
console.log(grid);
this.easyStar.setGrid(grid);
this.easyStar.setAcceptableTiles([0]); // zeroes are walkable
this.logGridToTheConsole(grid);
}
private logGridToTheConsole(grid: number[][]): void {