Hide sprites of corpses when in fog of war

This commit is contained in:
Peter Stockings
2026-01-27 15:56:32 +11:00
parent a15bb3675b
commit 7260781f38
4 changed files with 120 additions and 10 deletions

View File

@@ -5,7 +5,7 @@ import { GAME_CONFIG } from "../core/config/GameConfig";
export class FxRenderer {
private scene: Phaser.Scene;
private corpseSprites: Phaser.GameObjects.Sprite[] = [];
private corpseSprites: { sprite: Phaser.GameObjects.Sprite; x: number; y: number }[] = [];
constructor(scene: Phaser.Scene) {
this.scene = scene;
@@ -34,8 +34,8 @@ export class FxRenderer {
}
clearCorpses() {
for (const sprite of this.corpseSprites) {
sprite.destroy();
for (const entry of this.corpseSprites) {
entry.sprite.destroy();
}
this.corpseSprites = [];
}
@@ -142,7 +142,26 @@ export class FxRenderer {
);
corpse.setDepth(50);
corpse.play(`${textureKey}-die`);
this.corpseSprites.push(corpse);
this.corpseSprites.push({ sprite: corpse, x, y });
}
updateVisibility(seen: Uint8Array, visible: Uint8Array, worldWidth: number) {
for (const entry of this.corpseSprites) {
const idx = entry.y * worldWidth + entry.x;
const isSeen = seen[idx] === 1;
const isVisible = visible[idx] === 1;
entry.sprite.setVisible(isSeen);
if (isSeen) {
if (isVisible) {
entry.sprite.setAlpha(1);
entry.sprite.clearTint();
} else {
entry.sprite.setAlpha(0.4);
entry.sprite.setTint(0x888888);
}
}
}
}
showWait(x: number, y: number) {