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 of layer update events

A good place is the OnLayerUpdate callback method of the engine class. Check if one of the scores is 5 or bigger, and then set the game mode and also display a message.

  1. Check if the score field of the game class is 5 or greater.
    Method OnLayerUpdate:Int(layer:ftLayer)
    If g.score >= 5 Then
    
  2. If yes, the player won. Activate the g.txtYouWin text object.
    g.txtYouWin.SetActive(True)
    
  3. Set the game mode to g.gmGameOver and stop the engine sound effect.
    g.gameMode = g.gmGameOver
    g.sndEngine.Stop()
    
  4. If the player score is lower than 5, check if the computer score is greater or equal to 5.
    Elseif g.scoreC >= 5 Then
    
  5. If yes, the computer won. Display the You Lose message by activating the g.txtYouLoose object.
    g.txtYouLoose.SetActive(True) ...

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