Send event and play animation with user frame
This commit is contained in:
parent
b51ce51847
commit
5a6415607d
@ -216,6 +216,7 @@ export class IoSocketController {
|
|||||||
socket.roomId = message.roomId;
|
socket.roomId = message.roomId;
|
||||||
socket.userId = message.userId;
|
socket.userId = message.userId;
|
||||||
socket.name = message.name;
|
socket.name = message.name;
|
||||||
|
socket.frame = message.frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshUserPosition() {
|
refreshUserPosition() {
|
||||||
|
@ -7,5 +7,6 @@ export interface ExSocketInterface extends Socket {
|
|||||||
webRtcRoomId: string;
|
webRtcRoomId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
frame: string;
|
||||||
position: PointInterface;
|
position: PointInterface;
|
||||||
}
|
}
|
@ -25,6 +25,7 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server
|
|||||||
roomId: socket.roomId,
|
roomId: socket.roomId,
|
||||||
position: socket.position,
|
position: socket.position,
|
||||||
name: socket.name,
|
name: socket.name,
|
||||||
|
frame: socket.frame,
|
||||||
};
|
};
|
||||||
let dataArray = <any>[];
|
let dataArray = <any>[];
|
||||||
if (mapPositionUserByRoom.get(data.roomId)) {
|
if (mapPositionUserByRoom.get(data.roomId)) {
|
||||||
|
@ -2,6 +2,7 @@ export class Message {
|
|||||||
userId: string;
|
userId: string;
|
||||||
roomId: string;
|
roomId: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
frame: string;
|
||||||
|
|
||||||
constructor(data: any) {
|
constructor(data: any) {
|
||||||
if (!data.userId || !data.roomId) {
|
if (!data.userId || !data.roomId) {
|
||||||
@ -10,13 +11,15 @@ export class Message {
|
|||||||
this.userId = data.userId;
|
this.userId = data.userId;
|
||||||
this.roomId = data.roomId;
|
this.roomId = data.roomId;
|
||||||
this.name = data.name;
|
this.name = data.name;
|
||||||
|
this.frame = data.frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson() {
|
toJson() {
|
||||||
return {
|
return {
|
||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
roomId: this.roomId,
|
roomId: this.roomId,
|
||||||
name: this.name
|
name: this.name,
|
||||||
|
frame: this.frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,37 +3,38 @@ import {Message} from "../src/Model/Websocket/Message";
|
|||||||
|
|
||||||
describe("Message Model", () => {
|
describe("Message Model", () => {
|
||||||
it("should find userId and roomId", () => {
|
it("should find userId and roomId", () => {
|
||||||
let message = {userId: "test1", roomId: "test2", name: "foo"};
|
let message = {userId: "test1", roomId: "test2", name: "foo", frame: "user"};
|
||||||
let messageObject = new Message(message);
|
let messageObject = new Message(message);
|
||||||
expect(messageObject.userId).toBe("test1");
|
expect(messageObject.userId).toBe("test1");
|
||||||
expect(messageObject.roomId).toBe("test2");
|
expect(messageObject.roomId).toBe("test2");
|
||||||
expect(messageObject.name).toBe("foo");
|
expect(messageObject.name).toBe("foo");
|
||||||
|
expect(messageObject.name).toBe("user");
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should expose a toJson method", () => {
|
it("should expose a toJson method", () => {
|
||||||
let message = {userId: "test1", roomId: "test2", name: "foo"};
|
let message = {userId: "test1", roomId: "test2", name: "foo"};
|
||||||
let messageObject = new Message(message);
|
let messageObject = new Message(message);
|
||||||
expect(messageObject.toJson()).toEqual({userId: "test1", roomId: "test2", name: "foo"});
|
expect(messageObject.toJson()).toEqual({userId: "test1", roomId: "test2", name: "foo", frame: "user"});
|
||||||
})
|
});
|
||||||
|
|
||||||
it("should find throw error when no userId", () => {
|
it("should find throw error when no userId", () => {
|
||||||
let message = {roomId: "test2"};
|
let message = {roomId: "test2"};
|
||||||
expect(() => {
|
expect(() => {
|
||||||
let messageObject = new Message(message);
|
let messageObject = new Message(message);
|
||||||
}).toThrow(new Error("userId or roomId cannot be null"));
|
}).toThrow(new Error("userId or roomId cannot be null"));
|
||||||
})
|
});
|
||||||
|
|
||||||
it("should find throw error when no roomId", () => {
|
it("should find throw error when no roomId", () => {
|
||||||
let message = {userId: "test1"};
|
let message = {userId: "test1"};
|
||||||
expect(() => {
|
expect(() => {
|
||||||
let messageObject = new Message(message);
|
let messageObject = new Message(message);
|
||||||
}).toThrow(new Error("userId or roomId cannot be null"));
|
}).toThrow(new Error("userId or roomId cannot be null"));
|
||||||
})
|
});
|
||||||
|
|
||||||
it("should find throw error when no roomId", () => {
|
it("should find throw error when no roomId", () => {
|
||||||
let message = {name: "foo"};
|
let message = {name: "foo"};
|
||||||
expect(() => {
|
expect(() => {
|
||||||
let messageObject = new Message(message);
|
let messageObject = new Message(message);
|
||||||
}).toThrow(new Error("userId or roomId cannot be null"));
|
}).toThrow(new Error("userId or roomId cannot be null"));
|
||||||
})
|
});
|
||||||
})
|
})
|
@ -18,18 +18,21 @@ class Message {
|
|||||||
userId: string;
|
userId: string;
|
||||||
roomId: string;
|
roomId: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
frame: string;
|
||||||
|
|
||||||
constructor(userId : string, roomId : string, name: string) {
|
constructor(userId : string, roomId : string, name: string, frame: string) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.roomId = roomId;
|
this.roomId = roomId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.frame = frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson() {
|
toJson() {
|
||||||
return {
|
return {
|
||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
roomId: this.roomId,
|
roomId: this.roomId,
|
||||||
name: this.name
|
name: this.name,
|
||||||
|
frame: this.frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,14 +71,15 @@ export interface MessageUserPositionInterface {
|
|||||||
userId: string;
|
userId: string;
|
||||||
roomId: string;
|
roomId: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
frame: string;
|
||||||
position: PointInterface;
|
position: PointInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessageUserPosition extends Message implements MessageUserPositionInterface{
|
class MessageUserPosition extends Message implements MessageUserPositionInterface{
|
||||||
position: PointInterface;
|
position: PointInterface;
|
||||||
|
|
||||||
constructor(userId : string, roomId : string, point : Point, name: string) {
|
constructor(userId : string, roomId : string, point : Point, name: string, frame: string) {
|
||||||
super(userId, roomId, name);
|
super(userId, roomId, name, frame);
|
||||||
this.position = point;
|
this.position = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +115,8 @@ class ListMessageUserPosition {
|
|||||||
userPosition.position.y,
|
userPosition.position.y,
|
||||||
userPosition.position.direction
|
userPosition.position.direction
|
||||||
),
|
),
|
||||||
userPosition.name
|
userPosition.name,
|
||||||
|
userPosition.frame
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -124,11 +129,11 @@ export interface ConnexionInterface {
|
|||||||
userId: string;
|
userId: string;
|
||||||
startedRoom: string;
|
startedRoom: string;
|
||||||
|
|
||||||
createConnexion(): Promise<any>;
|
createConnexion(frameSelected: string): Promise<any>;
|
||||||
|
|
||||||
joinARoom(roomId: string): void;
|
joinARoom(roomId: string, frame: string): void;
|
||||||
|
|
||||||
sharePosition(x: number, y: number, direction: string): void;
|
sharePosition(x: number, y: number, direction: string, frame: string): void;
|
||||||
|
|
||||||
positionOfAllUser(): void;
|
positionOfAllUser(): void;
|
||||||
|
|
||||||
@ -156,7 +161,7 @@ export class Connexion implements ConnexionInterface {
|
|||||||
this.GameManager = GameManager;
|
this.GameManager = GameManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
createConnexion(): Promise<ConnexionInterface> {
|
createConnexion(frameSelected: string): Promise<ConnexionInterface> {
|
||||||
return Axios.post(`${API_URL}/login`, {email: this.email})
|
return Axios.post(`${API_URL}/login`, {email: this.email})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.token = res.data.token;
|
this.token = res.data.token;
|
||||||
@ -170,10 +175,10 @@ export class Connexion implements ConnexionInterface {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//join the room
|
//join the room
|
||||||
this.joinARoom(this.startedRoom);
|
this.joinARoom(this.startedRoom, frameSelected);
|
||||||
|
|
||||||
//share your first position
|
//share your first position
|
||||||
this.sharePosition(0, 0);
|
this.sharePosition(0, 0, frameSelected);
|
||||||
|
|
||||||
this.positionOfAllUser();
|
this.positionOfAllUser();
|
||||||
|
|
||||||
@ -188,11 +193,18 @@ export class Connexion implements ConnexionInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permit to join a room
|
*
|
||||||
* @param roomId
|
* @param roomId
|
||||||
|
* @param frame
|
||||||
*/
|
*/
|
||||||
joinARoom(roomId: string): void {
|
joinARoom(roomId: string, frame: string): void {
|
||||||
let messageUserPosition = new MessageUserPosition(this.userId, this.startedRoom, new Point(0, 0), this.email);
|
let messageUserPosition = new MessageUserPosition(
|
||||||
|
this.userId,
|
||||||
|
this.startedRoom,
|
||||||
|
new Point(0, 0),
|
||||||
|
this.email,
|
||||||
|
frame
|
||||||
|
);
|
||||||
this.socket.emit(EventMessage.JOIN_ROOM, messageUserPosition.toString());
|
this.socket.emit(EventMessage.JOIN_ROOM, messageUserPosition.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,13 +212,20 @@ export class Connexion implements ConnexionInterface {
|
|||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* @param y
|
* @param y
|
||||||
|
* @param frame
|
||||||
* @param direction
|
* @param direction
|
||||||
*/
|
*/
|
||||||
sharePosition(x : number, y : number, direction : string = "none") : void{
|
sharePosition(x : number, y : number, frame : string, direction : string = "none") : void{
|
||||||
if(!this.socket){
|
if(!this.socket){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let messageUserPosition = new MessageUserPosition(this.userId, ROOM[0], new Point(x, y, direction), this.email);
|
let messageUserPosition = new MessageUserPosition(
|
||||||
|
this.userId,
|
||||||
|
ROOM[0],
|
||||||
|
new Point(x, y, direction),
|
||||||
|
this.email,
|
||||||
|
frame
|
||||||
|
);
|
||||||
this.socket.emit(EventMessage.USER_POSITION, messageUserPosition.toString());
|
this.socket.emit(EventMessage.USER_POSITION, messageUserPosition.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,13 +2,40 @@ import {PlayerAnimationNames} from "../Player/Animation";
|
|||||||
import {SpeechBubble} from "./SpeechBubble";
|
import {SpeechBubble} from "./SpeechBubble";
|
||||||
import BitmapText = Phaser.GameObjects.BitmapText;
|
import BitmapText = Phaser.GameObjects.BitmapText;
|
||||||
|
|
||||||
|
export const PLAYER_RESOURCES: Array<any> = [
|
||||||
|
{name: "male1", img: "resources/characters/pipoya/Male 01-1.png", x: 32, y: 32},
|
||||||
|
{name: "male2", img: "resources/characters/pipoya/Male 02-2.png", x: 64, y: 32},
|
||||||
|
{name: "male3", img: "resources/characters/pipoya/Male 03-4.png", x: 96, y: 32},
|
||||||
|
{name: "male4", img: "resources/characters/pipoya/Male 09-1.png", x: 128, y: 32},
|
||||||
|
|
||||||
|
{name: "male5", img: "resources/characters/pipoya/Male 10-3.png", x: 32, y: 64},
|
||||||
|
{name: "male6", img: "resources/characters/pipoya/Male 17-2.png", x: 64, y: 64},
|
||||||
|
{name: "male7", img: "resources/characters/pipoya/Male 18-1.png", x: 96, y: 64},
|
||||||
|
{name: "male8", img: "resources/characters/pipoya/Male 16-4.png", x: 128, y: 64},
|
||||||
|
|
||||||
|
{name: "Female1", img: "resources/characters/pipoya/Female 01-1.png", x: 32, y: 96},
|
||||||
|
{name: "Female2", img: "resources/characters/pipoya/Female 02-2.png", x: 64, y: 96},
|
||||||
|
{name: "Female3", img: "resources/characters/pipoya/Female 03-4.png", x: 96, y: 96},
|
||||||
|
{name: "Female4", img: "resources/characters/pipoya/Female 09-1.png", x: 128, y: 96},
|
||||||
|
|
||||||
|
{name: "Female5", img: "resources/characters/pipoya/Female 10-3.png", x: 32, y: 128},
|
||||||
|
{name: "Female6", img: "resources/characters/pipoya/Female 17-2.png", x: 64, y: 128},
|
||||||
|
{name: "Female7", img: "resources/characters/pipoya/Female 18-1.png", x: 96, y: 128},
|
||||||
|
{name: "Female8", img: "resources/characters/pipoya/Female 16-4.png", x: 128, y: 128}
|
||||||
|
];
|
||||||
|
|
||||||
export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
|
export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
|
||||||
private bubble: SpeechBubble;
|
private bubble: SpeechBubble;
|
||||||
private playerName: BitmapText;
|
private playerName: BitmapText;
|
||||||
|
public PlayerValue: string;
|
||||||
|
public PlayerTexture: string;
|
||||||
|
|
||||||
|
|
||||||
constructor(scene: Phaser.Scene, x: number, y: number, texture: string, name: string, frame?: string | number) {
|
constructor(scene: Phaser.Scene, x: number, y: number, texture: string, name: string, frame?: string | number) {
|
||||||
super(scene, x, y, texture, frame);
|
super(scene, x, y, texture, frame);
|
||||||
|
|
||||||
|
this.PlayerValue = name;
|
||||||
|
this.PlayerTexture = texture;
|
||||||
this.playerName = new BitmapText(scene, x, y - 25, 'main_font', name, 8);
|
this.playerName = new BitmapText(scene, x, y - 25, 'main_font', name, 8);
|
||||||
this.playerName.setOrigin(0.5).setCenterAlign();
|
this.playerName.setOrigin(0.5).setCenterAlign();
|
||||||
scene.add.existing(this.playerName);
|
scene.add.existing(this.playerName);
|
||||||
@ -23,22 +50,22 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
|
|||||||
this.setOffset(8, 16);
|
this.setOffset(8, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
move(x: number, y: number){
|
move(x: number, y: number) {
|
||||||
|
|
||||||
this.setVelocity(x, y);
|
this.setVelocity(x, y);
|
||||||
|
|
||||||
//up or down animationss are prioritized over left and right
|
//up or down animationss are prioritized over left and right
|
||||||
if (this.body.velocity.y < 0) { //moving up
|
if (this.body.velocity.y < 0) { //moving up
|
||||||
this.play(PlayerAnimationNames.WalkUp, true);
|
this.play(`${this.PlayerTexture}-${PlayerAnimationNames.WalkUp}`, true);
|
||||||
} else if (this.body.velocity.y > 0) { //moving down
|
} else if (this.body.velocity.y > 0) { //moving down
|
||||||
this.play(PlayerAnimationNames.WalkDown, true);
|
this.play(`${this.PlayerTexture}-${PlayerAnimationNames.WalkDown}`, true);
|
||||||
} else if (this.body.velocity.x > 0) { //moving right
|
} else if (this.body.velocity.x > 0) { //moving right
|
||||||
this.play(PlayerAnimationNames.WalkRight, true);
|
this.play(`${this.PlayerTexture}-${PlayerAnimationNames.WalkRight}`, true);
|
||||||
} else if (this.body.velocity.x < 0) { //moving left
|
} else if (this.body.velocity.x < 0) { //moving left
|
||||||
this.anims.playReverse(PlayerAnimationNames.WalkLeft, true);
|
this.anims.playReverse(`${this.PlayerTexture}-${PlayerAnimationNames.WalkLeft}`, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.bubble) {
|
if (this.bubble) {
|
||||||
this.bubble.moveBubble(this.x, this.y);
|
this.bubble.moveBubble(this.x, this.y);
|
||||||
}
|
}
|
||||||
this.updatePlayerNamePosition(this.x, this.y);
|
this.updatePlayerNamePosition(this.x, this.y);
|
||||||
|
@ -13,6 +13,7 @@ export interface HasMovedEvent {
|
|||||||
direction: string;
|
direction: string;
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
frame: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GameManager {
|
export class GameManager {
|
||||||
@ -21,15 +22,17 @@ export class GameManager {
|
|||||||
private currentGameScene: GameScene;
|
private currentGameScene: GameScene;
|
||||||
private playerName: string;
|
private playerName: string;
|
||||||
SimplePeer : SimplePeerInterface;
|
SimplePeer : SimplePeerInterface;
|
||||||
|
private frameUserSelected: string;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.status = StatusGameManagerEnum.IN_PROGRESS;
|
this.status = StatusGameManagerEnum.IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(name:string) {
|
connect(name: string, frameUserSelected : string) {
|
||||||
this.playerName = name;
|
this.playerName = name;
|
||||||
|
this.frameUserSelected = frameUserSelected;
|
||||||
this.ConnexionInstance = new Connexion(name, this);
|
this.ConnexionInstance = new Connexion(name, this);
|
||||||
return this.ConnexionInstance.createConnexion().then(() => {
|
return this.ConnexionInstance.createConnexion(frameUserSelected).then(() => {
|
||||||
this.SimplePeer = new SimplePeer(this.ConnexionInstance);
|
this.SimplePeer = new SimplePeer(this.ConnexionInstance);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -67,8 +70,12 @@ export class GameManager {
|
|||||||
return this.playerName;
|
return this.playerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFrameSelected(): string {
|
||||||
|
return this.frameUserSelected;
|
||||||
|
}
|
||||||
|
|
||||||
pushPlayerPosition(event: HasMovedEvent) {
|
pushPlayerPosition(event: HasMovedEvent) {
|
||||||
this.ConnexionInstance.sharePosition(event.x, event.y, event.direction);
|
this.ConnexionInstance.sharePosition(event.x, event.y, event.frame, event.direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,10 +5,11 @@ import {DEBUG_MODE, RESOLUTION, ROOM, ZOOM_LEVEL} from "../../Enum/EnvironmentVa
|
|||||||
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 {PLAYER_RESOURCES} from "../Entity/PlayableCaracter";
|
||||||
|
|
||||||
export const GameSceneName = "GameScene";
|
export const GameSceneName = "GameScene";
|
||||||
export enum Textures {
|
export enum Textures {
|
||||||
Player = 'playerModel',
|
Player = 'male1',
|
||||||
Map = 'map'
|
Map = 'map'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,10 +58,16 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
this.load.tilemapTiledJSON(Textures.Map, mapUrl);
|
this.load.tilemapTiledJSON(Textures.Map, mapUrl);
|
||||||
this.load.spritesheet(Textures.Player,
|
|
||||||
'resources/characters/pipoya/Male 01-1.png',
|
//add player png
|
||||||
{ frameWidth: 32, frameHeight: 32 }
|
PLAYER_RESOURCES.forEach((playerResource: any) => {
|
||||||
);
|
this.load.spritesheet(
|
||||||
|
playerResource.name,
|
||||||
|
playerResource.img,
|
||||||
|
{frameWidth: 32, frameHeight: 32}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
this.load.bitmapFont('main_font', 'resources/fonts/arcade.png', 'resources/fonts/arcade.xml');
|
this.load.bitmapFont('main_font', 'resources/fonts/arcade.png', 'resources/fonts/arcade.xml');
|
||||||
|
|
||||||
cypressAsserter.preloadFinished();
|
cypressAsserter.preloadFinished();
|
||||||
@ -165,7 +172,8 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
this,
|
this,
|
||||||
this.startX,
|
this.startX,
|
||||||
this.startY,
|
this.startY,
|
||||||
this.GameManager.getPlayerName()
|
this.GameManager.getPlayerName(),
|
||||||
|
this.GameManager.getFrameSelected()
|
||||||
);
|
);
|
||||||
this.CurrentPlayer.initAnimation();
|
this.CurrentPlayer.initAnimation();
|
||||||
|
|
||||||
@ -258,7 +266,8 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||||||
this,
|
this,
|
||||||
MessageUserPosition.position.x,
|
MessageUserPosition.position.x,
|
||||||
MessageUserPosition.position.y,
|
MessageUserPosition.position.y,
|
||||||
MessageUserPosition.name
|
MessageUserPosition.name,
|
||||||
|
MessageUserPosition.frame
|
||||||
);
|
);
|
||||||
player.initAnimation();
|
player.initAnimation();
|
||||||
this.MapPlayers.add(player);
|
this.MapPlayers.add(player);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {gameManager, HasMovedEvent} from "../Game/GameManager";
|
import {gameManager} from "../Game/GameManager";
|
||||||
import {TextField} from "../Components/TextField";
|
import {TextField} from "../Components/TextField";
|
||||||
import {TextInput} from "../Components/TextInput";
|
import {TextInput} from "../Components/TextInput";
|
||||||
import {ClickButton} from "../Components/ClickButton";
|
import {ClickButton} from "../Components/ClickButton";
|
||||||
@ -7,6 +7,7 @@ import Image = Phaser.GameObjects.Image;
|
|||||||
import {Player} from "../Player/Player";
|
import {Player} from "../Player/Player";
|
||||||
import {getPlayerAnimations, PlayerAnimationNames} from "../Player/Animation";
|
import {getPlayerAnimations, PlayerAnimationNames} from "../Player/Animation";
|
||||||
import Rectangle = Phaser.GameObjects.Rectangle;
|
import Rectangle = Phaser.GameObjects.Rectangle;
|
||||||
|
import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter";
|
||||||
|
|
||||||
//todo: put this constants in a dedicated file
|
//todo: put this constants in a dedicated file
|
||||||
export const LoginSceneName = "LoginScene";
|
export const LoginSceneName = "LoginScene";
|
||||||
@ -28,28 +29,6 @@ export class LogincScene extends Phaser.Scene implements GameSceneInterface {
|
|||||||
private selectedPlayer: Phaser.Physics.Arcade.Sprite;
|
private selectedPlayer: Phaser.Physics.Arcade.Sprite;
|
||||||
private players: Array<Phaser.Physics.Arcade.Sprite> = new Array<Phaser.Physics.Arcade.Sprite>();
|
private players: Array<Phaser.Physics.Arcade.Sprite> = new Array<Phaser.Physics.Arcade.Sprite>();
|
||||||
|
|
||||||
private playerResources: Array<any> = [
|
|
||||||
{name: "male1", img: "resources/characters/pipoya/Male 01-1.png", x: 32, y: 32},
|
|
||||||
{name: "male2", img: "resources/characters/pipoya/Male 02-2.png", x: 64, y: 32},
|
|
||||||
{name: "male3", img: "resources/characters/pipoya/Male 03-4.png", x: 96, y: 32},
|
|
||||||
{name: "male4", img: "resources/characters/pipoya/Male 09-1.png", x: 128, y: 32},
|
|
||||||
|
|
||||||
{name: "male5", img: "resources/characters/pipoya/Male 10-3.png", x: 32, y: 64},
|
|
||||||
{name: "male6", img: "resources/characters/pipoya/Male 17-2.png", x: 64, y: 64},
|
|
||||||
{name: "male7", img: "resources/characters/pipoya/Male 18-1.png", x: 96, y: 64},
|
|
||||||
{name: "male8", img: "resources/characters/pipoya/Male 16-4.png", x: 128, y: 64},
|
|
||||||
|
|
||||||
{name: "Female1", img: "resources/characters/pipoya/Female 01-1.png", x: 32, y: 96},
|
|
||||||
{name: "Female2", img: "resources/characters/pipoya/Female 02-2.png", x: 64, y: 96},
|
|
||||||
{name: "Female3", img: "resources/characters/pipoya/Female 03-4.png", x: 96, y: 96},
|
|
||||||
{name: "Female4", img: "resources/characters/pipoya/Female 09-1.png", x: 128, y: 96},
|
|
||||||
|
|
||||||
{name: "Female5", img: "resources/characters/pipoya/Female 10-3.png", x: 32, y: 128},
|
|
||||||
{name: "Female6", img: "resources/characters/pipoya/Female 17-2.png", x: 64, y: 128},
|
|
||||||
{name: "Female7", img: "resources/characters/pipoya/Female 18-1.png", x: 96, y: 128},
|
|
||||||
{name: "Female8", img: "resources/characters/pipoya/Female 16-4.png", x: 128, y: 128}
|
|
||||||
];
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
key: LoginSceneName
|
key: LoginSceneName
|
||||||
@ -62,7 +41,7 @@ export class LogincScene extends Phaser.Scene implements GameSceneInterface {
|
|||||||
// Note: arcade.png from the Phaser 3 examples at: https://github.com/photonstorm/phaser3-examples/tree/master/public/assets/fonts/bitmap
|
// Note: arcade.png from the Phaser 3 examples at: https://github.com/photonstorm/phaser3-examples/tree/master/public/assets/fonts/bitmap
|
||||||
this.load.bitmapFont(LoginTextures.mainFont, 'resources/fonts/arcade.png', 'resources/fonts/arcade.xml');
|
this.load.bitmapFont(LoginTextures.mainFont, 'resources/fonts/arcade.png', 'resources/fonts/arcade.xml');
|
||||||
//add player png
|
//add player png
|
||||||
this.playerResources.forEach((playerResource: any) => {
|
PLAYER_RESOURCES.forEach((playerResource: any) => {
|
||||||
this.load.spritesheet(
|
this.load.spritesheet(
|
||||||
playerResource.name,
|
playerResource.name,
|
||||||
playerResource.img,
|
playerResource.img,
|
||||||
@ -108,7 +87,7 @@ export class LogincScene extends Phaser.Scene implements GameSceneInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async login(name: string) {
|
private async login(name: string) {
|
||||||
gameManager.connect(name).then(() => {
|
gameManager.connect(name, this.selectedPlayer.texture.key).then(() => {
|
||||||
this.scene.start(GameSceneName);
|
this.scene.start(GameSceneName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -120,8 +99,8 @@ export class LogincScene extends Phaser.Scene implements GameSceneInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createCurrentPlayer(UserId: string): void {
|
createCurrentPlayer(UserId: string): void {
|
||||||
for (let i = 0; i < this.playerResources.length; i++) {
|
for (let i = 0; i <PLAYER_RESOURCES.length; i++) {
|
||||||
let playerResource = this.playerResources[i];
|
let playerResource = PLAYER_RESOURCES[i];
|
||||||
let player = this.physics.add.sprite(playerResource.x, playerResource.y, playerResource.name, playerResource.name);
|
let player = this.physics.add.sprite(playerResource.x, playerResource.y, playerResource.name, playerResource.name);
|
||||||
player.setBounce(0.2);
|
player.setBounce(0.2);
|
||||||
player.setCollideWorldBounds(true);
|
player.setCollideWorldBounds(true);
|
||||||
@ -141,7 +120,7 @@ export class LogincScene extends Phaser.Scene implements GameSceneInterface {
|
|||||||
this.players.push(player);
|
this.players.push(player);
|
||||||
}
|
}
|
||||||
this.selectedPlayer = this.players[0];
|
this.selectedPlayer = this.players[0];
|
||||||
this.selectedPlayer.play(this.playerResources[0].name);
|
this.selectedPlayer.play(PLAYER_RESOURCES[0].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
shareUserPosition(UsersPosition: import("../../Connexion").MessageUserPositionInterface[]): void {
|
shareUserPosition(UsersPosition: import("../../Connexion").MessageUserPositionInterface[]): void {
|
||||||
|
@ -19,28 +19,28 @@ export enum PlayerAnimationNames {
|
|||||||
|
|
||||||
export const getPlayerAnimations = (name: string = Textures.Player): AnimationData[] => {
|
export const getPlayerAnimations = (name: string = Textures.Player): AnimationData[] => {
|
||||||
return [{
|
return [{
|
||||||
key: PlayerAnimationNames.WalkDown, //TODO chnage, it's a key for one anumation of ine user type.
|
key: `${name}-${PlayerAnimationNames.WalkDown}`, //TODO chnage, it's a key for one anumation of ine user type.
|
||||||
frameModel: name,
|
frameModel: name,
|
||||||
frameStart: 0,
|
frameStart: 0,
|
||||||
frameEnd: 2,
|
frameEnd: 2,
|
||||||
frameRate: 10,
|
frameRate: 10,
|
||||||
repeat: -1
|
repeat: -1
|
||||||
}, {
|
}, {
|
||||||
key: PlayerAnimationNames.WalkLeft,
|
key: `${name}-${PlayerAnimationNames.WalkLeft}`,
|
||||||
frameModel: name,
|
frameModel: name,
|
||||||
frameStart: 3,
|
frameStart: 3,
|
||||||
frameEnd: 5,
|
frameEnd: 5,
|
||||||
frameRate: 10,
|
frameRate: 10,
|
||||||
repeat: -1
|
repeat: -1
|
||||||
}, {
|
}, {
|
||||||
key: PlayerAnimationNames.WalkRight,
|
key: `${name}-${PlayerAnimationNames.WalkRight}`,
|
||||||
frameModel: name,
|
frameModel: name,
|
||||||
frameStart: 6,
|
frameStart: 6,
|
||||||
frameEnd: 8,
|
frameEnd: 8,
|
||||||
frameRate: 10,
|
frameRate: 10,
|
||||||
repeat: -1
|
repeat: -1
|
||||||
}, {
|
}, {
|
||||||
key: PlayerAnimationNames.WalkUp,
|
key: `${name}-${PlayerAnimationNames.WalkUp}`,
|
||||||
frameModel: name,
|
frameModel: name,
|
||||||
frameStart: 9,
|
frameStart: 9,
|
||||||
frameEnd: 11,
|
frameEnd: 11,
|
||||||
|
@ -8,7 +8,6 @@ import {PlayableCaracter} from "../Entity/PlayableCaracter";
|
|||||||
export const hasMovedEventName = "hasMoved";
|
export const hasMovedEventName = "hasMoved";
|
||||||
export interface CurrentGamerInterface extends PlayableCaracter{
|
export interface CurrentGamerInterface extends PlayableCaracter{
|
||||||
userId : string;
|
userId : string;
|
||||||
PlayerValue : string;
|
|
||||||
initAnimation() : void;
|
initAnimation() : void;
|
||||||
moveUser(delta: number) : void;
|
moveUser(delta: number) : void;
|
||||||
say(text : string) : void;
|
say(text : string) : void;
|
||||||
@ -16,7 +15,6 @@ export interface CurrentGamerInterface extends PlayableCaracter{
|
|||||||
|
|
||||||
export interface GamerInterface extends PlayableCaracter{
|
export interface GamerInterface extends PlayableCaracter{
|
||||||
userId : string;
|
userId : string;
|
||||||
PlayerValue : string;
|
|
||||||
initAnimation() : void;
|
initAnimation() : void;
|
||||||
updatePosition(MessageUserPosition : MessageUserPositionInterface) : void;
|
updatePosition(MessageUserPosition : MessageUserPositionInterface) : void;
|
||||||
say(text : string) : void;
|
say(text : string) : void;
|
||||||
@ -24,7 +22,6 @@ export interface GamerInterface extends PlayableCaracter{
|
|||||||
|
|
||||||
export class Player extends PlayableCaracter implements CurrentGamerInterface, GamerInterface {
|
export class Player extends PlayableCaracter implements CurrentGamerInterface, GamerInterface {
|
||||||
userId: string;
|
userId: string;
|
||||||
PlayerValue: string;
|
|
||||||
userInputManager: UserInputManager;
|
userInputManager: UserInputManager;
|
||||||
previousMove: string;
|
previousMove: string;
|
||||||
|
|
||||||
@ -34,23 +31,23 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
name: string,
|
name: string,
|
||||||
PlayerValue: string = Textures.Player
|
PlayerTexture: string = Textures.Player
|
||||||
) {
|
) {
|
||||||
super(Scene, x, y, PlayerValue, name, 1);
|
super(Scene, x, y, PlayerTexture, name, 1);
|
||||||
|
|
||||||
//create input to move
|
//create input to move
|
||||||
this.userInputManager = new UserInputManager(Scene);
|
this.userInputManager = new UserInputManager(Scene);
|
||||||
|
|
||||||
//set data
|
//set data
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
initAnimation(): void {
|
initAnimation(): void {
|
||||||
getPlayerAnimations().forEach(d => {
|
getPlayerAnimations(this.PlayerTexture).forEach(d => {
|
||||||
this.scene.anims.create({
|
this.scene.anims.create({
|
||||||
key: d.key,
|
key: d.key,
|
||||||
frames: this.scene.anims.generateFrameNumbers(d.frameModel, {start: d.frameStart, end: d.frameEnd}),
|
frames: this.scene.anims.generateFrameNumbers(d.frameModel, {start: d.frameStart, end: d.frameEnd}),
|
||||||
@ -73,17 +70,17 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||||||
let y = 0;
|
let y = 0;
|
||||||
if (activeEvents.get(UserInputEvent.MoveUp)) {
|
if (activeEvents.get(UserInputEvent.MoveUp)) {
|
||||||
y = - moveAmount;
|
y = - moveAmount;
|
||||||
direction = PlayerAnimationNames.WalkUp;
|
direction = `${this.PlayerTexture}-${PlayerAnimationNames.WalkUp}`;
|
||||||
} else if (activeEvents.get(UserInputEvent.MoveDown)) {
|
} else if (activeEvents.get(UserInputEvent.MoveDown)) {
|
||||||
y = moveAmount;
|
y = moveAmount;
|
||||||
direction = PlayerAnimationNames.WalkDown;
|
direction = `${this.PlayerTexture}-${PlayerAnimationNames.WalkDown}`;
|
||||||
}
|
}
|
||||||
if (activeEvents.get(UserInputEvent.MoveLeft)) {
|
if (activeEvents.get(UserInputEvent.MoveLeft)) {
|
||||||
x = -moveAmount;
|
x = -moveAmount;
|
||||||
direction = PlayerAnimationNames.WalkLeft;
|
direction = `${this.PlayerTexture}-${PlayerAnimationNames.WalkLeft}`;
|
||||||
} else if (activeEvents.get(UserInputEvent.MoveRight)) {
|
} else if (activeEvents.get(UserInputEvent.MoveRight)) {
|
||||||
x = moveAmount;
|
x = moveAmount;
|
||||||
direction = PlayerAnimationNames.WalkRight;
|
direction = `${this.PlayerTexture}-${PlayerAnimationNames.WalkRight}`;
|
||||||
}
|
}
|
||||||
if (x !== 0 || y !== 0) {
|
if (x !== 0 || y !== 0) {
|
||||||
this.move(x, y);
|
this.move(x, y);
|
||||||
@ -91,8 +88,7 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
|
|||||||
direction = PlayerAnimationNames.None;
|
direction = PlayerAnimationNames.None;
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y, frame: this.PlayerTexture});
|
||||||
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo: put this method into the NonPlayer class instead
|
//todo: put this method into the NonPlayer class instead
|
||||||
|
Loading…
Reference in New Issue
Block a user