All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m20s
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import Phaser from "phaser";
|
|
|
|
export class RemotePlayer {
|
|
sprite: Phaser.GameObjects.Rectangle;
|
|
label: Phaser.GameObjects.Text;
|
|
|
|
targetX: number;
|
|
targetY: number;
|
|
|
|
constructor(
|
|
scene: Phaser.Scene,
|
|
x: number,
|
|
y: number,
|
|
name: string,
|
|
color: number,
|
|
) {
|
|
this.sprite = scene.add.rectangle(x, y, 32, 32, color);
|
|
|
|
this.label = scene.add
|
|
.text(x, y - 26, name, {
|
|
fontSize: "12px",
|
|
color: "#ffffff",
|
|
stroke: "#000000",
|
|
strokeThickness: 3,
|
|
})
|
|
.setOrigin(0.5);
|
|
|
|
this.targetX = x;
|
|
this.targetY = y;
|
|
}
|
|
|
|
setTarget(x: number, y: number) {
|
|
this.targetX = x;
|
|
this.targetY = y;
|
|
}
|
|
|
|
update() {
|
|
// интерполяция позиции
|
|
this.sprite.x = Phaser.Math.Linear(this.sprite.x, this.targetX, 0.15);
|
|
this.sprite.y = Phaser.Math.Linear(this.sprite.y, this.targetY, 0.15);
|
|
|
|
// ник всегда над игроком
|
|
this.label.x = this.sprite.x;
|
|
this.label.y = this.sprite.y - 26;
|
|
}
|
|
|
|
destroy() {
|
|
this.sprite.destroy();
|
|
this.label.destroy();
|
|
}
|
|
}
|