kockasta mapa

This commit is contained in:
2025-12-07 14:28:39 +01:00
parent 98059a2659
commit 045bf24792
11 changed files with 670 additions and 1249 deletions

View File

@@ -34,6 +34,11 @@ class NPC {
// Naključna začetna pavza
this.pauseTime = Math.random() * this.maxPauseTime;
// Register in SpatialGrid
if (this.scene.spatialGrid) {
this.scene.spatialGrid.add(this);
}
}
tame() {
@@ -221,6 +226,7 @@ class NPC {
if (this.isMoving) {
this.updateDepth();
this.updatePosition();
if (this.scene.spatialGrid) this.scene.spatialGrid.updateEntity(this);
return;
}
@@ -378,23 +384,31 @@ class NPC {
this.healthBarBg.y = this.sprite.y;
this.healthBar.x = this.sprite.x;
this.healthBar.y = this.sprite.y;
this.healthBarBg.setDepth(this.sprite.depth + 100);
this.healthBar.setDepth(this.sprite.depth + 101);
}
// EYES
if (this.eyesGroup) {
this.eyesGroup.setPosition(this.sprite.x, this.sprite.y);
this.eyesGroup.setDepth(this.sprite.depth + 2);
}
this.updateDepth();
}
updateDepth() {
if (this.sprite) {
if (!this.sprite) return;
if (this.lastDepthY === undefined || Math.abs(this.sprite.y - this.lastDepthY) > 0.1) {
this.sprite.setDepth(this.sprite.y);
this.lastDepthY = this.sprite.y;
// Update attached elements depth
if (this.healthBarBg) {
this.healthBarBg.setDepth(this.sprite.depth + 100);
this.healthBar.setDepth(this.sprite.depth + 101);
}
if (this.eyesGroup) {
this.eyesGroup.setDepth(this.sprite.depth + 2);
}
}
}
@@ -436,7 +450,10 @@ class NPC {
die() {
console.log('🧟💀 Zombie DEAD');
// Spawn loot - BONE
if (this.scene.interactionSystem && this.scene.interactionSystem.spawnLoot) {
if (this.scene.lootSystem) {
this.scene.lootSystem.spawnLoot(this.gridX, this.gridY, 'item_bone');
} else if (this.scene.interactionSystem && this.scene.interactionSystem.spawnLoot) {
// Fallback
this.scene.interactionSystem.spawnLoot(this.gridX, this.gridY, 'item_bone');
}
this.destroy();
@@ -492,6 +509,9 @@ class NPC {
}
destroy() {
if (this.scene.spatialGrid) {
this.scene.spatialGrid.remove(this);
}
if (this.sprite) this.sprite.destroy();
if (this.healthBar) this.healthBar.destroy();
if (this.healthBarBg) this.healthBarBg.destroy();