From 3711c2897792e20e6b4b3bd967c47522d224dbed Mon Sep 17 00:00:00 2001 From: psugihara Date: Tue, 9 Apr 2024 15:25:05 -0700 Subject: [PATCH] gameover screen: fix text centering, bigger text, delay help message 2 seconds --- src/anybody.js | 9 ++++++++- src/visuals.js | 23 ++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/anybody.js b/src/anybody.js index 4d6081d4..d6d1a2d6 100644 --- a/src/anybody.js +++ b/src/anybody.js @@ -90,6 +90,7 @@ export class Anybody extends EventEmitter { this.gameOver = false this.firstFrame = true this.loaded = false + this.showPlayAgain = false } // run once at initilization @@ -240,7 +241,13 @@ export class Anybody extends EventEmitter { this.sound?.playGameOver() this.gameOver = true this.won = won - this.emit('gameOver', {won}) + this.setShowPlayAgain() + this.emit('gameOver', { won }) + } + + setShowPlayAgain = async () => { + await new Promise((resolve) => setTimeout(resolve, 2000)) + this.showPlayAgain = true } setPause(newPauseState = !this.paused) { diff --git a/src/visuals.js b/src/visuals.js index 8fca0a88..82aa055e 100644 --- a/src/visuals.js +++ b/src/visuals.js @@ -236,7 +236,7 @@ export const Visuals = { if ( this.mode == 'game' && - this.frames - this.startingFrame < this.timer && + this.frames - this.startingFrame + FPS < this.timer && this.bodies.reduce((a, c) => a + c.radius, 0) != 0 ) { this.drawGun() @@ -634,7 +634,6 @@ export const Visuals = { drawScore() { const { p } = this p.push() - p.translate(20, 10) p.fill('white') p.noStroke() @@ -646,20 +645,22 @@ export const Visuals = { if (this.gameOver) { this.scoreSize = initialScoreSize - p.textSize(100) + p.textSize(128) // game over in the center of screen p.textAlign(p.CENTER) p.text( this.won ? 'SUCCESS' : 'GAME OVER', this.windowWidth / 2, - this.windowHeight / 2 - 60 - ) - p.textSize(50) - p.text( - 'Click to play again', - this.windowWidth / 2, - this.windowHeight / 2 + 60 + this.windowHeight / 2 - 69 // place the crease of the R on the line ) + p.textSize(40) + if (this.showPlayAgain) { + p.text( + 'Click to play again', + this.windowWidth / 2, + this.windowHeight / 2 + 60 + ) + } p.pop() return } @@ -677,7 +678,7 @@ export const Visuals = { } p.textSize(this.scoreSize) - p.text(secondsLeft.toFixed(0), 0, 0) + p.text(secondsLeft.toFixed(0), 20, 10) p.pop() },