kockasta mapa
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -319,9 +319,13 @@ class Player {
|
||||
}
|
||||
|
||||
updateDepth() {
|
||||
if (this.sprite) {
|
||||
if (!this.sprite) return;
|
||||
|
||||
// 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);
|
||||
this.lastDepthY = this.sprite.y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user