Multi players on the map

- Fix share user position
 - Fix initialise map
 - Create function to add user on the map with back end data
This commit is contained in:
gparant 2020-04-10 12:54:05 +02:00
parent 6bec8b3703
commit d257b2b944
10 changed files with 253 additions and 48 deletions

View file

@ -3,13 +3,16 @@ import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "./Animat
import {GameSceneInterface} from "../Game/GameScene";
import {ConnexionInstance} from "../Game/GameManager";
import {CameraManagerInterface} from "../Game/CameraManager";
import {MessageUserPositionInterface} from "../../Connexion";
export class Player extends Phaser.GameObjects.Sprite{
userId : string;
MapManager : MapManagerInterface;
PlayerValue : string;
CameraManager: CameraManagerInterface;
constructor(
userId: string,
Scene : GameSceneInterface,
x : number,
y : number,
@ -18,13 +21,13 @@ export class Player extends Phaser.GameObjects.Sprite{
PlayerValue : string = "player"
) {
super(Scene, x, y, PlayerValue);
this.userId = userId;
this.PlayerValue = PlayerValue;
Scene.add.existing(this);
this.MapManager = MapManager;
this.CameraManager = CameraManager;
}
initAnimation(){
getPlayerAnimations(this.PlayerValue).forEach(d => {
this.scene.anims.create({
@ -80,10 +83,9 @@ export class Player extends Phaser.GameObjects.Sprite{
}
if(!haveMove){
playAnimation(this, PlayerAnimationNames.None);
}else{
this.sharePosition(direction);
direction = PlayerAnimationNames.None;
}
this.sharePosition(direction);
this.CameraManager.moveCamera(this);
}
@ -108,4 +110,10 @@ export class Player extends Phaser.GameObjects.Sprite{
private CanMoveRight(){
return this.MapManager.Map.widthInPixels > this.x;
}
updatePosition(MessageUserPosition : MessageUserPositionInterface){
playAnimation(this, MessageUserPosition.position.direction);
this.setX(MessageUserPosition.position.x);
this.setY(MessageUserPosition.position.y);
}
}