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

refactor: #fe extract useful stuff from HUD

parent cf2b555c
No related branches found
No related tags found
No related merge requests found
const ICONS = { export const ICONS = {
SCORE: "️⭐️", SCORE: "️⭐️",
CLOCK: "⏲️", CLOCK: "⏲️",
HEALTH: "❤️️", HEALTH: "❤️️",
...@@ -28,6 +28,17 @@ interface HudOptions { ...@@ -28,6 +28,17 @@ interface HudOptions {
inputPosition: number; inputPosition: number;
} }
export const formatTime = (milliseconds: number) => {
const minutes = Math.floor(milliseconds / 60000);
const seconds = Math.floor((milliseconds % 60000) / 1000)
.toString()
.padStart(2, "0");
const hundredths = Math.floor((milliseconds % 1000) / 10)
.toString()
.padStart(2, "0");
return `${minutes}:${seconds}.${hundredths}`;
};
export default class HUD { export default class HUD {
scene: Phaser.Scene; scene: Phaser.Scene;
options: HudOptions; options: HudOptions;
...@@ -118,16 +129,7 @@ export default class HUD { ...@@ -118,16 +129,7 @@ export default class HUD {
} }
setClock(milliseconds: number) { setClock(milliseconds: number) {
const minutes = Math.floor(milliseconds / 60000); this.clock.text = `${this.formatTime(milliseconds)}\u2009${ICONS.CLOCK}`;
const seconds = Math.floor((milliseconds % 60000) / 1000)
.toString()
.padStart(2, "0");
const hundredths = Math.floor((milliseconds % 1000) / 10)
.toString()
.padStart(2, "0");
const formatted = `${minutes}:${seconds}.${hundredths}`;
// TODO: we can probably do away with the clock icon
this.clock.text = `${formatted}\u2009${ICONS.CLOCK}`;
} }
showSubmitFeedback(color: string, input: string) { showSubmitFeedback(color: string, input: string) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment