Merge pull request #71 from thecodingmachine/improveAnims
used Phaser's event system to remove the dependency of Player on Connexion
This commit is contained in:
commit
dcaf9a8e46
@ -9,7 +9,11 @@ export enum StatusGameManagerEnum {
|
|||||||
CURRENT_USER_CREATED = 2
|
CURRENT_USER_CREATED = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
export let ConnexionInstance : ConnexionInterface;
|
export interface HasMovedEvent {
|
||||||
|
direction: string;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
}
|
||||||
|
|
||||||
export class GameManager {
|
export class GameManager {
|
||||||
status: number;
|
status: number;
|
||||||
@ -23,9 +27,8 @@ export class GameManager {
|
|||||||
|
|
||||||
connect(email:string) {
|
connect(email:string) {
|
||||||
this.ConnexionInstance = new Connexion(email, this);
|
this.ConnexionInstance = new Connexion(email, this);
|
||||||
ConnexionInstance = this.ConnexionInstance;
|
|
||||||
return this.ConnexionInstance.createConnexion().then(() => {
|
return this.ConnexionInstance.createConnexion().then(() => {
|
||||||
this.SimplePeer = new SimplePeer(ConnexionInstance);
|
this.SimplePeer = new SimplePeer(this.ConnexionInstance);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +60,10 @@ export class GameManager {
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pushPlayerPosition(event: HasMovedEvent) {
|
||||||
|
this.ConnexionInstance.sharePosition(event.x, event.y, event.direction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const gameManager = new GameManager();
|
export const gameManager = new GameManager();
|
@ -1,6 +1,6 @@
|
|||||||
import {GameManager, gameManager, StatusGameManagerEnum} from "./GameManager";
|
import {GameManager, gameManager, HasMovedEvent, StatusGameManagerEnum} from "./GameManager";
|
||||||
import {MessageUserPositionInterface} from "../../Connexion";
|
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 {DEBUG_MODE, RESOLUTION, ROOM, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
|
||||||
import Tile = Phaser.Tilemaps.Tile;
|
import Tile = Phaser.Tilemaps.Tile;
|
||||||
import {ITiledMap, ITiledTileSet} from "../Map/ITiledMap";
|
import {ITiledMap, ITiledTileSet} from "../Map/ITiledMap";
|
||||||
@ -168,6 +168,11 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
//create collision
|
//create collision
|
||||||
this.createCollisionWithPlayer();
|
this.createCollisionWithPlayer();
|
||||||
this.createCollisionObject();
|
this.createCollisionObject();
|
||||||
|
this.CurrentPlayer.on(hasMovedEventName, this.pushPlayerPosition.bind(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
pushPlayerPosition(event: HasMovedEvent) {
|
||||||
|
this.GameManager.pushPlayerPosition(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventToClickOnTile(){
|
EventToClickOnTile(){
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "./Animation";
|
import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "./Animation";
|
||||||
import {GameSceneInterface, Textures} from "../Game/GameScene";
|
import {GameSceneInterface, Textures} from "../Game/GameScene";
|
||||||
import {ConnexionInstance} from "../Game/GameManager";
|
|
||||||
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";
|
||||||
|
|
||||||
|
|
||||||
|
export const hasMovedEventName = "hasMoved";
|
||||||
export interface CurrentGamerInterface extends PlayableCaracter{
|
export interface CurrentGamerInterface extends PlayableCaracter{
|
||||||
userId : string;
|
userId : string;
|
||||||
PlayerValue : string;
|
PlayerValue : string;
|
||||||
@ -88,15 +89,11 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||||||
direction = PlayerAnimationNames.None;
|
direction = PlayerAnimationNames.None;
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
this.sharePosition(direction);
|
|
||||||
}
|
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y});
|
||||||
|
|
||||||
private sharePosition(direction: string) {
|
|
||||||
if (ConnexionInstance) {
|
|
||||||
ConnexionInstance.sharePosition(this.x, this.y, direction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//todo: put this method into the NonPlayer class instead
|
||||||
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