2020-04-07 19:23:21 +02:00
|
|
|
import {MapManagerInterface, MapManager} from "./MapManager";
|
2020-04-10 12:54:05 +02:00
|
|
|
import {GameManagerInterface, StatusGameManagerEnum} from "./GameManager";
|
|
|
|
import {MessageUserPositionInterface} from "../../Connexion";
|
2020-04-07 19:23:21 +02:00
|
|
|
|
2020-04-11 18:17:36 +02:00
|
|
|
export enum Textures {
|
|
|
|
Rock = 'rock',
|
2020-04-12 18:28:05 +02:00
|
|
|
Player = 'playerModel',
|
2020-04-12 16:12:08 +02:00
|
|
|
Map = 'map',
|
|
|
|
Tiles = 'tiles'
|
2020-04-11 18:17:36 +02:00
|
|
|
}
|
|
|
|
|
2020-04-07 20:41:35 +02:00
|
|
|
export interface GameSceneInterface extends Phaser.Scene {
|
|
|
|
RoomId : string;
|
2020-04-10 12:54:05 +02:00
|
|
|
createCurrentPlayer(UserId : string) : void;
|
|
|
|
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void;
|
2020-04-07 20:41:35 +02:00
|
|
|
}
|
|
|
|
export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
2020-04-07 19:23:21 +02:00
|
|
|
private MapManager : MapManagerInterface;
|
2020-04-10 12:54:05 +02:00
|
|
|
GameManager : GameManagerInterface;
|
2020-04-07 20:41:35 +02:00
|
|
|
RoomId : string;
|
2020-04-07 19:23:21 +02:00
|
|
|
|
2020-04-07 20:41:35 +02:00
|
|
|
constructor(RoomId : string, GameManager : GameManagerInterface) {
|
2020-04-07 19:23:21 +02:00
|
|
|
super({
|
|
|
|
key: "GameScene"
|
|
|
|
});
|
2020-04-07 20:41:35 +02:00
|
|
|
this.RoomId = RoomId;
|
2020-04-10 12:54:05 +02:00
|
|
|
this.GameManager = GameManager;
|
2020-04-07 19:23:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//hook preload scene
|
|
|
|
preload(): void {
|
2020-04-12 16:12:08 +02:00
|
|
|
this.load.image(Textures.Tiles, 'maps/tiles.png');
|
|
|
|
this.load.tilemapTiledJSON(Textures.Map, 'maps/map2.json');
|
2020-04-13 13:42:21 +02:00
|
|
|
this.load.image(Textures.Rock, 'resources/objects/rockSprite.png');
|
2020-04-12 16:12:08 +02:00
|
|
|
this.load.spritesheet(Textures.Player,
|
2020-04-07 19:23:21 +02:00
|
|
|
'resources/characters/pipoya/Male 01-1.png',
|
|
|
|
{ frameWidth: 32, frameHeight: 32 }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//hook initialisation
|
2020-04-07 20:46:30 +02:00
|
|
|
init(){}
|
2020-04-07 19:23:21 +02:00
|
|
|
|
|
|
|
//hook create scene
|
|
|
|
create(): void {
|
|
|
|
//create map manager
|
|
|
|
this.MapManager = new MapManager(this);
|
2020-04-10 12:54:05 +02:00
|
|
|
//notify game manager can to create currentUser in map
|
|
|
|
this.GameManager.createCurrentPlayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create current player
|
|
|
|
* @param UserId
|
|
|
|
*/
|
|
|
|
createCurrentPlayer(UserId : string): void {
|
|
|
|
this.MapManager.createCurrentPlayer(UserId)
|
2020-04-07 19:23:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//hook update
|
|
|
|
update(dt: number): void {
|
2020-04-10 12:54:05 +02:00
|
|
|
if(this.GameManager.status === StatusGameManagerEnum.IN_PROGRESS){
|
|
|
|
return;
|
|
|
|
}
|
2020-04-07 19:23:21 +02:00
|
|
|
this.MapManager.update();
|
|
|
|
}
|
2020-04-07 20:41:35 +02:00
|
|
|
|
2020-04-10 12:54:05 +02:00
|
|
|
/**
|
|
|
|
* Share position in scene
|
|
|
|
* @param UsersPosition
|
|
|
|
*/
|
|
|
|
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void {
|
|
|
|
this.MapManager.updateOrCreateMapPlayer(UsersPosition);
|
2020-04-07 20:41:35 +02:00
|
|
|
}
|
2020-04-07 19:23:21 +02:00
|
|
|
}
|