diff --git a/game/src/scenes/GameOverScene.ts b/game/src/scenes/GameOverScene.ts index 28ce75e..8c40e1f 100644 --- a/game/src/scenes/GameOverScene.ts +++ b/game/src/scenes/GameOverScene.ts @@ -26,25 +26,27 @@ export default class PlayScene extends Phaser.Scene { await window.updateTopList() } - console.log("Show end screen with data:", data) - this.add.image(250, 550, 'phaser-logo').setScale(0.5) this.add.image(550, 550, 'hs3-logo').setScale(0.5) this.add.text( this.cameras.main.centerX, - this.cameras.main.centerY - 100, + 110, "KONIEC GRY", { font: '64px Verdana', }).setOrigin(0.5, 0.5) const lines: string[] = [] - if (rank) { lines.push("Miejsce w rankingu: #" + rank) } + if (rank) { + lines.push("Aktualne miejsce w rankingu:") + lines.push("#" + rank) + lines.push("") + } lines.push("Punkty: " + pts) lines.push("Poziom: " + lvl) lines.push("Czas Gry: " + time + 's') - this.add.text(this.cameras.main.centerX, this.cameras.main.centerY, + this.add.text(this.cameras.main.centerX, 290, lines, { font: '32px Verdana', @@ -53,5 +55,19 @@ export default class PlayScene extends Phaser.Scene { }).setOrigin(0.5, 0.5) window.unfreezeGui() + + setTimeout(() => { + this.add.text(this.cameras.main.centerX, 450, + "Kliknij aby zacząć od nowa", + { + font: '32px Verdana', + align: 'center', + color: 'yellow' + }).setOrigin(0.5, 0.5) + + this.input.on('pointerup', () => { + this.scene.start('start-scene'); + }); + }, 5000) } } diff --git a/game/src/scenes/PlayScene.ts b/game/src/scenes/PlayScene.ts index 9aa4cd0..3932192 100644 --- a/game/src/scenes/PlayScene.ts +++ b/game/src/scenes/PlayScene.ts @@ -16,6 +16,7 @@ export default class PlayScene extends Phaser.Scene { backgroundOrder: number[] = [] backgroundId = 0 startTimestamp: number = 0 + gameOverState = false constructor() { super('play-scene') @@ -60,8 +61,10 @@ export default class PlayScene extends Phaser.Scene { } gameOver() { + if (this.gameOverState) return + console.log("%cU ded", "color:red") - console.log("points: ", this.difficulty!.getPoints()) + this.gameOverState = true this.scene.start('game-over-scene', { points: this.difficulty!.getPoints(), level: this.difficulty!.getLevel(), diff --git a/game/src/scenes/StartScene.ts b/game/src/scenes/StartScene.ts index 7a24dbe..7b3ea89 100644 --- a/game/src/scenes/StartScene.ts +++ b/game/src/scenes/StartScene.ts @@ -17,22 +17,31 @@ export default class StartScene extends Phaser.Scene { this.add.text( this.cameras.main.centerX, - this.cameras.main.centerY - 100, - "SPACE SMASHER 9001!", { + 130, + "SPACE SMASHER\n9001!", { font: '64px Verdana', + align: "center" }).setOrigin(0.5, 0.5) this.add.text(this.cameras.main.centerX, this.cameras.main.centerY, [ - "Naciśnij przycisk aby zacząć", + "Zaloguj się przed rozpoczęciem gry", + "za pomocą panelu na górze, aby zdobywać rekord.", "", - "Zaloguj się przed rozpoczęciem gry, aby zachować rekord", - "albo graj jako gość (bez rankingu)" + "Możesz też zagrać jako gość (bez rankingu)." ], { font: '21px Verdana', align: 'center', color: 'cyan' }).setOrigin(0.5, 0.5) + this.add.text(this.cameras.main.centerX, 450, + "Kliknij aby zacząć grę", + { + font: '32px Verdana', + align: 'center', + color: 'yellow' + }).setOrigin(0.5, 0.5) + this.input.on('pointerup', () => { window.freezeGui() this.scene.start('play-scene'); diff --git a/server/Database.js b/server/Database.js index bcf39ab..64fae38 100644 --- a/server/Database.js +++ b/server/Database.js @@ -48,6 +48,19 @@ class Database { .sort((a, b) => a.record > b.record ? -1 : 1) .slice(0, amount) } + + getRank(username) { + const users = this.db.data.users + .filter(user => user.record) + .sort((a, b) => a.record > b.record ? -1 : 1) + + for (let i = 0; i < users.length; ++i) { + if (users[i].name == username) + return i + 1 + } + + return 0 + } } export default new Database diff --git a/server/server.js b/server/server.js index 416d0f4..8b67213 100644 --- a/server/server.js +++ b/server/server.js @@ -78,9 +78,13 @@ app.post("/login", neededArguments(['key']), async (req, res) => { app.post("/record", protect, neededArguments(['points', 'shoots', 'time']), jg, async (req, res) => { db.updateRecord(req.user.name, req.body.points) + const rank = db.getRank(req.user.name) + + console.log(req.user, rank) res.json({ - status: "ok" + status: "ok", + rank: rank }) })