diff --git a/Games/TutoPhaser/src/game/scenes/Game.ts b/Games/TutoPhaser/src/game/scenes/Game.ts index b2626b8..33cd8c8 100644 --- a/Games/TutoPhaser/src/game/scenes/Game.ts +++ b/Games/TutoPhaser/src/game/scenes/Game.ts @@ -19,6 +19,10 @@ export class Game extends Scene { super("Game"); } + init() { + this.score = 0; + } + create(): void { this.gameOver = false; @@ -176,7 +180,7 @@ export class Game extends Scene { player.setTint(0xff0000); player.anims.play("turn"); this.gameOver = true; - this.changeScene("GameOver"); + this.changeScene("GameOver", this.score); } private collectStar(player: GameObjectWithBody | Tile, star: GameObjectWithBody | Tile): void { @@ -216,9 +220,9 @@ export class Game extends Scene { } } - changeScene(scene?: string) { + changeScene(scene?: string, score?: number): void { if (scene) { - this.scene.start(scene); + this.scene.start(scene, { score }); } else { this.scene.start("Boot"); } diff --git a/Games/TutoPhaser/src/game/scenes/GameOver.ts b/Games/TutoPhaser/src/game/scenes/GameOver.ts index 680e172..8439305 100644 --- a/Games/TutoPhaser/src/game/scenes/GameOver.ts +++ b/Games/TutoPhaser/src/game/scenes/GameOver.ts @@ -5,11 +5,17 @@ export class GameOver extends Scene { camera: Phaser.Cameras.Scene2D.Camera; background: Phaser.GameObjects.Image; gameOverText: Phaser.GameObjects.Text; + gameOverSubText: Phaser.GameObjects.Text; + score: number = 0; constructor() { super("GameOver"); } + init(data: { score?: number }) { + this.score = data?.score || 0; + } + create() { this.camera = this.cameras.main; this.camera.setBackgroundColor(0xff0000); @@ -29,6 +35,18 @@ export class GameOver extends Scene { .setOrigin(0.5) .setDepth(100); + this.gameOverSubText = this.add + .text(400, 360, `Score: ${this.score}`, { + fontFamily: "Arial Black", + fontSize: 44, + color: "#ffffff", + stroke: "#000000", + strokeThickness: 8, + align: "center", + }) + .setOrigin(0.5) + .setDepth(100); + EventBus.emit("current-scene-ready", this); }