Skip to content

Commit 84d1827

Browse files
Bricks Shape final score screen
1 parent 1e4db84 commit 84d1827

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

games/bricks-shape/src/banners.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ export function renderTextBanner(
4747
) {
4848
renderBanner(scene, bannerParams);
4949

50-
const { x: bannerX = HALF_WIDTH, y: bannerY = QUARTER_HEIGHT } = bannerParams;
50+
const { y: bannerY = QUARTER_HEIGHT } = bannerParams;
5151

5252
const { text, yOffset } = textParams;
53-
renderText(scene, bannerX, bannerY + yOffset, text);
53+
renderText(scene, HALF_WIDTH, bannerY + yOffset, text);
5454
}
5555

5656
export function renderText(

games/bricks-shape/src/scenes/GameOver.ts

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
11
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";
211

312
export class GameOver extends Scene {
4-
gameover_text: Phaser.GameObjects.Text;
5-
613
constructor() {
714
super("GameOver");
815
}
916

17+
preload() {
18+
this.load.image("home", "assets/home.png");
19+
}
20+
1021
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();
2145

22-
this.input.once("pointerdown", () => {
46+
homeButton.on("pointerdown", () => {
2347
this.scene.start("MainMenu");
2448
});
2549
}

0 commit comments

Comments
 (0)