Show overlay upon player death

This commit is contained in:
Peter Stockings
2026-01-04 16:06:08 +11:00
parent bfe5ebae8c
commit 6a050ac7a9
4 changed files with 287 additions and 0 deletions

View File

@@ -103,6 +103,11 @@ export class GameScene extends Phaser.Scene {
this.emitUIUpdate();
});
// Listen for game restart
this.events.on("restart-game", () => {
this.restartGame();
});
// Mouse click -> compute path (only during player turn, and not while menu/minimap is open)
this.input.on("pointerdown", (p: Phaser.Input.Pointer) => {
if (!this.awaitingPlayer) return;
@@ -234,6 +239,20 @@ export class GameScene extends Phaser.Scene {
}
}
// Check if player died
if (!this.world.actors.has(this.playerId)) {
this.syncRunStateFromPlayer(); // Save final stats for death screen
const uiScene = this.scene.get("GameUI") as any;
if (uiScene) {
uiScene.showDeathScreen({
level: this.levelIndex,
gold: this.runState.inventory.gold,
stats: this.runState.stats
});
}
return;
}
// Level transition
if (isPlayerOnExit(this.world, this.playerId)) {
this.syncRunStateFromPlayer();
@@ -285,6 +304,14 @@ export class GameScene extends Phaser.Scene {
};
}
private restartGame() {
this.runState = {
stats: { ...GAME_CONFIG.player.initialStats },
inventory: { gold: 0, items: [] }
};
this.loadLevel(1);
}
private centerCameraOnPlayer() {
const player = this.world.actors.get(this.playerId)!;
this.cameras.main.centerOn(