We will display Game Over by following the ensuing steps:
Create a new method called ShowGameOver inside the game class.
Method ShowGameOver:Int()
Set the game mode to gmGameOver and activate layers with it.
gameMode = gmGameOver
ActivateLayer(gameMode)
Set the final score text object with the score value. Then, close the method.
txtFinalScore.SetText("SCORE: "+score)
Return 0
End
What just happened?
This method will take care of showing the 'game over' screen.
Showing the menu screen
Usually, you don't need an extra method to show a layer, but if you do this in multiple places in your code, it makes sense to add a method for it and just call it. It helps in reducing the length of your code by removing redundant lines.