space-smasher-9001/game/src/scenes/GameOverScene.ts

80 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-10-17 17:08:16 +02:00
import Phaser from 'phaser'
2021-10-17 23:47:52 +02:00
import API from "../api"
2021-10-17 17:08:16 +02:00
export default class PlayScene extends Phaser.Scene {
constructor() {
super('game-over-scene')
}
preload() {
this.load.image('phaser-logo', 'assets/img/phaser3-logo.png')
this.load.image('hs3-logo', 'assets/img/hs3-logo.png')
}
2021-10-17 23:47:52 +02:00
async create(data) {
2021-10-18 00:23:15 +02:00
const pts = data.points || 0
const lvl = data.level || 0
const shts = data.shoots || 0
const time = Math.ceil(data.elapsedTime || 0)
let rank = 0
if (window.myStuff.token) {
const response = await API.record(pts, shts, time)
2021-10-18 02:33:29 +02:00
if (response.error) {
console.log("%c" + response.error, "color:red")
}
2021-10-18 01:53:50 +02:00
if (response.rank) {
rank = response.rank
await window.updateTopList()
}
2021-10-18 00:23:15 +02:00
}
2021-10-17 17:08:16 +02:00
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,
2021-10-18 00:44:02 +02:00
110,
2021-10-17 17:08:16 +02:00
"KONIEC GRY", {
2021-10-17 18:06:51 +02:00
font: '64px Verdana',
2021-10-17 17:08:16 +02:00
}).setOrigin(0.5, 0.5)
2021-10-18 00:23:15 +02:00
const lines: string[] = []
2021-10-18 00:44:02 +02:00
if (rank) {
lines.push("Aktualne miejsce w rankingu:")
lines.push("#" + rank)
lines.push("")
}
2021-10-18 00:23:15 +02:00
lines.push("Punkty: " + pts)
lines.push("Poziom: " + lvl)
lines.push("Czas Gry: " + time + 's')
2021-10-17 17:08:16 +02:00
2021-10-18 00:44:02 +02:00
this.add.text(this.cameras.main.centerX, 290,
2021-10-18 00:23:15 +02:00
lines,
{
font: '32px Verdana',
align: 'center',
color: 'cyan'
}).setOrigin(0.5, 0.5)
2021-10-17 23:47:52 +02:00
window.unfreezeGui()
2021-10-18 00:44:02 +02:00
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)
2021-10-17 17:08:16 +02:00
}
}