Changing the "Point" notion to add a notion of "moving" in addition to the notion of direction.
Also, refactoring JOIN_ROOM event to add complete position.
This commit is contained in:
parent
f44a44c109
commit
ab798b1c09
9 changed files with 101 additions and 88 deletions
|
@ -16,6 +16,7 @@ export enum StatusGameManagerEnum {
|
|||
|
||||
export interface HasMovedEvent {
|
||||
direction: string;
|
||||
moving: boolean;
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
@ -71,8 +72,8 @@ export class GameManager {
|
|||
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
|
||||
}
|
||||
|
||||
joinRoom(sceneKey : string){
|
||||
this.ConnexionInstance.joinARoom(sceneKey);
|
||||
joinRoom(sceneKey: string, startX: number, startY: number, direction: string, moving: boolean){
|
||||
this.ConnexionInstance.joinARoom(sceneKey, startX, startY, direction, moving);
|
||||
}
|
||||
|
||||
onUserJoins(message: MessageUserJoined): void {
|
||||
|
@ -80,7 +81,7 @@ export class GameManager {
|
|||
userId: message.userId,
|
||||
character: message.character,
|
||||
name: message.name,
|
||||
position: new Point(-1000, -1000)
|
||||
position: message.position
|
||||
}
|
||||
this.currentGameScene.addPlayer(userMessage);
|
||||
}
|
||||
|
@ -159,7 +160,7 @@ export class GameManager {
|
|||
}
|
||||
|
||||
pushPlayerPosition(event: HasMovedEvent) {
|
||||
this.ConnexionInstance.sharePosition(event.x, event.y, event.direction);
|
||||
this.ConnexionInstance.sharePosition(event.x, event.y, event.direction, event.moving);
|
||||
}
|
||||
|
||||
loadMap(mapUrl: string, scene: ScenePlugin): string {
|
||||
|
|
|
@ -13,6 +13,7 @@ import Texture = Phaser.Textures.Texture;
|
|||
import Sprite = Phaser.GameObjects.Sprite;
|
||||
import CanvasTexture = Phaser.Textures.CanvasTexture;
|
||||
import {AddPlayerInterface} from "./AddPlayerInterface";
|
||||
import {PlayerAnimationNames} from "../Player/Animation";
|
||||
|
||||
export enum Textures {
|
||||
Player = "male1"
|
||||
|
@ -273,16 +274,17 @@ export class GameScene extends Phaser.Scene {
|
|||
this.startX,
|
||||
this.startY,
|
||||
this.GameManager.getPlayerName(),
|
||||
this.GameManager.getCharacterSelected()
|
||||
this.GameManager.getCharacterSelected(),
|
||||
PlayerAnimationNames.WalkDown,
|
||||
false
|
||||
);
|
||||
this.CurrentPlayer.initAnimation();
|
||||
|
||||
//create collision
|
||||
this.createCollisionWithPlayer();
|
||||
this.createCollisionObject();
|
||||
|
||||
//join room
|
||||
this.GameManager.joinRoom(this.scene.key);
|
||||
this.GameManager.joinRoom(this.scene.key, this.startX, this.startY, PlayerAnimationNames.WalkDown, false);
|
||||
|
||||
//listen event to share position of user
|
||||
this.CurrentPlayer.on(hasMovedEventName, this.pushPlayerPosition.bind(this))
|
||||
|
@ -415,9 +417,10 @@ export class GameScene extends Phaser.Scene {
|
|||
addPlayerData.position.x,
|
||||
addPlayerData.position.y,
|
||||
addPlayerData.name,
|
||||
addPlayerData.character
|
||||
addPlayerData.character,
|
||||
addPlayerData.position.direction,
|
||||
addPlayerData.position.moving
|
||||
);
|
||||
player.initAnimation();
|
||||
this.MapPlayers.add(player);
|
||||
this.MapPlayersByKey.set(player.userId, player);
|
||||
player.updatePosition(addPlayerData.position);
|
||||
|
@ -429,6 +432,7 @@ export class GameScene extends Phaser.Scene {
|
|||
}
|
||||
|
||||
public removePlayer(userId: string) {
|
||||
console.log('Removing player ', userId)
|
||||
let player = this.MapPlayersByKey.get(userId);
|
||||
if (player === undefined) {
|
||||
console.error('Cannot find user with id ', userId);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue