partey_workadventure/front/src/Phaser/Entity/RemotePlayer.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-06-04 18:54:34 +02:00
import {GameScene} from "../Game/GameScene";
2020-09-25 18:29:22 +02:00
import {PointInterface} from "../../Connexion/ConnexionModels";
2020-06-04 18:54:34 +02:00
import {Character} from "../Entity/Character";
import {PlayerAnimationDirections} from "../Player/Animation";
2020-06-04 18:54:34 +02:00
/**
* Class representing the sprite of a remote player (a player that plays on another computer)
*/
export class RemotePlayer extends Character {
userId: number;
2020-06-04 18:54:34 +02:00
constructor(
userId: number,
2020-06-04 18:54:34 +02:00
Scene: GameScene,
x: number,
y: number,
name: string,
texturesPromise: Promise<string[]>,
direction: PlayerAnimationDirections,
2020-06-04 18:54:34 +02:00
moving: boolean
) {
super(Scene, x, y, texturesPromise, name, direction, moving, 1);
2020-06-04 18:54:34 +02:00
//set data
this.userId = userId;
}
updatePosition(position: PointInterface): void {
this.playAnimation(position.direction as PlayerAnimationDirections, position.moving);
2020-06-04 18:54:34 +02:00
this.setX(position.x);
this.setY(position.y);
this.setDepth(position.y); //this is to make sure the perspective (player models closer the bottom of the screen will appear in front of models nearer the top of the screen).
2020-06-04 18:54:34 +02:00
}
}