CURRENT_USER_CREATED = 2
}
-export let ConnexionInstance : ConnexionInterface;
+export interface HasMovedEvent {
+ direction: string;
+ x: number;
+ y: number;
+}
export class GameManager {
status: number;
connect(email:string) {
this.ConnexionInstance = new Connexion(email, this);
- ConnexionInstance = this.ConnexionInstance;
return this.ConnexionInstance.createConnexion().then(() => {
- this.SimplePeer = new SimplePeer(ConnexionInstance);
+ this.SimplePeer = new SimplePeer(this.ConnexionInstance);
});
}
console.error(e);
}
}
+
+ pushPlayerPosition(event: HasMovedEvent) {
+ this.ConnexionInstance.sharePosition(event.x, event.y, event.direction);
+ }
}
export const gameManager = new GameManager();
\ No newline at end of file
-import {GameManager, gameManager, StatusGameManagerEnum} from "./GameManager";
+import {GameManager, gameManager, HasMovedEvent, StatusGameManagerEnum} from "./GameManager";
import {MessageUserPositionInterface} from "../../Connexion";
-import {CurrentGamerInterface, GamerInterface, Player} from "../Player/Player";
+import {CurrentGamerInterface, GamerInterface, hasMovedEventName, Player} from "../Player/Player";
import {DEBUG_MODE, RESOLUTION, ROOM, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
import Tile = Phaser.Tilemaps.Tile;
import {ITiledMap, ITiledTileSet} from "../Map/ITiledMap";
//create collision
this.createCollisionWithPlayer();
this.createCollisionObject();
+ this.CurrentPlayer.on(hasMovedEventName, this.pushPlayerPosition.bind(this))
+ }
+
+ pushPlayerPosition(event: HasMovedEvent) {
+ this.GameManager.pushPlayerPosition(event);
}
EventToClickOnTile(){
import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "./Animation";
import {GameSceneInterface, Textures} from "../Game/GameScene";
-import {ConnexionInstance} from "../Game/GameManager";
import {MessageUserPositionInterface} from "../../Connexion";
import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
import {PlayableCaracter} from "../Entity/PlayableCaracter";
+
+export const hasMovedEventName = "hasMoved";
export interface CurrentGamerInterface extends PlayableCaracter{
userId : string;
PlayerValue : string;
direction = PlayerAnimationNames.None;
this.stop();
}
- this.sharePosition(direction);
- }
-
- private sharePosition(direction: string) {
- if (ConnexionInstance) {
- ConnexionInstance.sharePosition(this.x, this.y, direction);
- }
+
+ this.emit(hasMovedEventName, {direction, x: this.x, y: this.y});
}
+ //todo: put this method into the NonPlayer class instead
updatePosition(MessageUserPosition: MessageUserPositionInterface) {
playAnimation(this, MessageUserPosition.position.direction);
this.setX(MessageUserPosition.position.x);