created a class to centralize all user inputs catching and expose user events
This commit is contained in:
parent
6bec8b3703
commit
793e5318f7
3 changed files with 77 additions and 45 deletions
|
@ -2,35 +2,17 @@ import {CameraManager, CameraManagerInterface} from "./CameraManager";
|
|||
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
|
||||
import {Player} from "../Player/Player";
|
||||
import {GameScene, GameSceneInterface} from "./GameScene";
|
||||
import {UserInputManager} from "../UserInput/UserInputManager";
|
||||
|
||||
export interface MapManagerInterface {
|
||||
keyZ: Phaser.Input.Keyboard.Key;
|
||||
keyQ: Phaser.Input.Keyboard.Key;
|
||||
keyS: Phaser.Input.Keyboard.Key;
|
||||
keyD: Phaser.Input.Keyboard.Key;
|
||||
keyRight: Phaser.Input.Keyboard.Key;
|
||||
keyLeft: Phaser.Input.Keyboard.Key;
|
||||
keyUp: Phaser.Input.Keyboard.Key;
|
||||
keyDown: Phaser.Input.Keyboard.Key;
|
||||
keyShift: Phaser.Input.Keyboard.Key;
|
||||
|
||||
Map: Phaser.Tilemaps.Tilemap;
|
||||
Terrain: Phaser.Tilemaps.Tileset;
|
||||
Camera: CameraManagerInterface;
|
||||
Scene: GameSceneInterface;
|
||||
userInputManager: UserInputManager;
|
||||
update(): void;
|
||||
}
|
||||
export class MapManager implements MapManagerInterface{
|
||||
keyZ: Phaser.Input.Keyboard.Key;
|
||||
keyQ: Phaser.Input.Keyboard.Key;
|
||||
keyS: Phaser.Input.Keyboard.Key;
|
||||
keyD: Phaser.Input.Keyboard.Key;
|
||||
keyRight: Phaser.Input.Keyboard.Key;
|
||||
keyLeft: Phaser.Input.Keyboard.Key;
|
||||
keyUp: Phaser.Input.Keyboard.Key;
|
||||
keyDown: Phaser.Input.Keyboard.Key;
|
||||
keyShift: Phaser.Input.Keyboard.Key;
|
||||
|
||||
Terrain : Phaser.Tilemaps.Tileset;
|
||||
Camera: CameraManagerInterface;
|
||||
CurrentPlayer: Player;
|
||||
|
@ -38,6 +20,7 @@ export class MapManager implements MapManagerInterface{
|
|||
Map: Phaser.Tilemaps.Tilemap;
|
||||
startX = (window.innerWidth / 2) / RESOLUTION;
|
||||
startY = (window.innerHeight / 2) / RESOLUTION;
|
||||
userInputManager: UserInputManager;
|
||||
|
||||
constructor(scene: GameSceneInterface){
|
||||
this.Scene = scene;
|
||||
|
@ -49,11 +32,9 @@ export class MapManager implements MapManagerInterface{
|
|||
this.Map.createStaticLayer("Calque 1", [this.Terrain], 0, 0);
|
||||
this.Map.createStaticLayer("Calque 2", [this.Terrain], 0, 0);
|
||||
|
||||
//initialise keyboard
|
||||
this.initKeyBoard();
|
||||
|
||||
//initialise camera
|
||||
this.Camera = new CameraManager(this.Scene, this.Scene.cameras.main, this);
|
||||
this.userInputManager = new UserInputManager(this.Scene);
|
||||
//initialise player
|
||||
this.CurrentPlayer = new Player(
|
||||
this.Scene,
|
||||
|
@ -65,22 +46,9 @@ export class MapManager implements MapManagerInterface{
|
|||
this.CurrentPlayer.initAnimation();
|
||||
}
|
||||
|
||||
|
||||
initKeyBoard() {
|
||||
this.keyShift = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SHIFT);
|
||||
|
||||
this.keyZ = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z);
|
||||
this.keyQ = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q);
|
||||
this.keyS = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.S);
|
||||
this.keyD = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.D);
|
||||
|
||||
this.keyUp = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
|
||||
this.keyLeft = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
|
||||
this.keyDown = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN);
|
||||
this.keyRight = this.Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
|
||||
}
|
||||
|
||||
update() : void {
|
||||
this.CurrentPlayer.move();
|
||||
let activeEvents = this.userInputManager.getEventListForGameTick();
|
||||
|
||||
this.CurrentPlayer.move(activeEvents);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue