Time for action — finalizing the OnUpdate method

  1. Head over to the OnUpdate method and add a Select statement with the gameMode as a parameter.
    Method OnUpdate:Int()
    Select gameMode
    
  2. When the game mode is gmPlay, update the engine with the deltaTime divided by 60 as a speed parameter.
    Case gmPlay
    eng.Update(Float(UpdateGameTime())/60.0)
    
  3. Do a collision check only on the layerGame layer.
    eng.CollisionCheck(layerGame)
    
  4. Update the info text objects.
    UpdateInfoText()
    
  5. When the game mode is gmMenu or gmGameOver.
    Case gmMenu, gmGameOver
    

    If the P key was hit, then start a new game.

    If KeyHit(KEY_P) Then
    StartNewGame()
    Endif
    

    If the H key was hit, then show the high score list.

    If KeyHit(KEY_H) Then
    ShowScoreList()
    Endif
    
  6. When the game mode is gmScoreList.
    Case gmScoreList
    

    If the P key was hit, start a new game.

    If KeyHit(KEY_P) Then
    StartNewGame()
    Endif
    
  7. End the Select statement.
    End
    Return 0
    End
    

What just happened?

Now, if you build the game without any errors and press the P key, then you should see some comets moving over the screen and the spaceship in the middle.

What just happened?
..................Content has been hidden....................

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