fix
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m20s

This commit is contained in:
Smile Rex
2026-01-21 19:17:52 +03:00
parent 544160f916
commit ae4471dec9
3 changed files with 69 additions and 4 deletions

View File

@@ -2,12 +2,29 @@ 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, color: 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;
}
@@ -18,12 +35,17 @@ export class RemotePlayer {
}
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();
}
}