+import {GameManagerInterface} from "./Phaser/Game/GameManager";
+
const SocketIo = require('socket.io-client');
import Axios from "axios";
import {API_URL} from "./Enum/EnvironmentVariable";
email : string;
startedRoom : string;
- constructor(email : string) {
+ GameManager: GameManagerInterface;
+
+ constructor(email : string, GameManager: GameManagerInterface) {
this.email = email;
+ this.GameManager = GameManager;
Axios.post(`${API_URL}/login`, {email: email})
.then((res) => {
this.token = res.data.token;
this.joinARoom(this.startedRoom);
//share your first position
- this.sharePosition(0, 0);
+ this.sharePosition(this.startedRoom, 0, 0);
- //create listen event to get all data user shared by the back
this.positionOfAllUser();
this.errorMessage();
* @param x
* @param y
*/
- sharePosition(x : number, y : number){
- let messageUserPosition = new MessageUserPosition(this.email, this.startedRoom, new Point(x, y));
+ sharePosition(roomId : string, x : number, y : number){
+ let messageUserPosition = new MessageUserPosition(this.email, roomId, new Point(x, y));
this.socket.emit('user-position', messageUserPosition.toString());
}
**/
positionOfAllUser(){
this.socket.on("user-position", (message : string) => {
- //TODO show all user in map
- console.info("user-position", message);
+ let data = JSON.parse(message);
+ data.forEach((UserPositions : any) => {
+ this.GameManager.sharedUserPosition(UserPositions);
+ });
});
}
const API_URL = process.env.API_URL || "http://api.workadventure.localhost";
+const ROOM = [process.env.ROOM || "THECODINGMACHINE"];
const RESOLUTION = 2;
export {
API_URL,
- RESOLUTION
+ RESOLUTION,
+ ROOM
}
\ No newline at end of file
-import {RESOLUTION} from "../Enum/EnvironmentVariable";
-import {Player} from "./Player";
+import {RESOLUTION} from "../../Enum/EnvironmentVariable";
+import {Player} from "../Player/Player";
import {MapManagerInterface} from "./MapManager";
export interface CameraManagerInterface {
--- /dev/null
+import {GameSceneInterface, GameScene} from "./GameScene";
+import {ROOM} from "../../Enum/EnvironmentVariable"
+import {Connexion} from "../../Connexion";
+
+export let ConnexionInstance : Connexion;
+
+export interface GameManagerInterface {
+ GameScenes: Array<GameSceneInterface>;
+
+ sharedUserPosition(UserPositions: any): void;
+}
+export class GameManager implements GameManagerInterface {
+ GameScenes: Array<GameSceneInterface> = [];
+
+ constructor() {
+ this.configureGame();
+ ConnexionInstance = new Connexion("test@gmail.com", this);
+ }
+
+ configureGame() {
+ ROOM.forEach((roomId) => {
+ let newGame = new GameScene(roomId, this);
+ this.GameScenes.push(newGame);
+ });
+ }
+
+ sharedUserPosition(UserPositions: any) {
+ let Game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === UserPositions.roomId);
+ Game.sharedUserPosition(UserPositions)
+ }
+}
\ No newline at end of file
import {MapManagerInterface, MapManager} from "./MapManager";
+import {GameManagerInterface} from "./GameManager";
-export class GameScene extends Phaser.Scene {
+export interface GameSceneInterface extends Phaser.Scene {
+ RoomId : string;
+ sharedUserPosition(data : []): void;
+}
+export class GameScene extends Phaser.Scene implements GameSceneInterface{
private MapManager : MapManagerInterface;
+ RoomId : string;
- constructor() {
+ constructor(RoomId : string, GameManager : GameManagerInterface) {
super({
key: "GameScene"
});
+ this.RoomId = RoomId;
}
//hook preload scene
update(dt: number): void {
this.MapManager.update();
}
+
+ sharedUserPosition(data: []): void {
+ //TODO share position of all user
+ //console.log("sharedUserPosition", data);
+ }
}
import {CameraManager, CameraManagerInterface} from "./CameraManager";
-import {RESOLUTION} from "../Enum/EnvironmentVariable";
-import {Player} from "./Player";
+import {RESOLUTION} from "../../Enum/EnvironmentVariable";
+import {Player} from "../Player/Player";
+import {GameScene, GameSceneInterface} from "./GameScene";
export interface MapManagerInterface {
keyZ: Phaser.Input.Keyboard.Key;
Map: Phaser.Tilemaps.Tilemap;
Terrain: Phaser.Tilemaps.Tileset;
Camera: CameraManagerInterface;
+ Scene: GameSceneInterface;
update(): void;
}
export class MapManager implements MapManagerInterface{
Terrain : Phaser.Tilemaps.Tileset;
Camera: CameraManagerInterface;
CurrentPlayer: Player;
- Scene: Phaser.Scene;
+ Scene: GameSceneInterface;
Map: Phaser.Tilemaps.Tilemap;
startX = (window.innerWidth / 2) / RESOLUTION;
startY = (window.innerHeight / 2) / RESOLUTION;
- constructor(scene: Phaser.Scene){
+ constructor(scene: GameSceneInterface){
this.Scene = scene;
//initalise map
-import {MapManagerInterface} from "./MapManager";
-import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "./Player/Animation";
+import {MapManagerInterface} from "../Game/MapManager";
+import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "./Animation";
+import {Connexion} from "../../Connexion";
+import {GameSceneInterface} from "../Game/GameScene";
+import {ConnexionInstance} from "../Game/GameManager";
export class Player extends Phaser.GameObjects.Sprite{
MapManager : MapManagerInterface;
PlayerValue : string;
+ Connexion: Connexion;
constructor(
- Scene : Phaser.Scene,
+ Scene : GameSceneInterface,
x : number,
y : number,
MapManager: MapManagerInterface,
}
if(!haveMove){
playAnimation(this, PlayerAnimationNames.None);
+ }else{
+ this.sharePosition();
+ }
+ }
+
+ private sharePosition(){
+ if(ConnexionInstance) {
+ ConnexionInstance.sharePosition((this.scene as GameSceneInterface).RoomId, this.x, this.y);
}
}
import 'phaser';
import GameConfig = Phaser.Types.Core.GameConfig;
-import {GameScene} from "./Phaser/GameScene";
-import {Connexion} from "./Connexion";
+import {GameManager} from "./Phaser/Game/GameManager";
import {RESOLUTION} from "./Enum/EnvironmentVariable";
+let gameManager = new GameManager();
+
const config: GameConfig = {
title: "Office game",
width: window.innerWidth / RESOLUTION,
height: window.innerHeight / RESOLUTION,
parent: "game",
- scene: [GameScene],
+ scene: gameManager.GameScenes,
zoom: RESOLUTION,
};
window.addEventListener('resize', function (event) {
game.scale.resize(window.innerWidth / RESOLUTION, window.innerHeight / RESOLUTION);
});
-
-const connexion = new Connexion("test@gmail.com");