dreva in kamni top

This commit is contained in:
2025-12-07 22:32:45 +01:00
parent 974141c08c
commit 6b8f9aee66
13 changed files with 384 additions and 90 deletions

View File

@@ -493,7 +493,10 @@ class NPC {
if (!this.sprite) return;
if (this.lastDepthY === undefined || Math.abs(this.sprite.y - this.lastDepthY) > 0.1) {
this.sprite.setDepth(this.sprite.y);
const layerBase = this.iso.LAYER_OBJECTS || 200000;
const depth = layerBase + this.sprite.y;
this.sprite.setDepth(depth);
this.lastDepthY = this.sprite.y;
// Update attached elements depth

View File

@@ -133,6 +133,51 @@ class Player {
left: Phaser.Input.Keyboard.KeyCodes.A,
right: Phaser.Input.Keyboard.KeyCodes.D
});
// Gamepad Events
this.scene.input.gamepad.on('connected', (pad) => {
this.setupGamepadEvents(pad);
});
if (this.scene.input.gamepad.total > 0) {
this.setupGamepadEvents(this.scene.input.gamepad.getPad(0));
}
}
setupGamepadEvents(pad) {
if (!pad) return;
console.log('🎮 Gamepad Connected:', pad.id);
pad.on('down', (index) => {
if (this.isDead) return;
// A Button (0) - Attack
if (index === 0) {
this.attack();
}
// X Button (2) - Interact (Pick/Tame)
if (index === 2) {
const targetX = this.gridX + this.lastDir.x;
const targetY = this.gridY + this.lastDir.y;
if (this.scene.interactionSystem) {
this.scene.interactionSystem.handleInteraction(targetX, targetY);
}
}
// Y Button (3) - Crafting
if (index === 3) {
// Zahteva, da UIScene posluša ta event, ali pa direktni klic
const ui = this.scene.scene.get('UIScene');
if (ui) ui.toggleCrafting();
}
// B Button (1) - Inventory
if (index === 1) {
const ui = this.scene.scene.get('UIScene');
if (ui) ui.toggleInventory();
}
});
}
attack() {
@@ -224,6 +269,24 @@ class Player {
if (ui.virtualJoystick.right) right = true;
}
// Check Gamepad Input (Xbox Controller)
if (this.scene.input.gamepad && this.scene.input.gamepad.total > 0) {
const pad = this.scene.input.gamepad.getPad(0);
if (pad) {
const threshold = 0.3;
if (pad.leftStick.y < -threshold) up = true;
if (pad.leftStick.y > threshold) down = true;
if (pad.leftStick.x < -threshold) left = true;
if (pad.leftStick.x > threshold) right = true;
// D-Pad support
if (pad.up) up = true;
if (pad.down) down = true;
if (pad.left) left = true;
if (pad.right) right = true;
}
}
// Apply
let dx = 0;
let dy = 0;
@@ -354,8 +417,12 @@ class Player {
// Optimization: Create dirty check
if (this.lastDepthY === undefined || Math.abs(this.sprite.y - this.lastDepthY) > 0.1) {
this.sprite.setDepth(this.sprite.y);
if (this.handSprite) this.handSprite.setDepth(this.sprite.y + 1);
// Uporabi LAYER_OBJECTS da se pravilno sortira z drevesi/kamni
const layerBase = this.iso.LAYER_OBJECTS || 200000;
const depth = layerBase + this.sprite.y;
this.sprite.setDepth(depth);
if (this.handSprite) this.handSprite.setDepth(depth + 1);
this.lastDepthY = this.sprite.y;
}
}