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 — creating a StartNewGame method

This method will reset all score fields, deactivate the title layer, spawn the planes, and deactivate possibly visible status messages. It also starts the playback of the engine sound.

  1. Add a method called StartNewGame to the game class.
    Method StartNewGame:Int()
    
  2. Seed the random number generator with the current value of a call to Millisecs().
    Seed = Millisecs()
    
  3. Reset both score fields.
    score = 0
    scoreC = 0
    
  4. Deactivate the title layer.
    layerTitle.SetActive(False)
    
  5. Remove all existing objects on the game layer.
    layerGame.RemoveAllObjects()
    
  6. Set the default layer to be layerGame.
    eng.SetDefaultLayer(layerGame)
    
  7. Spawn the player and the enemy plane.
    SpawnPlayer()
    SpawnEnemy()
    
  8. Set the game mode to gmPlay.
    gameMode ...

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