FAZA 2: Fix player going off-terrain - sync player with terrain container offset

This commit is contained in:
2025-12-06 18:12:15 +01:00
parent 6e92e89f74
commit 1c1ee97b2c
2 changed files with 24 additions and 9 deletions

View File

@@ -1,14 +1,18 @@
// Player Entity
// Igralec z WASD kontrolami in isometrično podporo
class Player {
constructor(scene, gridX = 50, gridY = 50) {
constructor(scene, gridX = 50, gridY = 50, offsetX = 0, offsetY = 0) {
this.scene = scene;
this.gridX = gridX;
this.gridY = gridY;
// Terrain offset (za sinhronizacijo s terrain containerjem)
this.offsetX = offsetX;
this.offsetY = offsetY;
this.iso = new IsometricUtils(48, 24);
// Hitrost gibanja
// Hitrostgibanja
this.moveSpeed = 150; // px/s
this.gridMoveTime = 200; // ms za premik na eno kocko
@@ -32,7 +36,11 @@ class Player {
// Kreira sprite
const screenPos = this.iso.toScreen(this.gridX, this.gridY);
this.sprite = this.scene.add.sprite(screenPos.x, screenPos.y, 'player');
this.sprite = this.scene.add.sprite(
screenPos.x + this.offsetX,
screenPos.y + this.offsetY,
'player'
);
this.sprite.setOrigin(0.5, 1); // Anchor na dnu sprite-a
// Depth sorting
@@ -107,8 +115,8 @@ class Player {
// Tween za smooth gibanje (brez animacije za zdaj)
this.scene.tweens.add({
targets: this.sprite,
x: targetScreen.x,
y: targetScreen.y,
x: targetScreen.x + this.offsetX,
y: targetScreen.y + this.offsetY,
duration: this.gridMoveTime,
ease: 'Linear',
onComplete: () => {
@@ -122,7 +130,10 @@ class Player {
updatePosition() {
const screenPos = this.iso.toScreen(this.gridX, this.gridY);
this.sprite.setPosition(screenPos.x, screenPos.y);
this.sprite.setPosition(
screenPos.x + this.offsetX,
screenPos.y + this.offsetY
);
this.updateDepth();
}