Fix Message send to add direction
This commit is contained in:
parent
aba3322188
commit
67c3eaa7f4
@ -4,19 +4,22 @@ import {PointInterface} from "./PointInterface";
|
|||||||
export class Point implements PointInterface{
|
export class Point implements PointInterface{
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
direction: string;
|
||||||
|
|
||||||
constructor(x : number, y : number) {
|
constructor(x : number, y : number, direction : string = "none") {
|
||||||
if(x === null || y === null){
|
if(x === null || y === null){
|
||||||
throw Error("position x and y cannot be null");
|
throw Error("position x and y cannot be null");
|
||||||
}
|
}
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
this.direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson(){
|
toJson(){
|
||||||
return {
|
return {
|
||||||
x : this.x,
|
x : this.x,
|
||||||
y: this.y
|
y: this.y,
|
||||||
|
direction: this.direction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -27,7 +30,7 @@ export class MessageUserPosition extends Message{
|
|||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
super(message);
|
super(message);
|
||||||
let data = JSON.parse(message);
|
let data = JSON.parse(message);
|
||||||
this.position = new Point(data.position.x, data.position.y);
|
this.position = new Point(data.position.x, data.position.y, data.position.direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
export interface PointInterface {
|
export interface PointInterface {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
direction: string;
|
||||||
toJson() : object;
|
toJson() : object;
|
||||||
}
|
}
|
@ -30,19 +30,22 @@ export class Message {
|
|||||||
export class Point implements PointInterface{
|
export class Point implements PointInterface{
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
direction : string;
|
||||||
|
|
||||||
constructor(x : number, y : number) {
|
constructor(x : number, y : number, direction : string = "none") {
|
||||||
if(x === null || y === null){
|
if(x === null || y === null){
|
||||||
throw Error("position x and y cannot be null");
|
throw Error("position x and y cannot be null");
|
||||||
}
|
}
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
this.direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson(){
|
toJson(){
|
||||||
return {
|
return {
|
||||||
x : this.x,
|
x : this.x,
|
||||||
y: this.y
|
y: this.y,
|
||||||
|
direction: this.direction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,15 +117,17 @@ export class Connexion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permit to share your position in map
|
*
|
||||||
|
* @param roomId
|
||||||
* @param x
|
* @param x
|
||||||
* @param y
|
* @param y
|
||||||
|
* @param direction
|
||||||
*/
|
*/
|
||||||
sharePosition(roomId : string, x : number, y : number){
|
sharePosition(roomId : string, x : number, y : number, direction : string = "none"){
|
||||||
if(!this.socket){
|
if(!this.socket){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let messageUserPosition = new MessageUserPosition(this.email, roomId, new Point(x, y));
|
let messageUserPosition = new MessageUserPosition(this.email, roomId, new Point(x, y, direction));
|
||||||
this.socket.emit('user-position', messageUserPosition.toString());
|
this.socket.emit('user-position', messageUserPosition.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ export class Player extends Phaser.GameObjects.Sprite{
|
|||||||
//if user client on shift, camera and player speed
|
//if user client on shift, camera and player speed
|
||||||
let speedMultiplier = this.MapManager.keyShift.isDown ? 5 : 1;
|
let speedMultiplier = this.MapManager.keyShift.isDown ? 5 : 1;
|
||||||
let haveMove = false;
|
let haveMove = false;
|
||||||
|
let direction = null;
|
||||||
|
|
||||||
if((this.MapManager.keyZ.isDown || this.MapManager.keyUp.isDown)){
|
if((this.MapManager.keyZ.isDown || this.MapManager.keyUp.isDown)){
|
||||||
if(!this.CanToMoveUp()){
|
if(!this.CanToMoveUp()){
|
||||||
@ -46,6 +47,7 @@ export class Player extends Phaser.GameObjects.Sprite{
|
|||||||
playAnimation(this, PlayerAnimationNames.WalkUp);
|
playAnimation(this, PlayerAnimationNames.WalkUp);
|
||||||
this.setY(this.y - (2 * speedMultiplier));
|
this.setY(this.y - (2 * speedMultiplier));
|
||||||
haveMove = true;
|
haveMove = true;
|
||||||
|
direction = PlayerAnimationNames.WalkUp;
|
||||||
}
|
}
|
||||||
if((this.MapManager.keyQ.isDown || this.MapManager.keyLeft.isDown)){
|
if((this.MapManager.keyQ.isDown || this.MapManager.keyLeft.isDown)){
|
||||||
if(!this.CanToMoveLeft()){
|
if(!this.CanToMoveLeft()){
|
||||||
@ -54,6 +56,7 @@ export class Player extends Phaser.GameObjects.Sprite{
|
|||||||
playAnimation(this, PlayerAnimationNames.WalkLeft);
|
playAnimation(this, PlayerAnimationNames.WalkLeft);
|
||||||
this.setX(this.x - (2 * speedMultiplier));
|
this.setX(this.x - (2 * speedMultiplier));
|
||||||
haveMove = true;
|
haveMove = true;
|
||||||
|
direction = PlayerAnimationNames.WalkLeft;
|
||||||
}
|
}
|
||||||
if((this.MapManager.keyS.isDown || this.MapManager.keyDown.isDown)){
|
if((this.MapManager.keyS.isDown || this.MapManager.keyDown.isDown)){
|
||||||
if(!this.CanToMoveDown()){
|
if(!this.CanToMoveDown()){
|
||||||
@ -62,6 +65,7 @@ export class Player extends Phaser.GameObjects.Sprite{
|
|||||||
playAnimation(this, PlayerAnimationNames.WalkDown);
|
playAnimation(this, PlayerAnimationNames.WalkDown);
|
||||||
this.setY(this.y + (2 * speedMultiplier));
|
this.setY(this.y + (2 * speedMultiplier));
|
||||||
haveMove = true;
|
haveMove = true;
|
||||||
|
direction = PlayerAnimationNames.WalkDown;
|
||||||
}
|
}
|
||||||
if((this.MapManager.keyD.isDown || this.MapManager.keyRight.isDown)){
|
if((this.MapManager.keyD.isDown || this.MapManager.keyRight.isDown)){
|
||||||
if(!this.CanToMoveRight()){
|
if(!this.CanToMoveRight()){
|
||||||
@ -70,17 +74,18 @@ export class Player extends Phaser.GameObjects.Sprite{
|
|||||||
playAnimation(this, PlayerAnimationNames.WalkRight);
|
playAnimation(this, PlayerAnimationNames.WalkRight);
|
||||||
this.setX(this.x + (2 * speedMultiplier));
|
this.setX(this.x + (2 * speedMultiplier));
|
||||||
haveMove = true;
|
haveMove = true;
|
||||||
|
direction = PlayerAnimationNames.WalkRight;
|
||||||
}
|
}
|
||||||
if(!haveMove){
|
if(!haveMove){
|
||||||
playAnimation(this, PlayerAnimationNames.None);
|
playAnimation(this, PlayerAnimationNames.None);
|
||||||
}else{
|
}else{
|
||||||
this.sharePosition();
|
this.sharePosition(direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private sharePosition(){
|
private sharePosition(direction : string){
|
||||||
if(ConnexionInstance) {
|
if(ConnexionInstance) {
|
||||||
ConnexionInstance.sharePosition((this.scene as GameSceneInterface).RoomId, this.x, this.y);
|
ConnexionInstance.sharePosition((this.scene as GameSceneInterface).RoomId, this.x, this.y, direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user