O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — acting on layer update events

  1. Modify the OnLayerUpdate method in the engine class.
    Method OnLayerUpdate:Int(layer:ftLayer)
    
  2. Check if the game mode is equal to g.gmPlay.
    If g.gameMode = g.gmPlay Then
    
  3. Check if the end time is equal to or smaller than the current Millisecs value. If yes, that means the game time ran out and you must show the 'game over' screen.
    If g.endTime <= Millisecs() Then
    g.ShowGameOver()
    
  4. Add the last score to the score list, and save the high-score list.
    g.eng.scoreList.AddScore(g.score,"---")
    g.SaveHighScore()
    
  5. Close the last two IF checks.
    Endif
    Endif
    Return 0
    End
    End
    

What just happened?

Because we now act on the fact that the time ran out, we can finally play the full game. If everything builds well, you could ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required