Skip to content

Commit 3a878d4

Browse files
committed
Made Death Screen better
- Double-Jumps will now be displayed - Forgot to remove debug score set - Button press function is now otional - Made GameOver Screen Navigation better
1 parent 81429bd commit 3a878d4

File tree

9 files changed

+70
-36
lines changed

9 files changed

+70
-36
lines changed

public/hud/buttons/jumpsLeft.png

304 Bytes
Loading

src/game/custom_classes/Button.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ export class Button {
1212
keyboardKey?: Input.Keyboard.Key;
1313
gamepadButtonIndex?: number;
1414
isFocused: boolean = false;
15-
onButtonPressed: Function;
15+
onButtonPressed?: Function;
1616
gamepadCheckActive: boolean = false;
1717
buttonManager?: ButtonManager;
1818

1919
// Constructor
20-
constructor(x: number, y: number, scale: number, image: string, curScene: Scene, onButtonPressed: Function, keyboardKey?: string, gamepadButtonIndex?: number, buttonManager?: ButtonManager) {
20+
constructor(x: number, y: number, scale: number, image: string, curScene: Scene, onButtonPressed?: Function, keyboardKey?: string, gamepadButtonIndex?: number, buttonManager?: ButtonManager) {
2121
//initialise variables
2222
this.x = x; //x position
2323
this.y = y; //y position
2424
this.image = image; //image as string
25-
this.scene = curScene; //the scene the button is in (this)
25+
this.scene = curScene; //in the scene the button is in (this)
2626
this.onButtonPressed = onButtonPressed;
27-
this.gamepadButtonIndex = gamepadButtonIndex;
27+
this.gamepadButtonIndex = gamepadButtonIndex; // does this even work?
2828
this.buttonManager = buttonManager;
2929

3030
// add buttons to the current scene (just "this" in the scene you implement the buttons)
@@ -80,7 +80,7 @@ export class Button {
8080

8181
activate(): void {
8282
this.setFocus(true);
83-
this.onButtonPressed();
83+
if (this.onButtonPressed) this.onButtonPressed();
8484
// Reset focus after a short delay if not managed by ButtonManager
8585
if (!this.buttonManager) {
8686
this.scene.time.delayedCall(200, () => {

src/game/loader/Boot.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class Boot extends Scene {
3030
this.load.image("button_default", "default.png");
3131
this.load.image("button_gifts", "gifts.png");
3232
this.load.image("button_highscore", "highscore.png");
33+
this.load.image("button_jumpsLeft", "jumpsLeft.png");
3334
this.load.image("button_keyboard", "keyboard.png");
3435
this.load.image("button_leaderboard", "leaderboard.png");
3536
this.load.image("button_music", "music.png");

src/game/main.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {Controls} from './scenes/Controls.ts';
99
import Image = Phaser.GameObjects.Image;
1010
import {ThatGame} from './thatFolder/ThatGame.ts';
1111
import {Leaderboard} from './scenes/Leaderboard.ts';
12+
import Gamepad = Phaser.Input.Gamepad.Gamepad;
13+
import { get3 } from "./thatFolder/ThatPlayer.ts";
1214

1315
// Config
1416
const gameW: number = 1024;
@@ -94,11 +96,18 @@ export function displayDebug(scene: Scene): void {
9496
}
9597

9698
// Adds a Shortcut to exit the current menu
97-
export function escapeOption(that: Scene): void {
99+
export function escapeOption(that: Scene, gamepad?: Gamepad): void {
98100
const escKey = that.input.keyboard?.addKey('ESC');
99101
escKey?.on('down', () => {
100102
that.scene.start('mainMenu');
101103
});
102104

105+
if (gamepad) {
106+
if (get3(gamepad)) {
107+
that.scene.start('mainMenu');
108+
return;
109+
}
110+
}
111+
103112
// TODO | add controller 2 -> mainMenu
104113
}

src/game/scenes/Controls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class Controls extends Phaser.Scene {
5454
// Back button
5555
this.back_button = new Button(globalConsts.gameWidth * 0.5, globalConsts.gameHeight * 0.25, 4, 'button_back', this, () => {
5656
this.scene.start('mainMenu')
57-
}, 'B', 0, this.buttonManager);
57+
}, 'B', 3, this.buttonManager);
5858

5959
// Add navigation instructions
6060
this.add.text(globalConsts.gameWidth * 0.5, globalConsts.gameHeight * 0.9, 'Drücke B oder ESC zum Zurückkehren', {

src/game/scenes/Credits.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const roleColor: string = '#000000';
99
const nameColor: string = '#000000';
1010
const jsonPath: string = "./src/game/scenes/creditsConfig.json";
1111

12+
// TODO | add "thanks to all testers"
1213
export class Credits extends Phaser.Scene {
1314
// Types
1415
creditTexts: Phaser.GameObjects.Text[];

src/game/scenes/GameOver.ts

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {Scene} from 'phaser';
22
import {displayPlayer, globalConsts} from '../main.ts';
3-
import {formatTime} from '../thatFolder/ThatPlayer.ts';
3+
import {formatTime, get1, get3} from '../thatFolder/ThatPlayer.ts';
44
import {Button} from '../custom_classes/Button.ts';
55
import {ButtonManager} from '../custom_classes/ButtonManager.ts';
66
import Text = Phaser.GameObjects.Text;
7-
import Rectangle = Phaser.GameObjects.Rectangle;
87
import {fetchLeaderboard, removeEntry, sortedLeaderboard, sortLeaderboard} from './Leaderboard.ts';
8+
import Gamepad = Phaser.Input.Gamepad.Gamepad;
99

1010
// config
1111
const range: number = 2;
@@ -26,7 +26,9 @@ let leaderboardText: Phaser.GameObjects.Text;
2626
let gameOverImage: Phaser.GameObjects.Image;
2727
let saveButton: Button;
2828
let leaderboardIsLoaded: boolean = false;
29+
let savedScore: boolean = false;
2930
let buttonManager: ButtonManager;
31+
let gamePad: Gamepad;
3032

3133
// Scene class
3234
export class GameOver extends Scene {
@@ -48,12 +50,6 @@ export class GameOver extends Scene {
4850
// Creates the button manager
4951
buttonManager = new ButtonManager(scene);
5052

51-
// Adds the restart button (invisible but functional for keyboard/gamepad)
52-
new Button(globalConsts.gameWidth / 2, globalConsts.gameHeight * 0.85, 1, "button_play", scene, () => {
53-
window.location.reload();
54-
}, 'ENTER', 2, buttonManager).button.setVisible(false);
55-
56-
5753
// GameOver Image
5854
gameOverImage = this.add.image(512, 250, 'gameOverTitle');
5955
gameOverImage.setScale(0.2);
@@ -62,45 +58,70 @@ export class GameOver extends Scene {
6258
leaderboardText = scene.add.text(500, 290, "", style).setOrigin(0, 0);
6359

6460
// gets score
65-
const item: string | null = localStorage.getItem("score");
61+
const item: string | null = localStorage.getItem("last.score");
6662
score = parseInt(item ? item : "0", 10);
6763

6864
// Game infos
69-
new Button(130, 298, 4, "button_yourScore", this.scene.scene, () => {
70-
});
71-
this.add.text(245, 290, formatTime(score), style).setOrigin(0, 0);
65+
new Button(70, 298, 4, "button_yourScore", this.scene.scene).button.setOrigin(0, 0.5);
66+
this.add.text(265, 290, formatTime(score), style).setOrigin(0, 0);
67+
68+
new Button(70, 338, 4, "button_jumpsLeft", this.scene.scene).button.setOrigin(0, 0.5);
69+
this.add.text(265, 330, localStorage.getItem("last.jumpsLeft") ?? "0", style).setOrigin(0, 0);
7270

7371
// Renders leaderboard
7472
renderLeaderboard().then();
7573

74+
75+
// Adds the restart button
76+
new Button(globalConsts.gameWidth * 0.8, globalConsts.gameHeight * 0.85, 5, "button_play", scene, () => exit(), 'ENTER', 3, buttonManager).button.setVisible(true);
77+
7678
// Save score button
77-
saveButton = new Button(700, 650, 7, "button_save", scene, () => prompt(), 'S', 0, buttonManager);
78-
79-
// Clicker
80-
const blocker: Rectangle = this.add.rectangle(0, 0, globalConsts.gameWidth, globalConsts.gameHeight, 0x000000, 0)
81-
.setOrigin(0)
82-
.setInteractive();
83-
blocker.setDepth(-1);
84-
blocker.once('pointerdown', () => {
85-
window.location.reload();
86-
});
79+
saveButton = new Button(600, 650, 7, "button_save", scene, () => prompt(), 'S', 1, buttonManager);
8780

8881
// Add navigation instructions
89-
scene.add.text(globalConsts.gameWidth * 0.67, globalConsts.gameHeight * 0.92, "Press S to save", {
82+
scene.add.text(globalConsts.gameWidth * 0.67, globalConsts.gameHeight * 0.92, "Press S or 1 to save", {
9083
font: "16px " + globalConsts.pixelFont,
9184
color: "#ffffff",
9285
align: 'center'
9386
}).setOrigin(0.5);
9487

95-
scene.add.text(globalConsts.gameWidth * 0.67, globalConsts.gameHeight * 0.95, "Press ENTER to restart", {
88+
scene.add.text(globalConsts.gameWidth * 0.67, globalConsts.gameHeight * 0.95, "Press ENTER or 3 to restart", {
9689
font: "16px " + globalConsts.pixelFont,
9790
color: "#ffffff",
9891
align: 'center'
9992
}).setOrigin(0.5);
93+
94+
// Sets gamepad
95+
if (this.input.gamepad && this.input.gamepad.gamepads.length > 0) {
96+
gamePad = this.input.gamepad.getPad(0);
97+
}
10098
}
99+
100+
update(): void {
101+
// 1 -> Save
102+
if (get1(gamePad)) {
103+
prompt();
104+
return;
105+
}
106+
107+
// 3 -> back
108+
if (get3(gamePad)) {
109+
exit();
110+
return
111+
}
112+
}
113+
}
114+
115+
// Exit to the main Menu
116+
function exit(): void {
117+
window.location.reload();
101118
}
102119

120+
// Prompt to save
103121
function prompt(): void {
122+
// Already saved score | TODO | fix me
123+
if (savedScore) return;
124+
104125
// Check if the leaderboard is loaded
105126
if (!leaderboardIsLoaded) {
106127
alert("The leaderboard could not be loaded\nAnd therefore no score can be uploaded");
@@ -119,7 +140,7 @@ function prompt(): void {
119140
return;
120141
}
121142

122-
/// Neither does xxx
143+
// Neither does xxx
123144
if (prompt.toLowerCase() == "xxx") {
124145
alert("xxx doesn't work either");
125146
return;
@@ -157,9 +178,9 @@ function prompt(): void {
157178
clearsLeaderboardLine();
158179
renderLeaderboard();
159180

160-
// Resets button
181+
// Disables button
161182
saveButton.setImage("button_saved");
162-
saveButton.button.removeListener("pointerdown");
183+
savedScore = true;
163184
})
164185
}
165186

src/game/scenes/MainMenu.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ export class MainMenu extends Scene {
5050
}
5151

5252
// Add navigation instructions
53-
this.add.text(this.gameW * 0.7, this.gameH * 0.9, 'Navigation: Arrow keys, Tab, Space\nor Gamepad D-Pad/Stick', {
53+
this.add.text(this.gameW * 0.67, this.gameH * 0.9, 'Navigation: Arrow keys, Tab, Space\nor Gamepad Stick and 2', {
5454
font: "16px " + globalConsts.pixelFont,
5555
color: "#000000",
56+
lineSpacing: 3,
5657
align: 'center'
5758
}).setOrigin(0.5);
5859
}

src/game/thatFolder/ThatGame.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ export class ThatGame extends Phaser.Scene {
192192
}
193193

194194
// Saves score
195-
localStorage.setItem("score", String(1800)) // this.player.score.toString()
195+
localStorage.setItem("last.score", this.player.score.toString());
196+
localStorage.setItem("last.jumpsLeft", this.player.jumpLefts.toString());
196197

197198
// Switch du different scene
198199
this.scene.start("gameOver");

0 commit comments

Comments
 (0)