Time for action — modifying the UpdateGame method

To modify the UpdateGame method, we will follow the ensuing steps:

  1. We need to modify the UpdateGame method in the mainClass.monkey file.
    Method UpdateGame:Int()
    
  2. Check if a random number is equal to 100 and the current active bombs are not more than the level number.
    If Rnd(0,100) > 99 And (GetBombsCount() < levelNumber) Then
    
  3. Create a new bomb.
    CreateBomb()
    Endif
    UpdateLaunchers()
    UpdateBombs()
    UpdateRockets()
    UpdateExplosions()
    
  4. If no city is left, remove all rockets, bombs, and explosions, and set the game mode to gmGameOver.
    If GetCityCount() = 0 Then
    RemoveRockets()
    RemoveBombs()
    RemoveExplosions()
    gameMode = gmGameOver
    Endif
    
  5. Check if the next level is reached by comparing levelNumber times 10 with the total number of destroyed bombs.
    If totalBombsDestroyed >= (levelNumber * 10) Then
    
  6. Add 3000 points for each city left, and add 5 new rockets to each launcher. Also, raise the level number.
    score += GetCityCount() * 3000
    AddLauncherRockets(5)
    levelNumber += 1
    Endif
    Return True
    
  7. Now, save the mainClass.monkey file.

What just happened?

You have now implemented code that will spawn new bombs, check if the game is over, and also ensure that the player will get new rockets.

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

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