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 to0
, 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
tocw-20
(the canvas width minus 20):SpawnEnemy(Rnd(20,cw-20))
9. Start with a level number of
1:
levelNum = 1
10. Set
lifes
to3:
lifes = 3
11. Finally, set the game mode to
gmPlay
, and then close the method:gameMode = gmPlay Return 0 End