From 631fbd3a6567afa5ed9c5f8bb5fe1f32480fabc6 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Fri, 17 Jul 2026 15:19:40 -0400 Subject: Update --- 2026/games_submissions/cammymoop/js/stopwatch.js | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 2026/games_submissions/cammymoop/js/stopwatch.js (limited to '2026/games_submissions/cammymoop/js/stopwatch.js') diff --git a/2026/games_submissions/cammymoop/js/stopwatch.js b/2026/games_submissions/cammymoop/js/stopwatch.js new file mode 100644 index 0000000..4578ee9 --- /dev/null +++ b/2026/games_submissions/cammymoop/js/stopwatch.js @@ -0,0 +1,59 @@ + +M.Stopwatch = class extends Phaser.GameObjects.Container +{ + constructor(scene, totalSeconds, pos) { + super(scene); + this.setPosVec(pos); + + this.elapsed = 0; + this.totalSeconds = totalSeconds; + + this.frame = new Phaser.GameObjects.Image(scene, 0, -3, 'stopwatch_frame'); + this.add(this.frame); + this.tens = new Phaser.GameObjects.Image(scene, 0, 0, 'stopwatch_numbers', 0); + this.add(this.tens); + this.tens.setOrigin(1, 0.5); + this.ones = new Phaser.GameObjects.Image(scene, 0, 0, 'stopwatch_numbers', 0); + this.add(this.ones); + this.ones.setOrigin(0, 0.5); + + this.addToDisplayList(); + this.addToUpdateList(); + this.showNumber(totalSeconds - 1); + } + + pause() { + this.removeFromUpdateList(); + } + + resume() { + this.addToUpdateList(); + } + + getTimeLeft() { + return this.totalSeconds * 1000 - this.elapsed; + } + + setupHint(height, hintData) { + this.addHintData(hintData); + this.hint.y = -height; + } + + preUpdate (t, dt) { + this.elapsed += dt; + + const dispSeconds = Math.max(0, Math.floor(this.totalSeconds - (this.elapsed / 1000))); + this.showNumber(dispSeconds); + + if (this.elapsed / 1000 > this.totalSeconds) { + this.scene.nowFinished(false, true); + this.pause(); + } + } + + showNumber(dispNumber) { + const num = Math.round(dispNumber) % 100; + this.tens.setFrame(Math.floor(num / 10)); + this.ones.setFrame(num % 10); + } +}; -- cgit v1.3.1