|
1 | 1 | import { Scene } from "phaser";
|
| 2 | +import { renderTextBanner } from "../banners.ts"; |
| 3 | +import { |
| 4 | + HALF_HEIGHT, |
| 5 | + HALF_WIDTH, |
| 6 | + PLAYER_ID_PAIR_DATA_KEY, |
| 7 | + QUARTER_HEIGHT, |
| 8 | + WIDTH, |
| 9 | +} from "../constants.ts"; |
| 10 | +import { getPlayerOverallScore } from "../scoring.ts"; |
2 | 11 |
|
3 | 12 | export class GameOver extends Scene {
|
4 |
| - gameover_text: Phaser.GameObjects.Text; |
5 |
| - |
6 | 13 | constructor() {
|
7 | 14 | super("GameOver");
|
8 | 15 | }
|
9 | 16 |
|
| 17 | + preload() { |
| 18 | + this.load.image("home", "assets/home.png"); |
| 19 | + } |
| 20 | + |
10 | 21 | create() {
|
11 |
| - this.gameover_text = this.add |
12 |
| - .text(512, 384, "Game Over", { |
13 |
| - fontFamily: "Arial Black", |
14 |
| - fontSize: 64, |
15 |
| - color: "#ffffff", |
16 |
| - stroke: "#000000", |
17 |
| - strokeThickness: 8, |
18 |
| - align: "center", |
19 |
| - }) |
20 |
| - .setOrigin(0.5); |
| 22 | + renderTextBanner(this, {}, { text: "Ngā mihi!", yOffset: 30 }); |
| 23 | + |
| 24 | + const playerIdPair = this.registry.get(PLAYER_ID_PAIR_DATA_KEY); |
| 25 | + const playerIds = playerIdPair.split("-"); |
| 26 | + const pairScore = getPlayerOverallScore(playerIdPair); |
| 27 | + renderTextBanner( |
| 28 | + this, |
| 29 | + { |
| 30 | + x: WIDTH / 8, |
| 31 | + y: HALF_HEIGHT, |
| 32 | + height: 120, |
| 33 | + width: (3 / 4) * WIDTH, |
| 34 | + }, |
| 35 | + { |
| 36 | + text: `Your Player IDs: ${playerIds[0]} / ${playerIds[1]}\nCompleted Shapes: ${pairScore.totalShapes} in ${Math.floor(pairScore.totalTime / 60)} minutes ${Math.floor(pairScore.totalTime % 60)} seconds.`, |
| 37 | + yOffset: 15, |
| 38 | + }, |
| 39 | + ); |
| 40 | + |
| 41 | + const homeButton = this.add |
| 42 | + .sprite(HALF_WIDTH, HALF_HEIGHT + QUARTER_HEIGHT, "home") |
| 43 | + .setDisplaySize(50, 50) |
| 44 | + .setInteractive(); |
21 | 45 |
|
22 |
| - this.input.once("pointerdown", () => { |
| 46 | + homeButton.on("pointerdown", () => { |
23 | 47 | this.scene.start("MainMenu");
|
24 | 48 | });
|
25 | 49 | }
|
|
0 commit comments