Time for action — creating a StartNewGame method

To start a new game, we will create a new method in the game class. Follow the given steps:

  1. Add a new method called StartNewGame.
    Method StartNewGame:Int()
    
  2. Seed the random number generator with the current millisecond value:
    Seed = Millisecs()
    
  3. Reset the Score value to 0, as shown in the following code:
    Score = 0
    
  4. Deactivate the title layer:
    layerTitle.SetActive(False)
    
  5. Remove all objects from the game layer:
    layerGame.RemoveAllObjects()
    
  6. Create a new ball:
    CreateBall()
    
  7. Create a new set of tiles:
    CreateTiles()
    
  8. Spawn a new enemy with a random x position. This position ranges from 20 to cw-20 (the canvas width minus 20):
    SpawnEnemy(Rnd(20,cw-20))
    
  9. Start with a level number of 1:
    levelNum = 1
    
  10. Set lifes to 3:
    lifes = 3
    
  11. Finally, set the game mode to gmPlay, and then close the method:
    gameMode = gmPlay
    Return 0
    End
    

What just happened?

This method reset all the game variables and started a new game. It brought up the game and background layer and created the ball, the tiles, and an enemy.

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

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