Fix feadback @Kharhamel
This commit is contained in:
parent
48fe86634f
commit
2afe6b4b6e
@ -1,24 +1,20 @@
|
|||||||
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
|
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
|
||||||
import {Player} from "../Player/Player";
|
import {Player} from "../Player/Player";
|
||||||
import {MapManagerInterface} from "./MapManager";
|
import {GameSceneInterface} from "./GameScene";
|
||||||
|
|
||||||
export interface CameraManagerInterface {
|
export interface CameraManagerInterface {
|
||||||
MapManager : MapManagerInterface;
|
|
||||||
moveCamera(CurrentPlayer : Player) : void;
|
moveCamera(CurrentPlayer : Player) : void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CameraManager implements CameraManagerInterface{
|
export class CameraManager implements CameraManagerInterface{
|
||||||
Scene : Phaser.Scene;
|
Scene : GameSceneInterface;
|
||||||
Camera : Phaser.Cameras.Scene2D.Camera;
|
Camera : Phaser.Cameras.Scene2D.Camera;
|
||||||
MapManager : MapManagerInterface;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
Scene: Phaser.Scene,
|
Scene: GameSceneInterface,
|
||||||
Camera : Phaser.Cameras.Scene2D.Camera,
|
Camera : Phaser.Cameras.Scene2D.Camera,
|
||||||
MapManager: MapManagerInterface,
|
|
||||||
) {
|
) {
|
||||||
this.Scene = Scene;
|
this.Scene = Scene;
|
||||||
this.MapManager = MapManager;
|
|
||||||
this.Camera = Camera;
|
this.Camera = Camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,8 +26,8 @@ export class CameraManager implements CameraManagerInterface{
|
|||||||
let limit = {
|
let limit = {
|
||||||
top: startY,
|
top: startY,
|
||||||
left: startX,
|
left: startX,
|
||||||
bottom : this.MapManager.Map.heightInPixels - startY,
|
bottom : this.Scene.Map.heightInPixels - startY,
|
||||||
right: this.MapManager.Map.widthInPixels - startX,
|
right: this.Scene.Map.widthInPixels - startX,
|
||||||
};
|
};
|
||||||
|
|
||||||
if(CurrentPlayer.x < limit.left){
|
if(CurrentPlayer.x < limit.left){
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import {MapManagerInterface, MapManager} from "./MapManager";
|
|
||||||
import {GameManagerInterface, StatusGameManagerEnum} from "./GameManager";
|
import {GameManagerInterface, StatusGameManagerEnum} from "./GameManager";
|
||||||
import {MessageUserPositionInterface} from "../../Connexion";
|
import {MessageUserPositionInterface} from "../../Connexion";
|
||||||
|
import {CameraManager, CameraManagerInterface} from "./CameraManager";
|
||||||
|
import {CurrentGamerInterface, GamerInterface, Player} from "../Player/Player";
|
||||||
|
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
|
||||||
|
import Tile = Phaser.Tilemaps.Tile;
|
||||||
|
|
||||||
export enum Textures {
|
export enum Textures {
|
||||||
Rock = 'rock',
|
Rock = 'rock',
|
||||||
@ -11,13 +14,22 @@ export enum Textures {
|
|||||||
|
|
||||||
export interface GameSceneInterface extends Phaser.Scene {
|
export interface GameSceneInterface extends Phaser.Scene {
|
||||||
RoomId : string;
|
RoomId : string;
|
||||||
|
Map: Phaser.Tilemaps.Tilemap;
|
||||||
createCurrentPlayer(UserId : string) : void;
|
createCurrentPlayer(UserId : string) : void;
|
||||||
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void;
|
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void;
|
||||||
}
|
}
|
||||||
export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
||||||
private MapManager : MapManagerInterface;
|
|
||||||
GameManager : GameManagerInterface;
|
GameManager : GameManagerInterface;
|
||||||
RoomId : string;
|
RoomId : string;
|
||||||
|
Terrain : Phaser.Tilemaps.Tileset;
|
||||||
|
Camera: CameraManagerInterface;
|
||||||
|
CurrentPlayer: CurrentGamerInterface;
|
||||||
|
MapPlayers : Phaser.Physics.Arcade.Group;
|
||||||
|
Map: Phaser.Tilemaps.Tilemap;
|
||||||
|
Layers : Array<Phaser.Tilemaps.StaticTilemapLayer>;
|
||||||
|
Objects : Array<Phaser.Physics.Arcade.Sprite>;
|
||||||
|
startX = (window.innerWidth / 2) / RESOLUTION;
|
||||||
|
startY = (window.innerHeight / 2) / RESOLUTION;
|
||||||
|
|
||||||
constructor(RoomId : string, GameManager : GameManagerInterface) {
|
constructor(RoomId : string, GameManager : GameManagerInterface) {
|
||||||
super({
|
super({
|
||||||
@ -43,26 +55,100 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
|
|
||||||
//hook create scene
|
//hook create scene
|
||||||
create(): void {
|
create(): void {
|
||||||
//create map manager
|
|
||||||
this.MapManager = new MapManager(this);
|
//initalise map
|
||||||
|
this.Map = this.add.tilemap("map");
|
||||||
|
this.Terrain = this.Map.addTilesetImage("tiles", "tiles");
|
||||||
|
this.Map.createStaticLayer("tiles", "tiles");
|
||||||
|
|
||||||
|
//permit to set bound collision
|
||||||
|
this.physics.world.setBounds(0,0, this.Map.widthInPixels, this.Map.heightInPixels);
|
||||||
|
|
||||||
|
//add layer on map
|
||||||
|
this.Layers = new Array<Phaser.Tilemaps.StaticTilemapLayer>();
|
||||||
|
this.addLayer( this.Map.createStaticLayer("Calque 1", [this.Terrain], 0, 0).setDepth(-2) );
|
||||||
|
this.addLayer( this.Map.createStaticLayer("Calque 2", [this.Terrain], 0, 0).setDepth(-1) );
|
||||||
|
|
||||||
|
//add entities
|
||||||
|
this.Objects = new Array<Phaser.Physics.Arcade.Sprite>();
|
||||||
|
this.addSpite(this.physics.add.sprite(200, 400, Textures.Rock, 26));
|
||||||
|
|
||||||
|
//init event click
|
||||||
|
this.EventToClickOnTile();
|
||||||
|
|
||||||
|
//initialise camera
|
||||||
|
this.Camera = new CameraManager(this, this.cameras.main);
|
||||||
|
|
||||||
|
//initialise list of other player
|
||||||
|
this.MapPlayers = this.physics.add.group({ immovable: true });
|
||||||
|
|
||||||
//notify game manager can to create currentUser in map
|
//notify game manager can to create currentUser in map
|
||||||
this.GameManager.createCurrentPlayer();
|
this.GameManager.createCurrentPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
addLayer(Layer : Phaser.Tilemaps.StaticTilemapLayer){
|
||||||
* Create current player
|
this.Layers.push(Layer);
|
||||||
* @param UserId
|
|
||||||
*/
|
|
||||||
createCurrentPlayer(UserId : string): void {
|
|
||||||
this.MapManager.createCurrentPlayer(UserId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//hook update
|
createCollisionWithPlayer() {
|
||||||
update(dt: number): void {
|
//add collision layer
|
||||||
if(this.GameManager.status === StatusGameManagerEnum.IN_PROGRESS){
|
this.Layers.forEach((Layer: Phaser.Tilemaps.StaticTilemapLayer) => {
|
||||||
return;
|
this.physics.add.collider(this.CurrentPlayer, Layer, (object1: any, object2: any) => {
|
||||||
|
this.CurrentPlayer.say("Collision with layer : "+ (object2 as Tile).layer.name)
|
||||||
|
});
|
||||||
|
Layer.setCollisionByProperty({collides: true});
|
||||||
|
//debug code
|
||||||
|
//debug code to see the collision hitbox of the object in the top layer
|
||||||
|
Layer.renderDebug(this.add.graphics(), {
|
||||||
|
tileColor: null, //non-colliding tiles
|
||||||
|
collidingTileColor: new Phaser.Display.Color(243, 134, 48, 200), // Colliding tiles,
|
||||||
|
faceColor: new Phaser.Display.Color(40, 39, 37, 255) // Colliding face edges
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
this.MapManager.update();
|
|
||||||
|
addSpite(Object : Phaser.Physics.Arcade.Sprite){
|
||||||
|
Object.setImmovable(true);
|
||||||
|
this.Objects.push(Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
createCollisionObject(){
|
||||||
|
this.Objects.forEach((Object : Phaser.Physics.Arcade.Sprite) => {
|
||||||
|
this.physics.add.collider(this.CurrentPlayer, Object, (object1: any, object2: any) => {
|
||||||
|
this.CurrentPlayer.say("Collision with object : " + (object2 as Phaser.Physics.Arcade.Sprite).texture.key)
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
createCurrentPlayer(UserId : string){
|
||||||
|
//initialise player
|
||||||
|
this.CurrentPlayer = new Player(
|
||||||
|
UserId,
|
||||||
|
this,
|
||||||
|
this.startX,
|
||||||
|
this.startY,
|
||||||
|
this.Camera,
|
||||||
|
);
|
||||||
|
this.CurrentPlayer.initAnimation();
|
||||||
|
|
||||||
|
//create collision
|
||||||
|
this.createCollisionWithPlayer();
|
||||||
|
this.createCollisionObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
EventToClickOnTile(){
|
||||||
|
// debug code to get a tile properties by clicking on it
|
||||||
|
this.input.on("pointerdown", (pointer: Phaser.Input.Pointer)=>{
|
||||||
|
//pixel position toz tile position
|
||||||
|
let tile = this.Map.getTileAt(this.Map.worldToTileX(pointer.worldX), this.Map.worldToTileY(pointer.worldY));
|
||||||
|
if(tile){
|
||||||
|
this.CurrentPlayer.say("Your touch " + tile.layer.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
update() : void {
|
||||||
|
this.CurrentPlayer.moveUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,6 +156,69 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
* @param UsersPosition
|
* @param UsersPosition
|
||||||
*/
|
*/
|
||||||
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void {
|
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void {
|
||||||
this.MapManager.updateOrCreateMapPlayer(UsersPosition);
|
this.updateOrCreateMapPlayer(UsersPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new player and clean the player on the map
|
||||||
|
* @param UsersPosition
|
||||||
|
*/
|
||||||
|
updateOrCreateMapPlayer(UsersPosition : Array<MessageUserPositionInterface>){
|
||||||
|
if(!this.CurrentPlayer){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//add or create new user
|
||||||
|
UsersPosition.forEach((userPosition : MessageUserPositionInterface) => {
|
||||||
|
if(userPosition.userId === this.CurrentPlayer.userId){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let player = this.findPlayerInMap(userPosition.userId);
|
||||||
|
if(!player){
|
||||||
|
this.addPlayer(userPosition);
|
||||||
|
}else{
|
||||||
|
player.updatePosition(userPosition);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//clean map
|
||||||
|
this.MapPlayers.getChildren().forEach((player: GamerInterface) => {
|
||||||
|
if(UsersPosition.find((message : MessageUserPositionInterface) => message.userId === player.userId)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.destroy();
|
||||||
|
this.MapPlayers.remove(player);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private findPlayerInMap(UserId : string) : GamerInterface | null{
|
||||||
|
let player = this.MapPlayers.getChildren().find((player: Player) => UserId === player.userId);
|
||||||
|
if(!player){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (player as GamerInterface);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new player
|
||||||
|
* @param MessageUserPosition
|
||||||
|
*/
|
||||||
|
addPlayer(MessageUserPosition : MessageUserPositionInterface){
|
||||||
|
//initialise player
|
||||||
|
let player = new Player(
|
||||||
|
MessageUserPosition.userId,
|
||||||
|
this,
|
||||||
|
MessageUserPosition.position.x,
|
||||||
|
MessageUserPosition.position.y,
|
||||||
|
this.Camera,
|
||||||
|
);
|
||||||
|
player.initAnimation();
|
||||||
|
this.MapPlayers.add(player);
|
||||||
|
player.updatePosition(MessageUserPosition);
|
||||||
|
|
||||||
|
//init colision
|
||||||
|
this.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
|
||||||
|
MapPlayer.say("Hello, how are you ? ");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,196 +0,0 @@
|
|||||||
import {CameraManager, CameraManagerInterface} from "./CameraManager";
|
|
||||||
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
|
|
||||||
import {CurrentGamerInterface, GamerInterface, Player} from "../Player/Player";
|
|
||||||
import {GameSceneInterface, Textures} from "./GameScene";
|
|
||||||
import {MessageUserPositionInterface} from "../../Connexion";
|
|
||||||
import {NonPlayer} from "../NonPlayer/NonPlayer";
|
|
||||||
import GameObject = Phaser.GameObjects.GameObject;
|
|
||||||
import Tile = Phaser.Tilemaps.Tile;
|
|
||||||
|
|
||||||
export interface MapManagerInterface {
|
|
||||||
Map: Phaser.Tilemaps.Tilemap;
|
|
||||||
Terrain: Phaser.Tilemaps.Tileset;
|
|
||||||
Camera: CameraManagerInterface;
|
|
||||||
Scene: GameSceneInterface;
|
|
||||||
|
|
||||||
createCurrentPlayer(UserId : string): void;
|
|
||||||
update(): void;
|
|
||||||
updateOrCreateMapPlayer(UsersPosition : Array<MessageUserPositionInterface>): void;
|
|
||||||
}
|
|
||||||
export class MapManager implements MapManagerInterface{
|
|
||||||
Terrain : Phaser.Tilemaps.Tileset;
|
|
||||||
Camera: CameraManagerInterface;
|
|
||||||
CurrentPlayer: CurrentGamerInterface;
|
|
||||||
MapPlayers : Phaser.Physics.Arcade.Group;
|
|
||||||
Scene: GameSceneInterface;
|
|
||||||
Map: Phaser.Tilemaps.Tilemap;
|
|
||||||
Layers : Array<Phaser.Tilemaps.StaticTilemapLayer>;
|
|
||||||
Objects : Array<Phaser.Physics.Arcade.Sprite>;
|
|
||||||
startX = (window.innerWidth / 2) / RESOLUTION;
|
|
||||||
startY = (window.innerHeight / 2) / RESOLUTION;
|
|
||||||
|
|
||||||
constructor(scene: GameSceneInterface){
|
|
||||||
this.Scene = scene;
|
|
||||||
|
|
||||||
//initalise map
|
|
||||||
this.Map = this.Scene.add.tilemap("map");
|
|
||||||
this.Terrain = this.Map.addTilesetImage("tiles", "tiles");
|
|
||||||
this.Map.createStaticLayer("tiles", "tiles");
|
|
||||||
|
|
||||||
//permit to set bound collision
|
|
||||||
this.Scene.physics.world.setBounds(0,0, this.Map.widthInPixels, this.Map.heightInPixels);
|
|
||||||
|
|
||||||
//add layer on map
|
|
||||||
this.Layers = new Array<Phaser.Tilemaps.StaticTilemapLayer>();
|
|
||||||
this.addLayer( this.Map.createStaticLayer("Calque 1", [this.Terrain], 0, 0).setDepth(-2) );
|
|
||||||
this.addLayer( this.Map.createStaticLayer("Calque 2", [this.Terrain], 0, 0).setDepth(-1) );
|
|
||||||
|
|
||||||
//add entities
|
|
||||||
this.Objects = new Array<Phaser.Physics.Arcade.Sprite>();
|
|
||||||
this.addSpite(this.Scene.physics.add.sprite(200, 400, Textures.Rock, 26));
|
|
||||||
|
|
||||||
//debug code
|
|
||||||
//debug code to see the collision hitbox of the object in the top layer
|
|
||||||
/*this.TopLayer.renderDebug(this.Scene.add.graphics(),{
|
|
||||||
tileColor: null, //non-colliding tiles
|
|
||||||
collidingTileColor: new Phaser.Display.Color(243, 134, 48, 200), // Colliding tiles,
|
|
||||||
faceColor: new Phaser.Display.Color(40, 39, 37, 255) // Colliding face edges
|
|
||||||
});*/
|
|
||||||
|
|
||||||
//init event click
|
|
||||||
this.EventToClickOnTile();
|
|
||||||
|
|
||||||
//initialise camera
|
|
||||||
this.Camera = new CameraManager(this.Scene, this.Scene.cameras.main, this);
|
|
||||||
|
|
||||||
//initialise list of other player
|
|
||||||
this.MapPlayers = this.Scene.physics.add.group({ immovable: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
addLayer(Layer : Phaser.Tilemaps.StaticTilemapLayer){
|
|
||||||
this.Layers.push(Layer);
|
|
||||||
}
|
|
||||||
|
|
||||||
createCollisionWithPlayer() {
|
|
||||||
//add collision layer
|
|
||||||
this.Layers.forEach((Layer: Phaser.Tilemaps.StaticTilemapLayer) => {
|
|
||||||
this.Scene.physics.add.collider(this.CurrentPlayer, Layer);
|
|
||||||
Layer.setCollisionByProperty({collides: true});
|
|
||||||
//debug code
|
|
||||||
//debug code to see the collision hitbox of the object in the top layer
|
|
||||||
Layer.renderDebug(this.Scene.add.graphics(), {
|
|
||||||
tileColor: null, //non-colliding tiles
|
|
||||||
collidingTileColor: new Phaser.Display.Color(243, 134, 48, 200), // Colliding tiles,
|
|
||||||
faceColor: new Phaser.Display.Color(40, 39, 37, 255) // Colliding face edges
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
addSpite(Object : Phaser.Physics.Arcade.Sprite){
|
|
||||||
Object.setImmovable(true);
|
|
||||||
this.Objects.push(Object);
|
|
||||||
}
|
|
||||||
|
|
||||||
createCollisionObject(){
|
|
||||||
this.Objects.forEach((Object : Phaser.Physics.Arcade.Sprite) => {
|
|
||||||
this.Scene.physics.add.collider(this.CurrentPlayer, Object);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
createCurrentPlayer(UserId : string){
|
|
||||||
//initialise player
|
|
||||||
this.CurrentPlayer = new Player(
|
|
||||||
UserId,
|
|
||||||
this.Scene,
|
|
||||||
this.startX,
|
|
||||||
this.startY,
|
|
||||||
this.Camera,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
this.CurrentPlayer.initAnimation();
|
|
||||||
|
|
||||||
//create collision
|
|
||||||
this.createCollisionWithPlayer();
|
|
||||||
this.createCollisionObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
EventToClickOnTile(){
|
|
||||||
// debug code to get a tile properties by clicking on it
|
|
||||||
this.Scene.input.on("pointerdown", (pointer: Phaser.Input.Pointer)=>{
|
|
||||||
//pixel position toz tile position
|
|
||||||
let tile = this.Map.getTileAt(this.Map.worldToTileX(pointer.worldX), this.Map.worldToTileY(pointer.worldY));
|
|
||||||
if(tile){
|
|
||||||
//console.log("MapManager => tile => pointerdown", tile);
|
|
||||||
this.CurrentPlayer.say("Your touch " + tile.layer.name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
update() : void {
|
|
||||||
this.CurrentPlayer.moveUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new player and clean the player on the map
|
|
||||||
* @param UsersPosition
|
|
||||||
*/
|
|
||||||
updateOrCreateMapPlayer(UsersPosition : Array<MessageUserPositionInterface>){
|
|
||||||
if(!this.CurrentPlayer){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//add or create new user
|
|
||||||
UsersPosition.forEach((userPosition : MessageUserPositionInterface) => {
|
|
||||||
if(userPosition.userId === this.CurrentPlayer.userId){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let player = this.findPlayerInMap(userPosition.userId);
|
|
||||||
if(!player){
|
|
||||||
this.addPlayer(userPosition);
|
|
||||||
}else{
|
|
||||||
player.updatePosition(userPosition);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//clean map
|
|
||||||
this.MapPlayers.getChildren().forEach((player: GamerInterface) => {
|
|
||||||
if(UsersPosition.find((message : MessageUserPositionInterface) => message.userId === player.userId)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
player.destroy();
|
|
||||||
this.MapPlayers.remove(player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private findPlayerInMap(UserId : string) : GamerInterface | null{
|
|
||||||
let player = this.MapPlayers.getChildren().find((player: Player) => UserId === player.userId);
|
|
||||||
if(!player){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (player as GamerInterface);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new player
|
|
||||||
* @param MessageUserPosition
|
|
||||||
*/
|
|
||||||
addPlayer(MessageUserPosition : MessageUserPositionInterface){
|
|
||||||
//initialise player
|
|
||||||
let player = new Player(
|
|
||||||
MessageUserPosition.userId,
|
|
||||||
this.Scene,
|
|
||||||
MessageUserPosition.position.x,
|
|
||||||
MessageUserPosition.position.y,
|
|
||||||
this.Camera,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
player.initAnimation();
|
|
||||||
this.MapPlayers.add(player);
|
|
||||||
player.updatePosition(MessageUserPosition);
|
|
||||||
|
|
||||||
//init colision
|
|
||||||
this.Scene.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
|
|
||||||
MapPlayer.say("Hello, how are you ? ");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,11 +5,9 @@ import {CameraManagerInterface} from "../Game/CameraManager";
|
|||||||
import {MessageUserPositionInterface} from "../../Connexion";
|
import {MessageUserPositionInterface} from "../../Connexion";
|
||||||
import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
|
import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
|
||||||
import {PlayableCaracter} from "../Entity/PlayableCaracter";
|
import {PlayableCaracter} from "../Entity/PlayableCaracter";
|
||||||
import {MapManagerInterface} from "../Game/MapManager";
|
|
||||||
|
|
||||||
export interface CurrentGamerInterface extends PlayableCaracter{
|
export interface CurrentGamerInterface extends PlayableCaracter{
|
||||||
userId : string;
|
userId : string;
|
||||||
MapManager : MapManagerInterface;
|
|
||||||
PlayerValue : string;
|
PlayerValue : string;
|
||||||
CameraManager: CameraManagerInterface;
|
CameraManager: CameraManagerInterface;
|
||||||
initAnimation() : void;
|
initAnimation() : void;
|
||||||
@ -19,7 +17,6 @@ export interface CurrentGamerInterface extends PlayableCaracter{
|
|||||||
|
|
||||||
export interface GamerInterface extends PlayableCaracter{
|
export interface GamerInterface extends PlayableCaracter{
|
||||||
userId : string;
|
userId : string;
|
||||||
MapManager : MapManagerInterface;
|
|
||||||
PlayerValue : string;
|
PlayerValue : string;
|
||||||
CameraManager: CameraManagerInterface;
|
CameraManager: CameraManagerInterface;
|
||||||
initAnimation() : void;
|
initAnimation() : void;
|
||||||
@ -29,7 +26,6 @@ export interface GamerInterface extends PlayableCaracter{
|
|||||||
|
|
||||||
export class Player extends PlayableCaracter implements CurrentGamerInterface, GamerInterface {
|
export class Player extends PlayableCaracter implements CurrentGamerInterface, GamerInterface {
|
||||||
userId: string;
|
userId: string;
|
||||||
MapManager : MapManagerInterface;
|
|
||||||
PlayerValue: string;
|
PlayerValue: string;
|
||||||
CameraManager: CameraManagerInterface;
|
CameraManager: CameraManagerInterface;
|
||||||
userInputManager: UserInputManager;
|
userInputManager: UserInputManager;
|
||||||
@ -40,7 +36,6 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
CameraManager: CameraManagerInterface,
|
CameraManager: CameraManagerInterface,
|
||||||
MapManager: MapManagerInterface,
|
|
||||||
PlayerValue: string = Textures.Player
|
PlayerValue: string = Textures.Player
|
||||||
) {
|
) {
|
||||||
super(Scene, x, y, PlayerValue, 1);
|
super(Scene, x, y, PlayerValue, 1);
|
||||||
@ -51,7 +46,6 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||||||
//set data
|
//set data
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.PlayerValue = PlayerValue;
|
this.PlayerValue = PlayerValue;
|
||||||
this.MapManager = MapManager;
|
|
||||||
this.CameraManager = CameraManager;
|
this.CameraManager = CameraManager;
|
||||||
|
|
||||||
//the current player model should be push away by other players to prevent conflict
|
//the current player model should be push away by other players to prevent conflict
|
||||||
@ -73,7 +67,6 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||||||
|
|
||||||
moveUser(): void {
|
moveUser(): void {
|
||||||
//if user client on shift, camera and player speed
|
//if user client on shift, camera and player speed
|
||||||
//let speedMultiplier = this.MapManager.keyShift.isDown ? 5 : 1;
|
|
||||||
let haveMove = false;
|
let haveMove = false;
|
||||||
let direction = null;
|
let direction = null;
|
||||||
|
|
||||||
@ -81,33 +74,21 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||||||
let speedMultiplier = activeEvents.get(UserInputEvent.SpeedUp) ? 500 : 100;
|
let speedMultiplier = activeEvents.get(UserInputEvent.SpeedUp) ? 500 : 100;
|
||||||
|
|
||||||
if (activeEvents.get(UserInputEvent.MoveUp)) {
|
if (activeEvents.get(UserInputEvent.MoveUp)) {
|
||||||
if (!this.CanMoveUp()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.move(0, -speedMultiplier);
|
this.move(0, -speedMultiplier);
|
||||||
haveMove = true;
|
haveMove = true;
|
||||||
direction = PlayerAnimationNames.WalkUp;
|
direction = PlayerAnimationNames.WalkUp;
|
||||||
}
|
}
|
||||||
if (activeEvents.get(UserInputEvent.MoveLeft)) {
|
if (activeEvents.get(UserInputEvent.MoveLeft)) {
|
||||||
if (!this.CanMoveLeft()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.move(-speedMultiplier, 0);
|
this.move(-speedMultiplier, 0);
|
||||||
haveMove = true;
|
haveMove = true;
|
||||||
direction = PlayerAnimationNames.WalkLeft;
|
direction = PlayerAnimationNames.WalkLeft;
|
||||||
}
|
}
|
||||||
if (activeEvents.get(UserInputEvent.MoveDown)) {
|
if (activeEvents.get(UserInputEvent.MoveDown)) {
|
||||||
if (!this.CanMoveDown()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.move(0, speedMultiplier);
|
this.move(0, speedMultiplier);
|
||||||
haveMove = true;
|
haveMove = true;
|
||||||
direction = PlayerAnimationNames.WalkDown;
|
direction = PlayerAnimationNames.WalkDown;
|
||||||
}
|
}
|
||||||
if (activeEvents.get(UserInputEvent.MoveRight)) {
|
if (activeEvents.get(UserInputEvent.MoveRight)) {
|
||||||
if (!this.CanMoveRight()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.move(speedMultiplier, 0);
|
this.move(speedMultiplier, 0);
|
||||||
haveMove = true;
|
haveMove = true;
|
||||||
direction = PlayerAnimationNames.WalkRight;
|
direction = PlayerAnimationNames.WalkRight;
|
||||||
@ -126,26 +107,6 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CanMoveUp(){
|
|
||||||
return this.y > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CanMoveLeft(){
|
|
||||||
return this.x > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CanMoveDown(){
|
|
||||||
return this.MapManager.Map.heightInPixels > this.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CanMoveRight() {
|
|
||||||
return this.MapManager.Map.widthInPixels > this.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
this.setVelocity(0, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePosition(MessageUserPosition: MessageUserPositionInterface) {
|
updatePosition(MessageUserPosition: MessageUserPositionInterface) {
|
||||||
playAnimation(this, MessageUserPosition.position.direction);
|
playAnimation(this, MessageUserPosition.position.direction);
|
||||||
this.setX(MessageUserPosition.position.x);
|
this.setX(MessageUserPosition.position.x);
|
||||||
|
Loading…
Reference in New Issue
Block a user