FAZA 2: Fix player going off-terrain - sync player with terrain container offset
This commit is contained in:
@@ -1,14 +1,18 @@
|
|||||||
// Player Entity
|
// Player Entity
|
||||||
// Igralec z WASD kontrolami in isometrično podporo
|
// Igralec z WASD kontrolami in isometrično podporo
|
||||||
class Player {
|
class Player {
|
||||||
constructor(scene, gridX = 50, gridY = 50) {
|
constructor(scene, gridX = 50, gridY = 50, offsetX = 0, offsetY = 0) {
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.gridX = gridX;
|
this.gridX = gridX;
|
||||||
this.gridY = gridY;
|
this.gridY = gridY;
|
||||||
|
|
||||||
|
// Terrain offset (za sinhronizacijo s terrain containerjem)
|
||||||
|
this.offsetX = offsetX;
|
||||||
|
this.offsetY = offsetY;
|
||||||
|
|
||||||
this.iso = new IsometricUtils(48, 24);
|
this.iso = new IsometricUtils(48, 24);
|
||||||
|
|
||||||
// Hitrost gibanja
|
// Hitrostgibanja
|
||||||
this.moveSpeed = 150; // px/s
|
this.moveSpeed = 150; // px/s
|
||||||
this.gridMoveTime = 200; // ms za premik na eno kocko
|
this.gridMoveTime = 200; // ms za premik na eno kocko
|
||||||
|
|
||||||
@@ -32,7 +36,11 @@ class Player {
|
|||||||
|
|
||||||
// Kreira sprite
|
// Kreira sprite
|
||||||
const screenPos = this.iso.toScreen(this.gridX, this.gridY);
|
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
|
this.sprite.setOrigin(0.5, 1); // Anchor na dnu sprite-a
|
||||||
|
|
||||||
// Depth sorting
|
// Depth sorting
|
||||||
@@ -107,8 +115,8 @@ class Player {
|
|||||||
// Tween za smooth gibanje (brez animacije za zdaj)
|
// Tween za smooth gibanje (brez animacije za zdaj)
|
||||||
this.scene.tweens.add({
|
this.scene.tweens.add({
|
||||||
targets: this.sprite,
|
targets: this.sprite,
|
||||||
x: targetScreen.x,
|
x: targetScreen.x + this.offsetX,
|
||||||
y: targetScreen.y,
|
y: targetScreen.y + this.offsetY,
|
||||||
duration: this.gridMoveTime,
|
duration: this.gridMoveTime,
|
||||||
ease: 'Linear',
|
ease: 'Linear',
|
||||||
onComplete: () => {
|
onComplete: () => {
|
||||||
@@ -122,7 +130,10 @@ class Player {
|
|||||||
|
|
||||||
updatePosition() {
|
updatePosition() {
|
||||||
const screenPos = this.iso.toScreen(this.gridX, this.gridY);
|
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();
|
this.updateDepth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,15 @@ class GameScene extends Phaser.Scene {
|
|||||||
console.log('🌍 Initializing terrain...');
|
console.log('🌍 Initializing terrain...');
|
||||||
this.terrainSystem = new TerrainSystem(this, 100, 100);
|
this.terrainSystem = new TerrainSystem(this, 100, 100);
|
||||||
this.terrainSystem.generate();
|
this.terrainSystem.generate();
|
||||||
this.terrainContainer = this.terrainSystem.render(width / 2, 100);
|
|
||||||
|
|
||||||
// Dodaj igralca - spawn na sredini mape
|
// Terrain offset
|
||||||
|
this.terrainOffsetX = width / 2;
|
||||||
|
this.terrainOffsetY = 100;
|
||||||
|
this.terrainContainer = this.terrainSystem.render(this.terrainOffsetX, this.terrainOffsetY);
|
||||||
|
|
||||||
|
// Dodaj igralca - spawn na sredini mape S TERRAIN OFFSETOM
|
||||||
console.log('👤 Initializing player...');
|
console.log('👤 Initializing player...');
|
||||||
this.player = new Player(this, 50, 50);
|
this.player = new Player(this, 50, 50, this.terrainOffsetX, this.terrainOffsetY);
|
||||||
|
|
||||||
// Kamera sledi igralcu
|
// Kamera sledi igralcu
|
||||||
this.cameras.main.startFollow(this.player.sprite, true, 0.1, 0.1);
|
this.cameras.main.startFollow(this.player.sprite, true, 0.1, 0.1);
|
||||||
|
|||||||
Reference in New Issue
Block a user