2020-04-07 19:23:21 +02:00
|
|
|
import {CameraManager, CameraManagerInterface} from "./CameraManager";
|
2020-04-07 20:41:35 +02:00
|
|
|
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
|
|
|
|
import {Player} from "../Player/Player";
|
|
|
|
import {GameScene, GameSceneInterface} from "./GameScene";
|
2020-04-11 16:46:28 +02:00
|
|
|
import {UserInputManager} from "../UserInput/UserInputManager";
|
2020-04-07 19:23:21 +02:00
|
|
|
|
|
|
|
export interface MapManagerInterface {
|
|
|
|
Map: Phaser.Tilemaps.Tilemap;
|
|
|
|
Terrain: Phaser.Tilemaps.Tileset;
|
|
|
|
Camera: CameraManagerInterface;
|
2020-04-07 20:41:35 +02:00
|
|
|
Scene: GameSceneInterface;
|
2020-04-11 16:46:28 +02:00
|
|
|
userInputManager: UserInputManager;
|
2020-04-07 19:23:21 +02:00
|
|
|
update(): void;
|
|
|
|
}
|
|
|
|
export class MapManager implements MapManagerInterface{
|
|
|
|
Terrain : Phaser.Tilemaps.Tileset;
|
|
|
|
Camera: CameraManagerInterface;
|
|
|
|
CurrentPlayer: Player;
|
2020-04-07 20:41:35 +02:00
|
|
|
Scene: GameSceneInterface;
|
2020-04-07 19:23:21 +02:00
|
|
|
Map: Phaser.Tilemaps.Tilemap;
|
|
|
|
startX = (window.innerWidth / 2) / RESOLUTION;
|
|
|
|
startY = (window.innerHeight / 2) / RESOLUTION;
|
2020-04-11 16:46:28 +02:00
|
|
|
userInputManager: UserInputManager;
|
2020-04-07 19:23:21 +02:00
|
|
|
|
2020-04-07 20:41:35 +02:00
|
|
|
constructor(scene: GameSceneInterface){
|
2020-04-07 19:23:21 +02:00
|
|
|
this.Scene = scene;
|
|
|
|
|
|
|
|
//initalise map
|
|
|
|
this.Map = this.Scene.add.tilemap("map");
|
|
|
|
this.Terrain = this.Map.addTilesetImage("tiles", "tiles");
|
|
|
|
this.Map.createStaticLayer("tiles", "tiles");
|
|
|
|
this.Map.createStaticLayer("Calque 1", [this.Terrain], 0, 0);
|
|
|
|
this.Map.createStaticLayer("Calque 2", [this.Terrain], 0, 0);
|
|
|
|
|
2020-04-07 22:38:53 +02:00
|
|
|
//initialise camera
|
|
|
|
this.Camera = new CameraManager(this.Scene, this.Scene.cameras.main, this);
|
2020-04-11 16:46:28 +02:00
|
|
|
this.userInputManager = new UserInputManager(this.Scene);
|
2020-04-07 19:23:21 +02:00
|
|
|
//initialise player
|
|
|
|
this.CurrentPlayer = new Player(
|
|
|
|
this.Scene,
|
|
|
|
this.startX,
|
|
|
|
this.startY,
|
2020-04-07 22:38:53 +02:00
|
|
|
this.Camera,
|
2020-04-07 19:23:21 +02:00
|
|
|
this
|
|
|
|
);
|
|
|
|
this.CurrentPlayer.initAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
update() : void {
|
2020-04-11 16:46:28 +02:00
|
|
|
let activeEvents = this.userInputManager.getEventListForGameTick();
|
|
|
|
|
|
|
|
this.CurrentPlayer.move(activeEvents);
|
2020-04-07 19:23:21 +02:00
|
|
|
}
|
|
|
|
}
|