Coding a "Game Over" Screen

I’ve got a project due tomorrow – a game that requires a game over screen.

The problem is, I don’t know how to properly get one working. Rather than the screen appearing as soon as you get hit by an enemy, it appears after 5 seconds have passed (this is how it’s supposed to work; I just can’t get the screen itself to show up, after the 5 seconds have passed).

For a more detailed explanation, it should work like this: get hit --> timer begins --> timer runs out
–> game over screen (this screen should be unaffected by anything else in the game; it disappears whenever you collect a power up, which is something I’m trying to fix, but don’t know how to)

Any help with this would be very much appreciated!

(I can’t upload the game itself, apparently, so I apologize if my explanation itself wasn’t thorough enough. If more detail is needed, I’d be happy to provide what I can!)

1 Like

[1] Declare a window.gameOver boolean variable and initialize it to false on a Default tab script.
[2] Declare a window.goCounter variable and initialize it to 0
[3] When the enemy hits you, change the gameOver value to true.
[4] have a new logic like…

// At Default tab:

window.gameOver = false;
window.goCounter = 0;

// At an Update tab:

if (gameOver) {
    if(goCounter++ > project.framerate * 5) {
        // put logic for the Game Over splash to appear...
        // then set gameOver back to false to prevent these lines to execute again...
    }
}
3 Likes

That’s good to know, thank you!

Let me know if you make it work.

I couldn’t get it to work, myself (just because the code I’d initially written was a bit of a mess, so I couldn’t get it all working in conjunction with itself), but if I ever need to code something like this again, I’ll make sure to try your advice out again – thank you!

We’ll always be here to help! Also, if you ever make any more games or want to help us make some just ask!