Skip to content
Snippets Groups Projects
Commit 01189057 authored by Paolo Brasolin's avatar Paolo Brasolin
Browse files

refactor: #fe FightScene

parent ac79adef
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,42 @@ export default class FightScene extends MainScene { ...@@ -17,6 +17,42 @@ export default class FightScene extends MainScene {
super("fight"); super("fight");
} }
async beforeGameStart() {
this.planBackgroundTransitions();
this.planMusicChanges();
this.planWaveAnnouncements();
await this.initBeDevice();
await this.initBeGame();
this.spawnFoes();
}
async afterGameEnd() {
this.beGame = (
await backend.updateGame(this.beGame.id, {
ended_at: new Date().toISOString(),
ended_at_gmtm: this.getGameTime(),
score: this.score,
})
).data;
this.spawner.remove();
this.scene.start("game_over", {
music: this.music,
words: this.acceptedWords,
score: this.beGame.score,
time: this.beGame.ended_at_gmtm,
});
}
//=[ Ambient transitions ]====================================================
planBackgroundTransitions() {
(this.scene.get("background") as BackgroundScene).atmosphere.play();
}
musicSoftReplace(nextMusic: Phaser.Sound.BaseSound) { musicSoftReplace(nextMusic: Phaser.Sound.BaseSound) {
this.music.on("looped", () => { this.music.on("looped", () => {
this.music.stop(); this.music.stop();
...@@ -39,6 +75,7 @@ export default class FightScene extends MainScene { ...@@ -39,6 +75,7 @@ export default class FightScene extends MainScene {
} }
planWaveAnnouncements() { planWaveAnnouncements() {
// TODO: parameterize
this.time.delayedCall(0 * 60 * 1000, () => this.time.delayedCall(0 * 60 * 1000, () =>
this.hud.announceWave("LEVEL 1"), this.hud.announceWave("LEVEL 1"),
); );
...@@ -56,15 +93,7 @@ export default class FightScene extends MainScene { ...@@ -56,15 +93,7 @@ export default class FightScene extends MainScene {
); );
} }
async beforeGameStart() { //=[ BE initialization ]======================================================
(this.scene.get("background") as BackgroundScene).atmosphere.play();
this.planMusicChanges();
this.planWaveAnnouncements();
await this.initBeDevice();
await this.initBeGame();
this.gameTime.paused = false;
this.spawnFoes();
}
async initBeDevice() { async initBeDevice() {
const deviceId = sessionStorage.getItem(DEVICE_KEY); const deviceId = sessionStorage.getItem(DEVICE_KEY);
...@@ -85,6 +114,8 @@ export default class FightScene extends MainScene { ...@@ -85,6 +114,8 @@ export default class FightScene extends MainScene {
).data; ).data;
} }
//=[ Game loop ]==============================================================
nthFibonacci(n: number) { nthFibonacci(n: number) {
return Math.round(Math.pow((1 + Math.sqrt(5)) / 2, n) / Math.sqrt(5)); return Math.round(Math.pow((1 + Math.sqrt(5)) / 2, n) / Math.sqrt(5));
} }
...@@ -232,22 +263,4 @@ export default class FightScene extends MainScene { ...@@ -232,22 +263,4 @@ export default class FightScene extends MainScene {
// TODO: this is a terrible pattern // TODO: this is a terrible pattern
await new Foe(this, timeout).initialize(length); await new Foe(this, timeout).initialize(length);
} }
async afterGameEnd() {
this.beGame = (
await backend.updateGame(this.beGame.id, {
ended_at: new Date().toISOString(),
ended_at_gmtm: this.getGameTime(),
score: this.score,
})
).data;
this.spawner.remove();
this.scene.start("game_over", {
music: this.music,
words: this.acceptedWords,
score: this.beGame.score,
time: this.beGame.ended_at_gmtm,
});
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment