export class Point implements PointInterface{
x: number;
y: number;
+ direction: string;
- constructor(x : number, y : number) {
+ 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
+ y: this.y,
+ direction: this.direction
}
}
}
constructor(message: string) {
super(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() {
export interface PointInterface {
x: number;
y: number;
+ direction: string;
toJson() : object;
}
\ No newline at end of file
export class Point implements PointInterface{
x: number;
y: number;
+ direction : string;
- constructor(x : number, y : number) {
+ 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
+ y: this.y,
+ direction: this.direction
}
}
}
}
/**
- * Permit to share your position in map
+ *
+ * @param roomId
* @param x
* @param y
+ * @param direction
*/
- sharePosition(roomId : string, x : number, y : number){
+ sharePosition(roomId : string, x : number, y : number, direction : string = "none"){
if(!this.socket){
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());
}
//if user client on shift, camera and player speed
let speedMultiplier = this.MapManager.keyShift.isDown ? 5 : 1;
let haveMove = false;
+ let direction = null;
if((this.MapManager.keyZ.isDown || this.MapManager.keyUp.isDown)){
if(!this.CanToMoveUp()){
playAnimation(this, PlayerAnimationNames.WalkUp);
this.setY(this.y - (2 * speedMultiplier));
haveMove = true;
+ direction = PlayerAnimationNames.WalkUp;
}
if((this.MapManager.keyQ.isDown || this.MapManager.keyLeft.isDown)){
if(!this.CanToMoveLeft()){
playAnimation(this, PlayerAnimationNames.WalkLeft);
this.setX(this.x - (2 * speedMultiplier));
haveMove = true;
+ direction = PlayerAnimationNames.WalkLeft;
}
if((this.MapManager.keyS.isDown || this.MapManager.keyDown.isDown)){
if(!this.CanToMoveDown()){
playAnimation(this, PlayerAnimationNames.WalkDown);
this.setY(this.y + (2 * speedMultiplier));
haveMove = true;
+ direction = PlayerAnimationNames.WalkDown;
}
if((this.MapManager.keyD.isDown || this.MapManager.keyRight.isDown)){
if(!this.CanToMoveRight()){
playAnimation(this, PlayerAnimationNames.WalkRight);
this.setX(this.x + (2 * speedMultiplier));
haveMove = true;
+ direction = PlayerAnimationNames.WalkRight;
}
if(!haveMove){
playAnimation(this, PlayerAnimationNames.None);
}else{
- this.sharePosition();
+ this.sharePosition(direction);
}
}
- private sharePosition(){
+ private sharePosition(direction : string){
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);
}
}