Skip to content

Commit

Permalink
Merge pull request #103 from trifle-labs/gameover-screen-polish
Browse files Browse the repository at this point in the history
gameover screen polish
  • Loading branch information
okwme authored Apr 10, 2024
2 parents be9618f + 3711c28 commit 92d1db5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/anybody.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
23 changes: 12 additions & 11 deletions src/visuals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -634,7 +634,6 @@ export const Visuals = {
drawScore() {
const { p } = this
p.push()
p.translate(20, 10)
p.fill('white')
p.noStroke()

Expand All @@ -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
}
Expand All @@ -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()
},
Expand Down

0 comments on commit 92d1db5

Please sign in to comment.