Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
9364cb3b12 | |||
60606947ab | |||
61c6b9dacb | |||
f3fdcba16a |
|
@ -3,6 +3,7 @@ import Jwt from "jsonwebtoken";
|
||||||
import {BAD_REQUEST, OK} from "http-status-codes";
|
import {BAD_REQUEST, OK} from "http-status-codes";
|
||||||
import {SECRET_KEY, ROOM} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..."
|
import {SECRET_KEY, ROOM} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..."
|
||||||
import { uuid } from 'uuidv4';
|
import { uuid } from 'uuidv4';
|
||||||
|
import {userManager} from "../Model/Users/UserManager";
|
||||||
|
|
||||||
export class AuthenticateController{
|
export class AuthenticateController{
|
||||||
App : Application;
|
App : Application;
|
||||||
|
@ -10,6 +11,7 @@ export class AuthenticateController{
|
||||||
constructor(App : Application) {
|
constructor(App : Application) {
|
||||||
this.App = App;
|
this.App = App;
|
||||||
this.login();
|
this.login();
|
||||||
|
this.getAllUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
//permit to login on application. Return token to connect on Websocket IO.
|
//permit to login on application. Return token to connect on Websocket IO.
|
||||||
|
@ -22,13 +24,16 @@ export class AuthenticateController{
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//TODO check user email for The Coding Machine game
|
//TODO check user email for The Coding Machine game
|
||||||
let userId = uuid();
|
let user = userManager.createUser(param.email);
|
||||||
let token = Jwt.sign({email: param.email, roomId: ROOM, userId: userId}, SECRET_KEY, {expiresIn: '24h'});
|
let token = Jwt.sign({email: user.email, userId: user.id}, SECRET_KEY, {expiresIn: '24h'});
|
||||||
return res.status(OK).send({
|
return res.status(OK).send(user);
|
||||||
token: token,
|
|
||||||
roomId: ROOM,
|
|
||||||
userId: userId
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllUsers(){
|
||||||
|
this.App.get("/users", (req: Request, res: Response) => {
|
||||||
|
let users = userManager.getAllUsers();
|
||||||
|
return res.status(OK).send(users);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ import Jwt, {JsonWebTokenError} from "jsonwebtoken";
|
||||||
import {SECRET_KEY} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..."
|
import {SECRET_KEY} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..."
|
||||||
import {ExtRooms, RefreshUserPositionFunction} from "../Model/Websocket/ExtRoom";
|
import {ExtRooms, RefreshUserPositionFunction} from "../Model/Websocket/ExtRoom";
|
||||||
import {ExtRoomsInterface} from "_Model/Websocket/ExtRoomsInterface";
|
import {ExtRoomsInterface} from "_Model/Websocket/ExtRoomsInterface";
|
||||||
|
import {userManager} from "../Model/Users/UserManager";
|
||||||
|
|
||||||
export class IoSocketController{
|
export class IoSocketController{
|
||||||
Io: socketIO.Server;
|
Io: socketIO.Server;
|
||||||
|
@ -112,23 +113,12 @@ export class IoSocketController{
|
||||||
**/
|
**/
|
||||||
seTimeOutInProgress : any = null;
|
seTimeOutInProgress : any = null;
|
||||||
shareUsersPosition(){
|
shareUsersPosition(){
|
||||||
if(this.seTimeOutInProgress){
|
//every 1/10 of seconds, emit the current list of events
|
||||||
clearTimeout(this.seTimeOutInProgress);
|
setInterval(() => {
|
||||||
|
let userEvents = userManager.getEventList();
|
||||||
|
if (userEvents.length) {
|
||||||
|
this.Io.emit('user-position', JSON.stringify(userEvents));
|
||||||
}
|
}
|
||||||
//send for each room, all data of position user
|
}, 100)
|
||||||
let arrayMap = (this.Io.sockets.adapter.rooms as ExtRooms).userPositionMapByRoom;
|
|
||||||
if(!arrayMap){
|
|
||||||
this.seTimeOutInProgress = setTimeout(() => {
|
|
||||||
this.shareUsersPosition();
|
|
||||||
}, 10);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
arrayMap.forEach((value : any) => {
|
|
||||||
let roomId = value[0];
|
|
||||||
this.Io.in(roomId).emit('user-position', JSON.stringify(arrayMap));
|
|
||||||
});
|
|
||||||
this.seTimeOutInProgress = setTimeout(() => {
|
|
||||||
this.shareUsersPosition();
|
|
||||||
}, 10);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
86
back/src/Model/Users/UserManager.ts
Normal file
86
back/src/Model/Users/UserManager.ts
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
import {uuid} from "uuidv4";
|
||||||
|
import {BehaviorSubject} from "rxjs";
|
||||||
|
|
||||||
|
export interface UserPosition {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class User {
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
position: UserPosition;
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
constructor(id: string, name: string, email: string, position: UserPosition) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.email = email;
|
||||||
|
this.position = position
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserPositionChangeEvent {
|
||||||
|
user: User;
|
||||||
|
deleted: boolean
|
||||||
|
added: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
class UserManager {
|
||||||
|
|
||||||
|
private usersList: Map<string, User> = new Map();
|
||||||
|
|
||||||
|
private eventsList: UserPositionChangeEvent[] = [];
|
||||||
|
|
||||||
|
//todo add more parameters
|
||||||
|
createUser(email: string): User {
|
||||||
|
let userId = uuid();
|
||||||
|
let user = new User(userId, "toto", email, {x: 0, y: 0});
|
||||||
|
|
||||||
|
this.usersList.set(userId, user);
|
||||||
|
this.eventsList.push({added: true, deleted: false, user})
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteUser(id: string): User {
|
||||||
|
let user = this.usersList.get(id);
|
||||||
|
if (!user) {
|
||||||
|
throw "Could not delete user with id "+id;
|
||||||
|
}
|
||||||
|
this.usersList.delete(id);
|
||||||
|
|
||||||
|
this.eventsList.push({added: false, deleted: true, user});
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateUserPosition(id: string, userPosition: UserPosition): User {
|
||||||
|
let user = this.usersList.get(id);
|
||||||
|
if (!user) {
|
||||||
|
throw "Could not find user with id "+id;
|
||||||
|
}
|
||||||
|
user.position = userPosition;
|
||||||
|
this.usersList.set(id, user);
|
||||||
|
|
||||||
|
this.eventsList.push({added: false, deleted: false, user});
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllUsers(): User[] {
|
||||||
|
let array = [];
|
||||||
|
for (const value of this.usersList.values()) {
|
||||||
|
array.push(value);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
//flush the list of events
|
||||||
|
getEventList(): UserPositionChangeEvent[] {
|
||||||
|
let events = this.eventsList;
|
||||||
|
this.eventsList = [];
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const userManager = new UserManager();
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,7 @@
|
||||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||||
|
|
||||||
/* Advanced Options */
|
/* Advanced Options */
|
||||||
|
"downlevelIteration": true,
|
||||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
front/dist/resources/objects/play_button.png
vendored
Normal file
BIN
front/dist/resources/objects/play_button.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 969 B |
BIN
front/dist/resources/objects/rockSprite.png
vendored
BIN
front/dist/resources/objects/rockSprite.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 3.6 KiB |
|
@ -17,6 +17,7 @@
|
||||||
"@types/axios": "^0.14.0",
|
"@types/axios": "^0.14.0",
|
||||||
"@types/socket.io-client": "^1.4.32",
|
"@types/socket.io-client": "^1.4.32",
|
||||||
"phaser": "^3.22.0",
|
"phaser": "^3.22.0",
|
||||||
|
"rxjs": "^6.5.5",
|
||||||
"socket.io-client": "^2.3.0"
|
"socket.io-client": "^2.3.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -1,212 +0,0 @@
|
||||||
import {GameManagerInterface} from "./Phaser/Game/GameManager";
|
|
||||||
|
|
||||||
const SocketIo = require('socket.io-client');
|
|
||||||
import Axios from "axios";
|
|
||||||
import {API_URL} from "./Enum/EnvironmentVariable";
|
|
||||||
|
|
||||||
class Message {
|
|
||||||
userId: string;
|
|
||||||
roomId: string;
|
|
||||||
|
|
||||||
constructor(userId : string, roomId : string) {
|
|
||||||
this.userId = userId;
|
|
||||||
this.roomId = roomId;
|
|
||||||
}
|
|
||||||
|
|
||||||
toJson() {
|
|
||||||
return {
|
|
||||||
userId: this.userId,
|
|
||||||
roomId: this.roomId,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PointInterface {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
direction : string;
|
|
||||||
toJson() : object;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Point implements PointInterface{
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
direction : string;
|
|
||||||
|
|
||||||
constructor(x : number, y : number, direction : string = "none") {
|
|
||||||
if(x === null || y === null){
|
|
||||||
throw Error("position x and y cannot be null");
|
|
||||||
}
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.direction = direction;
|
|
||||||
}
|
|
||||||
|
|
||||||
toJson(){
|
|
||||||
return {
|
|
||||||
x : this.x,
|
|
||||||
y: this.y,
|
|
||||||
direction: this.direction
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MessageUserPositionInterface {
|
|
||||||
userId: string;
|
|
||||||
roomId: string;
|
|
||||||
position: PointInterface;
|
|
||||||
}
|
|
||||||
class MessageUserPosition extends Message implements MessageUserPositionInterface{
|
|
||||||
position: PointInterface;
|
|
||||||
|
|
||||||
constructor(userId : string, roomId : string, point : Point) {
|
|
||||||
super(userId, roomId);
|
|
||||||
this.position = point;
|
|
||||||
}
|
|
||||||
|
|
||||||
toString() {
|
|
||||||
return JSON.stringify(
|
|
||||||
Object.assign(
|
|
||||||
super.toJson(),
|
|
||||||
{
|
|
||||||
position: this.position.toJson()
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ListMessageUserPositionInterface {
|
|
||||||
roomId : string;
|
|
||||||
listUsersPosition: Array<MessageUserPosition>;
|
|
||||||
}
|
|
||||||
class ListMessageUserPosition{
|
|
||||||
roomId : string;
|
|
||||||
listUsersPosition: Array<MessageUserPosition>;
|
|
||||||
|
|
||||||
constructor(roomId : string, data : any) {
|
|
||||||
this.roomId = roomId;
|
|
||||||
this.listUsersPosition = new Array<MessageUserPosition>();
|
|
||||||
data.forEach((userPosition: any) => {
|
|
||||||
this.listUsersPosition.push(new MessageUserPosition(
|
|
||||||
userPosition.userId,
|
|
||||||
userPosition.roomId,
|
|
||||||
new Point(
|
|
||||||
userPosition.position.x,
|
|
||||||
userPosition.position.y,
|
|
||||||
userPosition.position.direction
|
|
||||||
)
|
|
||||||
));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export interface ConnexionInterface {
|
|
||||||
socket : any;
|
|
||||||
token : string;
|
|
||||||
email : string;
|
|
||||||
userId: string;
|
|
||||||
startedRoom : string;
|
|
||||||
createConnexion() : Promise<any>;
|
|
||||||
joinARoom(roomId : string) : void;
|
|
||||||
sharePosition(roomId : string, x : number, y : number, direction : string) : void;
|
|
||||||
positionOfAllUser() : void;
|
|
||||||
}
|
|
||||||
export class Connexion implements ConnexionInterface{
|
|
||||||
socket : any;
|
|
||||||
token : string;
|
|
||||||
email : string;
|
|
||||||
userId: string;
|
|
||||||
startedRoom : string;
|
|
||||||
|
|
||||||
GameManager: GameManagerInterface;
|
|
||||||
|
|
||||||
constructor(email : string, GameManager: GameManagerInterface) {
|
|
||||||
this.email = email;
|
|
||||||
this.GameManager = GameManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
createConnexion() : Promise<ConnexionInterface>{
|
|
||||||
return Axios.post(`${API_URL}/login`, {email: this.email})
|
|
||||||
.then((res) => {
|
|
||||||
this.token = res.data.token;
|
|
||||||
this.startedRoom = res.data.roomId;
|
|
||||||
this.userId = res.data.userId;
|
|
||||||
|
|
||||||
this.socket = SocketIo(`${API_URL}`, {
|
|
||||||
query: {
|
|
||||||
token: this.token
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//join the room
|
|
||||||
this.joinARoom(this.startedRoom);
|
|
||||||
|
|
||||||
//share your first position
|
|
||||||
this.sharePosition(this.startedRoom, 0, 0);
|
|
||||||
|
|
||||||
this.positionOfAllUser();
|
|
||||||
|
|
||||||
this.errorMessage();
|
|
||||||
|
|
||||||
return this;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(err);
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permit to join a room
|
|
||||||
* @param roomId
|
|
||||||
*/
|
|
||||||
joinARoom(roomId : string) : void {
|
|
||||||
let messageUserPosition = new MessageUserPosition(this.userId, this.startedRoom, new Point(0, 0));
|
|
||||||
this.socket.emit('join-room', messageUserPosition.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param roomId
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param direction
|
|
||||||
*/
|
|
||||||
sharePosition(roomId : string, x : number, y : number, direction : string = "none") : void{
|
|
||||||
if(!this.socket){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let messageUserPosition = new MessageUserPosition(this.userId, roomId, new Point(x, y, direction));
|
|
||||||
this.socket.emit('user-position', messageUserPosition.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The data sent is an array with information for each user :
|
|
||||||
* [
|
|
||||||
* {
|
|
||||||
* userId: <string>,
|
|
||||||
* roomId: <string>,
|
|
||||||
* position: {
|
|
||||||
* x : <number>,
|
|
||||||
* y : <number>,
|
|
||||||
* direction: <string>
|
|
||||||
* }
|
|
||||||
* },
|
|
||||||
* ...
|
|
||||||
* ]
|
|
||||||
**/
|
|
||||||
positionOfAllUser() : void {
|
|
||||||
this.socket.on("user-position", (message: string) => {
|
|
||||||
let dataList = JSON.parse(message);
|
|
||||||
dataList.forEach((UserPositions: any) => {
|
|
||||||
let listMessageUserPosition = new ListMessageUserPosition(UserPositions[0], UserPositions[1]);
|
|
||||||
this.GameManager.shareUserPosition(listMessageUserPosition);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
errorMessage() : void {
|
|
||||||
this.socket.on('message-error', (message : string) => {
|
|
||||||
console.error("message-error", message);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
17
front/src/Connexion/ConnectedUser.ts
Normal file
17
front/src/Connexion/ConnectedUser.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
export class ConnectedUser {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
roomId: string
|
||||||
|
|
||||||
|
constructor( id: string,name: string, email: string, x: number, y: number) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.email = email;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.roomId = "THECODINGMACHINE";
|
||||||
|
}
|
||||||
|
}
|
37
front/src/Connexion/ConnexionManager.ts
Normal file
37
front/src/Connexion/ConnexionManager.ts
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import {ConnectedUser} from "./ConnectedUser";
|
||||||
|
|
||||||
|
const SocketIo = require('socket.io-client');
|
||||||
|
import Axios from "axios";
|
||||||
|
import {API_URL} from "../Enum/EnvironmentVariable";
|
||||||
|
|
||||||
|
class ConnexionManager {
|
||||||
|
socket : any;
|
||||||
|
token : string;
|
||||||
|
email : string;
|
||||||
|
userId: string;
|
||||||
|
startedRoom : string;
|
||||||
|
|
||||||
|
|
||||||
|
async createConnexion(email : string) : Promise<{connectedUser: ConnectedUser, socket: any}>{
|
||||||
|
let res = await Axios.post(`${API_URL}/login`, {email});
|
||||||
|
this.token = res.data.token;
|
||||||
|
this.startedRoom = res.data.roomId;
|
||||||
|
this.userId = res.data.userId;
|
||||||
|
let connectedUser = new ConnectedUser(res.data.userId, res.data.name, res.data.email, 0, 0);
|
||||||
|
|
||||||
|
let socket = SocketIo(`${API_URL}`, {
|
||||||
|
query: {
|
||||||
|
token: this.token
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return {connectedUser, socket};
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllUsers() {
|
||||||
|
return Axios.post(`${API_URL}/users`).then(res => {
|
||||||
|
return res.data.map((user:any) => new ConnectedUser(user.id, user.name, user.email, user.x, user.y))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const connexionManager = new ConnexionManager();
|
73
front/src/Connexion/GameManager.ts
Normal file
73
front/src/Connexion/GameManager.ts
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
import {ConnectedUser} from "./ConnectedUser";
|
||||||
|
import {BehaviorSubject} from "rxjs";
|
||||||
|
import {connexionManager} from "./ConnexionManager";
|
||||||
|
|
||||||
|
export enum StatusGameManagerEnum {
|
||||||
|
IN_PROGRESS = 1,
|
||||||
|
CURRENT_USER_CREATED = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Position{
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConnectedUserPositionData{
|
||||||
|
userId: string;
|
||||||
|
position: Position;
|
||||||
|
|
||||||
|
constructor(userId: string, position: Position) {
|
||||||
|
this.userId = userId;
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserPositionChangeEvent {
|
||||||
|
userId: string;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
deleted: boolean
|
||||||
|
added: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GameManager {
|
||||||
|
status: StatusGameManagerEnum;
|
||||||
|
private connectedUser: ConnectedUser;
|
||||||
|
private socket: any;
|
||||||
|
private connectedUserPosition = new BehaviorSubject({x: 0, y: 0});
|
||||||
|
public otherUserPositionsChange: BehaviorSubject<UserPositionChangeEvent[]> = new BehaviorSubject([]);
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.status = StatusGameManagerEnum.IN_PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async login(email:string) {
|
||||||
|
let response = await connexionManager.createConnexion(email);
|
||||||
|
this.connectedUser = response.connectedUser;
|
||||||
|
this.socket = response.socket;
|
||||||
|
|
||||||
|
this.socket.on('message-error', (message : string) => {
|
||||||
|
console.error("message-error", message);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
this.socket.on("user-position", (message: string) => {
|
||||||
|
let eventList = JSON.parse(message);
|
||||||
|
this.otherUserPositionsChange.next(eventList);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.connectedUserPosition.subscribe(position => {
|
||||||
|
let data = new ConnectedUserPositionData(this.connectedUser.id, position);
|
||||||
|
this.socket.emit('user-position', JSON.stringify(data));
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
updateConnectedUserPosition(x: number, y: number) {
|
||||||
|
this.connectedUserPosition.next({x, y});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const gameManager = new GameManager();
|
|
@ -18,6 +18,17 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
|
||||||
this.setOffset(8, 16);
|
this.setOffset(8, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initAnimation(): void {
|
||||||
|
getPlayerAnimations().forEach(d => {
|
||||||
|
this.scene.anims.create({
|
||||||
|
key: d.key,
|
||||||
|
frames: this.scene.anims.generateFrameNumbers(d.frameModel, {start: d.frameStart, end: d.frameEnd}),
|
||||||
|
frameRate: d.frameRate,
|
||||||
|
repeat: d.repeat
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
move(x: number, y: number){
|
move(x: number, y: number){
|
||||||
|
|
||||||
this.setVelocity(x, y);
|
this.setVelocity(x, y);
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
import {GameSceneInterface, GameScene} from "./GameScene";
|
|
||||||
import {ROOM} from "../../Enum/EnvironmentVariable"
|
|
||||||
import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion";
|
|
||||||
|
|
||||||
export enum StatusGameManagerEnum {
|
|
||||||
IN_PROGRESS = 1,
|
|
||||||
CURRENT_USER_CREATED = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
export let ConnexionInstance : ConnexionInterface;
|
|
||||||
|
|
||||||
export interface GameManagerInterface {
|
|
||||||
GameScenes: Array<GameSceneInterface>;
|
|
||||||
status : number;
|
|
||||||
createCurrentPlayer() : void;
|
|
||||||
shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void;
|
|
||||||
}
|
|
||||||
export class GameManager implements GameManagerInterface {
|
|
||||||
GameScenes: Array<GameSceneInterface> = [];
|
|
||||||
status: number;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.status = StatusGameManagerEnum.IN_PROGRESS;
|
|
||||||
ConnexionInstance = new Connexion("test@gmail.com", this);
|
|
||||||
}
|
|
||||||
|
|
||||||
createGame(){
|
|
||||||
return ConnexionInstance.createConnexion().then(() => {
|
|
||||||
this.configureGame();
|
|
||||||
/** TODO add loader in the page **/
|
|
||||||
}).catch((err) => {
|
|
||||||
console.error(err);
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* permit to config rooms
|
|
||||||
*/
|
|
||||||
configureGame() {
|
|
||||||
ROOM.forEach((roomId) => {
|
|
||||||
let newGame = new GameScene(roomId, this);
|
|
||||||
this.GameScenes.push((newGame as GameSceneInterface));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permit to create player in started room
|
|
||||||
* @param RoomId
|
|
||||||
* @param UserId
|
|
||||||
*/
|
|
||||||
createCurrentPlayer(): void {
|
|
||||||
//Get started room send by the backend
|
|
||||||
let game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === ConnexionInstance.startedRoom);
|
|
||||||
game.createCurrentPlayer(ConnexionInstance.userId);
|
|
||||||
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Share position in game
|
|
||||||
* @param ListMessageUserPosition
|
|
||||||
*/
|
|
||||||
shareUserPosition(ListMessageUserPosition: ListMessageUserPositionInterface): void {
|
|
||||||
if (this.status === StatusGameManagerEnum.IN_PROGRESS) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
let Game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === ListMessageUserPosition.roomId);
|
|
||||||
if (!Game) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Game.shareUserPosition(ListMessageUserPosition.listUsersPosition)
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +1,20 @@
|
||||||
import {GameManagerInterface, StatusGameManagerEnum} from "./GameManager";
|
import {CurrentGamerInterface, Player} from "../Player/Player";
|
||||||
import {MessageUserPositionInterface} from "../../Connexion";
|
|
||||||
import {CurrentGamerInterface, GamerInterface, Player} from "../Player/Player";
|
|
||||||
import {DEBUG_MODE, RESOLUTION, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
|
import {DEBUG_MODE, RESOLUTION, 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";
|
||||||
import {cypressAsserter} from "../../Cypress/CypressAsserter";
|
import {cypressAsserter} from "../../Cypress/CypressAsserter";
|
||||||
|
import {NonPlayer} from "../NonPlayer/NonPlayer";
|
||||||
|
import {ConnectedUser} from "../../Connexion/ConnectedUser";
|
||||||
|
import {gameManager, UserPositionChangeEvent} from "../../Connexion/GameManager";
|
||||||
|
import {connexionManager} from "../../Connexion/ConnexionManager";
|
||||||
|
|
||||||
|
export const GameSceneName = "GameScene";
|
||||||
export enum Textures {
|
export enum Textures {
|
||||||
Rock = 'rock',
|
|
||||||
Player = 'playerModel',
|
Player = 'playerModel',
|
||||||
Map = 'map'
|
Map = 'map'
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GameSceneInterface extends Phaser.Scene {
|
export class GameScene extends Phaser.Scene {
|
||||||
RoomId : string;
|
|
||||||
Map: Phaser.Tilemaps.Tilemap;
|
|
||||||
createCurrentPlayer(UserId : string) : void;
|
|
||||||
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void;
|
|
||||||
}
|
|
||||||
export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|
||||||
GameManager : GameManagerInterface;
|
|
||||||
RoomId : string;
|
RoomId : string;
|
||||||
Terrains : Array<Phaser.Tilemaps.Tileset>;
|
Terrains : Array<Phaser.Tilemaps.Tileset>;
|
||||||
CurrentPlayer: CurrentGamerInterface;
|
CurrentPlayer: CurrentGamerInterface;
|
||||||
|
@ -32,12 +27,11 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
||||||
startY = (window.innerHeight / 2) / RESOLUTION;
|
startY = (window.innerHeight / 2) / RESOLUTION;
|
||||||
|
|
||||||
|
|
||||||
constructor(RoomId : string, GameManager : GameManagerInterface) {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
key: "GameScene"
|
key: GameSceneName
|
||||||
});
|
});
|
||||||
this.RoomId = RoomId;
|
this.RoomId = connexionManager.startedRoom;
|
||||||
this.GameManager = GameManager;
|
|
||||||
this.Terrains = [];
|
this.Terrains = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +49,6 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
this.load.tilemapTiledJSON(Textures.Map, mapUrl);
|
this.load.tilemapTiledJSON(Textures.Map, mapUrl);
|
||||||
this.load.image(Textures.Rock, 'resources/objects/rockSprite.png');
|
|
||||||
this.load.spritesheet(Textures.Player,
|
this.load.spritesheet(Textures.Player,
|
||||||
'resources/characters/pipoya/Male 01-1.png',
|
'resources/characters/pipoya/Male 01-1.png',
|
||||||
{ frameWidth: 32, frameHeight: 32 }
|
{ frameWidth: 32, frameHeight: 32 }
|
||||||
|
@ -96,7 +89,6 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
||||||
|
|
||||||
//add entities
|
//add entities
|
||||||
this.Objects = new Array<Phaser.Physics.Arcade.Sprite>();
|
this.Objects = new Array<Phaser.Physics.Arcade.Sprite>();
|
||||||
this.addSpite(this.physics.add.sprite(200, 400, Textures.Rock, 26));
|
|
||||||
|
|
||||||
//init event click
|
//init event click
|
||||||
this.EventToClickOnTile();
|
this.EventToClickOnTile();
|
||||||
|
@ -105,7 +97,9 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
||||||
this.MapPlayers = this.physics.add.group({ immovable: true });
|
this.MapPlayers = this.physics.add.group({ immovable: true });
|
||||||
|
|
||||||
//notify game manager can to create currentUser in map
|
//notify game manager can to create currentUser in map
|
||||||
this.GameManager.createCurrentPlayer();
|
this.createCurrentPlayer();
|
||||||
|
|
||||||
|
gameManager.otherUserPositionsChange.subscribe((list:any) => this.updateOrCreateMapPlayer(list))
|
||||||
|
|
||||||
|
|
||||||
//initialise camera
|
//initialise camera
|
||||||
|
@ -155,10 +149,11 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
createCurrentPlayer(UserId : string){
|
createCurrentPlayer(){
|
||||||
//initialise player
|
//initialise player
|
||||||
this.CurrentPlayer = new Player(
|
this.CurrentPlayer = new Player(
|
||||||
UserId,
|
connexionManager.userId,
|
||||||
|
connexionManager.email,
|
||||||
this,
|
this,
|
||||||
this.startX,
|
this.startX,
|
||||||
this.startY,
|
this.startY,
|
||||||
|
@ -186,61 +181,44 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
||||||
this.CurrentPlayer.moveUser();
|
this.CurrentPlayer.moveUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Share position in scene
|
|
||||||
* @param UsersPosition
|
|
||||||
*/
|
|
||||||
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void {
|
|
||||||
this.updateOrCreateMapPlayer(UsersPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new player and clean the player on the map
|
* Create new player and clean the player on the map
|
||||||
* @param UsersPosition
|
* @param UsersPosition
|
||||||
*/
|
*/
|
||||||
updateOrCreateMapPlayer(UsersPosition : Array<MessageUserPositionInterface>){
|
updateOrCreateMapPlayer(userEvents : UserPositionChangeEvent[]){
|
||||||
if(!this.CurrentPlayer){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//add or create new user
|
//add or create new user
|
||||||
UsersPosition.forEach((userPosition : MessageUserPositionInterface) => {
|
userEvents.forEach(userEvent => {
|
||||||
if(userPosition.userId === this.CurrentPlayer.userId){
|
let player = this.findPlayerInMap(userEvent.userId);
|
||||||
return;
|
|
||||||
}
|
|
||||||
let player = this.findPlayerInMap(userPosition.userId);
|
|
||||||
if(!player){
|
if(!player){
|
||||||
this.addPlayer(userPosition);
|
this.addPlayer(userEvent);
|
||||||
}else{
|
}else{
|
||||||
player.updatePosition(userPosition);
|
if (userEvent.deleted) {
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//clean map
|
|
||||||
this.MapPlayers.getChildren().forEach((player: GamerInterface) => {
|
|
||||||
if(UsersPosition.find((message : MessageUserPositionInterface) => message.userId === player.userId)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
player.destroy();
|
player.destroy();
|
||||||
this.MapPlayers.remove(player);
|
} else {
|
||||||
});
|
player.updatePosition(userEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private findPlayerInMap(UserId : string) : GamerInterface | null{
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private findPlayerInMap(UserId : string) : any | null{
|
||||||
let player = this.MapPlayers.getChildren().find((player: Player) => UserId === player.userId);
|
let player = this.MapPlayers.getChildren().find((player: Player) => UserId === player.userId);
|
||||||
if(!player){
|
if(!player){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (player as GamerInterface);
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new player
|
* Create new player
|
||||||
* @param MessageUserPosition
|
* @param MessageUserPosition
|
||||||
*/
|
*/
|
||||||
addPlayer(MessageUserPosition : MessageUserPositionInterface){
|
addPlayer(MessageUserPosition : any){
|
||||||
//initialise player
|
//initialise player
|
||||||
let player = new Player(
|
let player = new NonPlayer(
|
||||||
MessageUserPosition.userId,
|
MessageUserPosition.userId,
|
||||||
this,
|
this,
|
||||||
MessageUserPosition.position.x,
|
MessageUserPosition.position.x,
|
||||||
|
@ -251,8 +229,9 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
||||||
player.updatePosition(MessageUserPosition);
|
player.updatePosition(MessageUserPosition);
|
||||||
|
|
||||||
//init colision
|
//init colision
|
||||||
this.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
|
this.physics.add.overlap(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: any) => {
|
||||||
CurrentPlayer.say("Hello, how are you ? ");
|
CurrentPlayer.say("Salut ça va?");
|
||||||
|
MapPlayer.say("Oui et toi?");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
52
front/src/Phaser/Login/LogincScene.ts
Normal file
52
front/src/Phaser/Login/LogincScene.ts
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
import KeyboardKeydownCallback = Phaser.Types.Input.Keyboard.KeyboardKeydownCallback;
|
||||||
|
import {GameSceneName} from "../Game/GameScene";
|
||||||
|
import {connexionManager} from "../../Connexion/ConnexionManager";
|
||||||
|
|
||||||
|
export const LoginSceneName = "LoginScene";
|
||||||
|
enum LoginTextures {
|
||||||
|
playButton = "play_button",
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LogincScene extends Phaser.Scene {
|
||||||
|
private playButton: Phaser.GameObjects.Image;
|
||||||
|
private textEntry: Phaser.GameObjects.Text;
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
key: LoginSceneName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
preload() {
|
||||||
|
this.load.image(LoginTextures.playButton, "resources/objects/play_button.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
create() {
|
||||||
|
this.add.text(10, 10, 'Enter your email:', { font: '32px Courier', fill: '#ffffff' });
|
||||||
|
|
||||||
|
this.textEntry = this.add.text(10, 50, '', { font: '32px Courier', fill: '#ffff00' });
|
||||||
|
let keySpace = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE);
|
||||||
|
let keyBackspace = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.BACKSPACE);
|
||||||
|
this.input.keyboard.on('keydown', (event: any) => {
|
||||||
|
if (event.keyCode === 8 && this.textEntry.text.length > 0) {
|
||||||
|
this.textEntry.text = this.textEntry.text.substr(0, this.textEntry.text.length - 1);
|
||||||
|
} else if (event.keyCode === 32 || (event.keyCode >= 48 && event.keyCode < 90)) {
|
||||||
|
this.textEntry.text += event.key;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.playButton = this.add.image(this.game.renderer.width / 2, this.game.renderer.height / 2, LoginTextures.playButton).setDepth(1);
|
||||||
|
this.playButton.setInteractive();
|
||||||
|
this.playButton.on("pointerup", this.login.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
update(time: number, delta: number): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async login() {
|
||||||
|
let email = this.textEntry.text;
|
||||||
|
if (!email) return;
|
||||||
|
await connexionManager.createConnexion("a.poly@thecodingmachine.com");
|
||||||
|
this.scene.start(GameSceneName);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,27 +2,41 @@ import {PlayableCaracter} from "../Entity/PlayableCaracter";
|
||||||
import {Textures} from "../Game/GameScene";
|
import {Textures} from "../Game/GameScene";
|
||||||
import {UserInputEvent} from "../UserInput/UserInputManager";
|
import {UserInputEvent} from "../UserInput/UserInputManager";
|
||||||
import {Player} from "../Player/Player";
|
import {Player} from "../Player/Player";
|
||||||
import {MessageUserPositionInterface} from "../../Connexion";
|
import {getPlayerAnimations, playAnimation} from "../Player/Animation";
|
||||||
import {playAnimation} from "../Player/Animation";
|
|
||||||
|
|
||||||
export class NonPlayer extends PlayableCaracter {
|
export class NonPlayer extends PlayableCaracter {
|
||||||
|
|
||||||
isFleeing: boolean = false;
|
isFleeing: boolean = false;
|
||||||
fleeingDirection:any = null //todo create a vector class
|
fleeingDirection:any = null
|
||||||
|
private userId: string;
|
||||||
|
|
||||||
constructor(scene: Phaser.Scene, x: number, y: number) {
|
//todo create a vector class
|
||||||
|
|
||||||
|
constructor(userId:string, scene: Phaser.Scene, x: number, y: number) {
|
||||||
super(scene, x, y, Textures.Player, 1);
|
super(scene, x, y, Textures.Player, 1);
|
||||||
|
this.userId = userId
|
||||||
this.setSize(32, 32); //edit the hitbox to better match the caracter model
|
this.setSize(32, 32); //edit the hitbox to better match the caracter model
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
updatePosition(MessageUserPosition : MessageUserPositionInterface){
|
updatePosition(MessageUserPosition:any){
|
||||||
playAnimation(this, MessageUserPosition.position.direction);
|
playAnimation(this, MessageUserPosition.position.direction);
|
||||||
this.setX(MessageUserPosition.position.x);
|
this.setX(MessageUserPosition.position.x);
|
||||||
this.setY(MessageUserPosition.position.y);
|
this.setY(MessageUserPosition.position.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
fleeFrom(player:Player) {
|
initAnimation(): void {
|
||||||
|
getPlayerAnimations().forEach(d => {
|
||||||
|
this.scene.anims.create({
|
||||||
|
key: d.key,
|
||||||
|
frames: this.scene.anims.generateFrameNumbers(d.frameModel, {start: d.frameStart, end: d.frameEnd}),
|
||||||
|
frameRate: d.frameRate,
|
||||||
|
repeat: d.repeat
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/*fleeFrom(player:Player) {
|
||||||
if (this.isFleeing) return;
|
if (this.isFleeing) return;
|
||||||
this.say("Don't touch me!");
|
this.say("Don't touch me!");
|
||||||
this.isFleeing = true;
|
this.isFleeing = true;
|
||||||
|
@ -36,5 +50,5 @@ export class NonPlayer extends PlayableCaracter {
|
||||||
let vectorX = this.x - player.x;
|
let vectorX = this.x - player.x;
|
||||||
let vectorY = this.y - player.y;
|
let vectorY = this.y - player.y;
|
||||||
this.fleeingDirection = {x: vectorX, y: vectorY}
|
this.fleeingDirection = {x: vectorX, y: vectorY}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
|
@ -1,9 +1,8 @@
|
||||||
import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "./Animation";
|
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 {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
|
||||||
import {PlayableCaracter} from "../Entity/PlayableCaracter";
|
import {PlayableCaracter} from "../Entity/PlayableCaracter";
|
||||||
|
import {gameManager} from "../../Connexion/GameManager";
|
||||||
|
import {Textures} from "../Game/GameScene";
|
||||||
|
|
||||||
export interface CurrentGamerInterface extends PlayableCaracter{
|
export interface CurrentGamerInterface extends PlayableCaracter{
|
||||||
userId : string;
|
userId : string;
|
||||||
|
@ -13,22 +12,16 @@ export interface CurrentGamerInterface extends PlayableCaracter{
|
||||||
say(text : string) : void;
|
say(text : string) : void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GamerInterface extends PlayableCaracter{
|
export class Player extends PlayableCaracter implements CurrentGamerInterface {
|
||||||
userId : string;
|
|
||||||
PlayerValue : string;
|
|
||||||
initAnimation() : void;
|
|
||||||
updatePosition(MessageUserPosition : MessageUserPositionInterface) : void;
|
|
||||||
say(text : string) : void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Player extends PlayableCaracter implements CurrentGamerInterface, GamerInterface {
|
|
||||||
userId: string;
|
userId: string;
|
||||||
PlayerValue: string;
|
PlayerValue: string;
|
||||||
userInputManager: UserInputManager;
|
userInputManager: UserInputManager;
|
||||||
|
private email: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
userId: string,
|
userId: string,
|
||||||
Scene: GameSceneInterface,
|
email: string,
|
||||||
|
Scene: Phaser.Scene,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
PlayerValue: string = Textures.Player
|
PlayerValue: string = Textures.Player
|
||||||
|
@ -40,21 +33,12 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
||||||
|
|
||||||
//set data
|
//set data
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
|
this.email = email;
|
||||||
this.PlayerValue = PlayerValue;
|
this.PlayerValue = PlayerValue;
|
||||||
|
|
||||||
//the current player model should be push away by other players to prevent conflict
|
//the current player model should be push away by other players to prevent conflict
|
||||||
this.setImmovable(false);
|
this.setImmovable(false);
|
||||||
}
|
this.say("My email is "+this.email)
|
||||||
|
|
||||||
initAnimation(): void {
|
|
||||||
getPlayerAnimations().forEach(d => {
|
|
||||||
this.scene.anims.create({
|
|
||||||
key: d.key,
|
|
||||||
frames: this.scene.anims.generateFrameNumbers(d.frameModel, {start: d.frameStart, end: d.frameEnd}),
|
|
||||||
frameRate: d.frameRate,
|
|
||||||
repeat: d.repeat
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
moveUser(): void {
|
moveUser(): void {
|
||||||
|
@ -89,18 +73,7 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
||||||
direction = PlayerAnimationNames.None;
|
direction = PlayerAnimationNames.None;
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
this.sharePosition(direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
private sharePosition(direction: string) {
|
gameManager.updateConnectedUserPosition(this.x, this.y);
|
||||||
if (ConnexionInstance) {
|
|
||||||
ConnexionInstance.sharePosition((this.scene as GameSceneInterface).RoomId, this.x, this.y, direction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePosition(MessageUserPosition: MessageUserPositionInterface) {
|
|
||||||
playAnimation(this, MessageUserPosition.position.direction);
|
|
||||||
this.setX(MessageUserPosition.position.x);
|
|
||||||
this.setY(MessageUserPosition.position.y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
import Map = Phaser.Structs.Map;
|
import Map = Phaser.Structs.Map;
|
||||||
import {GameSceneInterface} from "../Game/GameScene";
|
|
||||||
|
|
||||||
interface UserInputManagerDatum {
|
interface UserInputManagerDatum {
|
||||||
keyCode: number;
|
keyCode: number;
|
||||||
|
@ -50,7 +49,7 @@ export class UserInputManager {
|
||||||
{keyCode: Phaser.Input.Keyboard.KeyCodes.F, event: UserInputEvent.Shout, keyInstance: null},
|
{keyCode: Phaser.Input.Keyboard.KeyCodes.F, event: UserInputEvent.Shout, keyInstance: null},
|
||||||
];
|
];
|
||||||
|
|
||||||
constructor(Scene : GameSceneInterface) {
|
constructor(Scene : Phaser.Scene) {
|
||||||
this.KeysCode.forEach(d => {
|
this.KeysCode.forEach(d => {
|
||||||
d.keyInstance = Scene.input.keyboard.addKey(d.keyCode);
|
d.keyInstance = Scene.input.keyboard.addKey(d.keyCode);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
import 'phaser';
|
import 'phaser';
|
||||||
import GameConfig = Phaser.Types.Core.GameConfig;
|
import GameConfig = Phaser.Types.Core.GameConfig;
|
||||||
import {GameManager} from "./Phaser/Game/GameManager";
|
|
||||||
import {DEBUG_MODE, RESOLUTION} from "./Enum/EnvironmentVariable";
|
import {DEBUG_MODE, RESOLUTION} from "./Enum/EnvironmentVariable";
|
||||||
import {cypressAsserter} from "./Cypress/CypressAsserter";
|
import {cypressAsserter} from "./Cypress/CypressAsserter";
|
||||||
|
import {LogincScene} from "./Phaser/Login/LogincScene";
|
||||||
let gameManager = new GameManager();
|
import {GameScene} from "./Phaser/Game/GameScene";
|
||||||
|
|
||||||
const config: GameConfig = {
|
const config: GameConfig = {
|
||||||
title: "Office game",
|
title: "Office game",
|
||||||
width: window.innerWidth / RESOLUTION,
|
width: window.innerWidth / RESOLUTION,
|
||||||
height: window.innerHeight / RESOLUTION,
|
height: window.innerHeight / RESOLUTION,
|
||||||
parent: "game",
|
parent: "game",
|
||||||
scene: gameManager.GameScenes,
|
scene: [LogincScene, GameScene],
|
||||||
zoom: RESOLUTION,
|
zoom: RESOLUTION,
|
||||||
physics: {
|
physics: {
|
||||||
default: "arcade",
|
default: "arcade",
|
||||||
|
@ -23,10 +22,8 @@ const config: GameConfig = {
|
||||||
|
|
||||||
cypressAsserter.gameStarted();
|
cypressAsserter.gameStarted();
|
||||||
|
|
||||||
gameManager.createGame().then(() => {
|
let game = new Phaser.Game(config);
|
||||||
let game = new Phaser.Game(config);
|
|
||||||
|
|
||||||
window.addEventListener('resize', function (event) {
|
window.addEventListener('resize', function (event) {
|
||||||
game.scale.resize(window.innerWidth / RESOLUTION, window.innerHeight / RESOLUTION);
|
game.scale.resize(window.innerWidth / RESOLUTION, window.innerHeight / RESOLUTION);
|
||||||
});
|
|
||||||
});
|
});
|
|
@ -7,6 +7,7 @@
|
||||||
"module": "es6",
|
"module": "es6",
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
|
"downlevelIteration": true,
|
||||||
"allowJs": true
|
"allowJs": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3278,7 +3278,7 @@ run-queue@^1.0.0, run-queue@^1.0.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
aproba "^1.1.1"
|
aproba "^1.1.1"
|
||||||
|
|
||||||
rxjs@^6.5.3:
|
rxjs@^6.5.3, rxjs@^6.5.5:
|
||||||
version "6.5.5"
|
version "6.5.5"
|
||||||
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.5.tgz#c5c884e3094c8cfee31bf27eb87e54ccfc87f9ec"
|
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.5.tgz#c5c884e3094c8cfee31bf27eb87e54ccfc87f9ec"
|
||||||
integrity sha512-WfQI+1gohdf0Dai/Bbmk5L5ItH5tYqm3ki2c5GdWhKjalzjg93N3avFjVStyZZz+A2Em+ZxKH5bNghw9UeylGQ==
|
integrity sha512-WfQI+1gohdf0Dai/Bbmk5L5ItH5tYqm3ki2c5GdWhKjalzjg93N3avFjVStyZZz+A2Em+ZxKH5bNghw9UeylGQ==
|
||||||
|
|
Loading…
Reference in a new issue