Merge branch 'develop' of github.com:thecodingmachine/workadventure into develop
This commit is contained in:
commit
4e6a622546
@ -126,19 +126,7 @@ export class GameMap {
|
|||||||
for (let y = 0; y < this.map.height; y += 1) {
|
for (let y = 0; y < this.map.height; y += 1) {
|
||||||
const row: number[] = [];
|
const row: number[] = [];
|
||||||
for (let x = 0; x < this.map.width; x += 1) {
|
for (let x = 0; x < this.map.width; x += 1) {
|
||||||
row.push(this.isCollidingAt(x, y) ? 1 : 0);
|
row.push(this.isCollidingAt(x, y) ? 1 : this.isExitTile(x, y) ? 2 : 0);
|
||||||
}
|
|
||||||
grid.push(row);
|
|
||||||
}
|
|
||||||
return grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getWalkingCostGrid(): number[][] {
|
|
||||||
const grid: number[][] = [];
|
|
||||||
for (let y = 0; y < this.map.height; y += 1) {
|
|
||||||
const row: number[] = [];
|
|
||||||
for (let x = 0; x < this.map.width; x += 1) {
|
|
||||||
row.push(this.getWalkingCostAt(x, y));
|
|
||||||
}
|
}
|
||||||
grid.push(row);
|
grid.push(row);
|
||||||
}
|
}
|
||||||
@ -368,8 +356,7 @@ export class GameMap {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getWalkingCostAt(x: number, y: number): number {
|
private isExitTile(x: number, y: number): boolean {
|
||||||
const bigCost = 100;
|
|
||||||
for (const layer of this.phaserLayers) {
|
for (const layer of this.phaserLayers) {
|
||||||
if (!layer.visible) {
|
if (!layer.visible) {
|
||||||
continue;
|
continue;
|
||||||
@ -382,16 +369,16 @@ export class GameMap {
|
|||||||
tile &&
|
tile &&
|
||||||
(tile.properties[GameMapProperties.EXIT_URL] || tile.properties[GameMapProperties.EXIT_SCENE_URL])
|
(tile.properties[GameMapProperties.EXIT_URL] || tile.properties[GameMapProperties.EXIT_SCENE_URL])
|
||||||
) {
|
) {
|
||||||
return bigCost;
|
return true;
|
||||||
}
|
}
|
||||||
for (const property of layer.layer.properties) {
|
for (const property of layer.layer.properties) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
if (property.name && property.name === "exitUrl") {
|
if (property.name && property.name === "exitUrl") {
|
||||||
return bigCost;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private triggerAllProperties(): void {
|
private triggerAllProperties(): void {
|
||||||
|
@ -589,7 +589,6 @@ export class GameScene extends DirtyScene {
|
|||||||
this.pathfindingManager = new PathfindingManager(
|
this.pathfindingManager = new PathfindingManager(
|
||||||
this,
|
this,
|
||||||
this.gameMap.getCollisionGrid(),
|
this.gameMap.getCollisionGrid(),
|
||||||
this.gameMap.getWalkingCostGrid(),
|
|
||||||
this.gameMap.getTileDimensions()
|
this.gameMap.getTileDimensions()
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1487,7 +1486,7 @@ export class GameScene extends DirtyScene {
|
|||||||
phaserLayers[i].setCollisionByProperty({ collides: true }, visible);
|
phaserLayers[i].setCollisionByProperty({ collides: true }, visible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.pathfindingManager.setCollisionGrid(this.gameMap.getCollisionGrid(), this.gameMap.getWalkingCostGrid());
|
this.pathfindingManager.setCollisionGrid(this.gameMap.getCollisionGrid());
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,27 +8,21 @@ export class PathfindingManager {
|
|||||||
private grid: number[][];
|
private grid: number[][];
|
||||||
private tileDimensions: { width: number; height: number };
|
private tileDimensions: { width: number; height: number };
|
||||||
|
|
||||||
constructor(
|
constructor(scene: Phaser.Scene, collisionsGrid: number[][], tileDimensions: { width: number; height: number }) {
|
||||||
scene: Phaser.Scene,
|
|
||||||
collisionsGrid: number[][],
|
|
||||||
walkingCostGrid: number[][],
|
|
||||||
tileDimensions: { width: number; height: number }
|
|
||||||
) {
|
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
|
|
||||||
this.easyStar = new EasyStar.js();
|
this.easyStar = new EasyStar.js();
|
||||||
this.easyStar.enableDiagonals();
|
this.easyStar.enableDiagonals();
|
||||||
this.easyStar.disableCornerCutting();
|
this.easyStar.disableCornerCutting();
|
||||||
|
this.easyStar.setTileCost(2, 100);
|
||||||
|
|
||||||
this.grid = collisionsGrid;
|
this.grid = collisionsGrid;
|
||||||
this.tileDimensions = tileDimensions;
|
this.tileDimensions = tileDimensions;
|
||||||
this.setEasyStarGrid(collisionsGrid);
|
this.setEasyStarGrid(collisionsGrid);
|
||||||
this.setWalkingCostGrid(walkingCostGrid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setCollisionGrid(collisionGrid: number[][], walkingCostGrid: number[][]): void {
|
public setCollisionGrid(collisionGrid: number[][]): void {
|
||||||
this.setEasyStarGrid(collisionGrid);
|
this.setEasyStarGrid(collisionGrid);
|
||||||
this.setWalkingCostGrid(walkingCostGrid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async findPath(
|
public async findPath(
|
||||||
@ -120,15 +114,7 @@ export class PathfindingManager {
|
|||||||
|
|
||||||
private setEasyStarGrid(grid: number[][]): void {
|
private setEasyStarGrid(grid: number[][]): void {
|
||||||
this.easyStar.setGrid(grid);
|
this.easyStar.setGrid(grid);
|
||||||
this.easyStar.setAcceptableTiles([0]); // zeroes are walkable
|
this.easyStar.setAcceptableTiles([0, 2]); // zeroes are walkable, 2 are exits, also walkable
|
||||||
}
|
|
||||||
|
|
||||||
private setWalkingCostGrid(grid: number[][]): void {
|
|
||||||
for (let y = 0; y < grid.length; y += 1) {
|
|
||||||
for (let x = 0; x < grid[y].length; x += 1) {
|
|
||||||
this.easyStar.setAdditionalPointCost(x, y, grid[y][x]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private logGridToTheConsole(grid: number[][]): void {
|
private logGridToTheConsole(grid: number[][]): void {
|
||||||
|
@ -104,7 +104,7 @@
|
|||||||
"x":0,
|
"x":0,
|
||||||
"y":0
|
"y":0
|
||||||
}],
|
}],
|
||||||
"nextlayerid":9,
|
"nextlayerid":11,
|
||||||
"nextobjectid":13,
|
"nextobjectid":13,
|
||||||
"orientation":"orthogonal",
|
"orientation":"orthogonal",
|
||||||
"properties":[
|
"properties":[
|
||||||
|
Loading…
Reference in New Issue
Block a user