walk on dbl click

This commit is contained in:
_Bastler 2022-01-27 14:57:46 +01:00
parent 6c094b714b
commit 08816ae80f

View File

@ -4,6 +4,10 @@ import type { GameScene } from "../Game/GameScene";
export class GameSceneUserInputHandler implements UserInputHandlerInterface { export class GameSceneUserInputHandler implements UserInputHandlerInterface {
private gameScene: GameScene; private gameScene: GameScene;
private lastTime: number = 0;
private lastX: number = 0;
private lastY: number = 0;
constructor(gameScene: GameScene) { constructor(gameScene: GameScene) {
this.gameScene = gameScene; this.gameScene = gameScene;
} }
@ -22,27 +26,34 @@ export class GameSceneUserInputHandler implements UserInputHandlerInterface {
if (pointer.rightButtonReleased() || pointer.getDuration() > 250) { if (pointer.rightButtonReleased() || pointer.getDuration() > 250) {
return; return;
} }
const camera = this.gameScene.getCameraManager().getCamera();
const index = this.gameScene if (this.lastTime > 0 && pointer.time - this.lastTime < 500 && this.lastX == pointer.x && this.lastY == pointer.y) {
.getGameMap() const camera = this.gameScene.getCameraManager().getCamera();
.getTileIndexAt(pointer.x + camera.scrollX, pointer.y + camera.scrollY); const index = this.gameScene
const startTile = this.gameScene .getGameMap()
.getGameMap() .getTileIndexAt(pointer.x + camera.scrollX, pointer.y + camera.scrollY);
.getTileIndexAt(this.gameScene.CurrentPlayer.x, this.gameScene.CurrentPlayer.y); const startTile = this.gameScene
this.gameScene .getGameMap()
.getPathfindingManager() .getTileIndexAt(this.gameScene.CurrentPlayer.x, this.gameScene.CurrentPlayer.y);
.findPath(startTile, index, true, true) this.gameScene
.then((path) => { .getPathfindingManager()
// Remove first step as it is for the tile we are currently standing on .findPath(startTile, index, true, true)
path.shift(); .then((path) => {
this.gameScene.CurrentPlayer.setPathToFollow(path).catch((reason) => {}); // Remove first step as it is for the tile we are currently standing on
}) path.shift();
.catch((reason) => { this.gameScene.CurrentPlayer.setPathToFollow(path).catch((reason) => { });
console.warn(reason); })
}); .catch((reason) => {
console.warn(reason);
});
}
this.lastTime = pointer.time;
this.lastX = pointer.x;
this.lastY = pointer.y;
} }
public handlePointerDownEvent(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]): void {} public handlePointerDownEvent(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]): void { }
public handleSpaceKeyUpEvent(event: Event): Event { public handleSpaceKeyUpEvent(event: Event): Event {
this.gameScene.activateOutlinedItem(); this.gameScene.activateOutlinedItem();