Skip to content

Commit 839e198

Browse files
committed
rejig string displays
1 parent 2fc67e2 commit 839e198

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

src/game/scenes/GameOverScene.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import Phaser from "phaser";
22

33
export class GameOverScene extends Phaser.Scene {
4+
private score: number = 0;
5+
6+
init(data: { score: number }) {
7+
this.score = data.score;
8+
}
9+
410
constructor() {
511
super("GameOverScene");
612
}
@@ -9,23 +15,31 @@ export class GameOverScene extends Phaser.Scene {
915
const { width, height } = this.cameras.main;
1016
document.fonts.load('16px "Monogram"').then(() => {
1117
this.add
12-
.text(width / 2, height / 2 - 10, "BUSTED!", {
18+
.text(width / 2, height / 2 - 32, "BUSTED!", {
19+
fontFamily: "Monogram",
20+
fontSize: "16px",
21+
color: "#0f380f",
22+
})
23+
.setOrigin(0.5);
24+
25+
this.add
26+
.text(width / 2, height / 2 - 16, `YOUR SCORE: ${this.score}`, {
1327
fontFamily: "Monogram",
1428
fontSize: "16px",
1529
color: "#0f380f",
1630
})
1731
.setOrigin(0.5);
1832

1933
this.add
20-
.text(width / 2, height / 2 + 10, "Press Backspace to go back", {
34+
.text(width / 2, height / 2 + 16, "Press Enter to continue", {
2135
fontFamily: "Monogram",
2236
fontSize: "16px",
2337
color: "#0f380f",
2438
})
2539
.setOrigin(0.5);
2640
});
2741

28-
this.input.keyboard?.once("keydown-BACKSPACE", () =>
42+
this.input.keyboard?.once("keydown-ENTER", () =>
2943
this.scene.start("MenuScene")
3044
);
3145
}

src/game/scenes/GameScene.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export class GameScene extends Phaser.Scene {
1111
private obstacles: Obstacle[] = [];
1212
private obstacleTimer: number = 0;
1313

14+
private score: number = 0;
15+
private scoreText!: Phaser.GameObjects.Text;
16+
private scoreTimer!: Phaser.Time.TimerEvent;
17+
1418
private switchy!: Phaser.GameObjects.Sprite;
1519

1620
private background!: Phaser.GameObjects.TileSprite;
@@ -54,6 +58,7 @@ export class GameScene extends Phaser.Scene {
5458

5559
create() {
5660
this.gameEnded = false;
61+
this.score = 0;
5762
// Get current game dimensions
5863
const gameWidth = this.cameras.main.width;
5964
const gameHeight = this.cameras.main.height;
@@ -70,6 +75,26 @@ export class GameScene extends Phaser.Scene {
7075
// Load sprites from asset handler
7176
SpriteAssets.createSprites(this);
7277

78+
document.fonts.load('24px "Monogram"').then(() => {
79+
this.scoreText = this.add
80+
.text(8, 0, `${this.score}`, {
81+
fontFamily: "Monogram",
82+
fontSize: "24px",
83+
color: "#0f380f",
84+
})
85+
.setOrigin(0, 0)
86+
.setDepth(1000);
87+
});
88+
89+
this.scoreTimer = this.time.addEvent({
90+
delay: 2000,
91+
loop: true,
92+
callback: () => {
93+
this.score++;
94+
this.scoreText.setText(`${this.score}`);
95+
},
96+
});
97+
7398
// Set up Switchy (the player character)
7499
this.player = new Player(this, gameWidth / 2, gameHeight - 16, "switchy");
75100

@@ -127,9 +152,12 @@ export class GameScene extends Phaser.Scene {
127152

128153
handlePlayerHit() {
129154
if (this.gameEnded) return;
155+
this.scoreTimer.remove(false);
130156
this.physics.pause();
131157
this.gameEnded = true;
132-
this.playWipeTransition(() => this.scene.start("GameOverScene"));
158+
this.playWipeTransition(() =>
159+
this.scene.start("GameOverScene", { score: this.score })
160+
);
133161
}
134162

135163
playWipeTransition(onComplete: () => void) {

src/game/scenes/MenuScene.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ export class MenuScene extends Phaser.Scene {
2828
color: "#0f380f",
2929
})
3030
.setOrigin(0.5, 0.5);
31+
3132
this.add
3233
.text(width / 2, height - 16, "2025 heidi@wooting", {
3334
fontFamily: "Monogram",
34-
fontSize: "14px",
35+
fontSize: "16px",
3536
color: "#0f380f",
3637
})
3738
.setOrigin(0.5, 0.5);
39+
3840
this.add
3941
.text(width / 2, height / 2 - 12, "TAX FRAUD", {
4042
fontFamily: "Monogram",

0 commit comments

Comments
 (0)