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 = gmPlay
    
  9. Deactivate the text objects that display whether or not you have won.
    txtYouWin.SetActive(False)
    txtYouLoose.SetActive(False)
    
  10. Start playing the engine sound, and then close this method.
    sndEngine.Play()
    Return 0
    End
    

What just happened?

We will set up a new game with this method. It resets some data fields and spawns both planes. It also switches the game into the play mode. We can now modify the update process of the game.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.124.21