Show overlay upon player death
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user