During the OnUpdate
method, we will do different things depending on the gameMode
field. If the mode is gmPlay
, we will update all objects and do collision checks. In other modes, we mostly check for certain keys that are hit on the keyboard to switch the game into a different mode.
Select
statement with the gameMode
field as a parameter.Method OnUpdate:Int() Local d:Float = Float(eng.CalcDeltaTime())/60.0 If isSuspended = False Then Select gameMode
gmPlay
constant.Case gmPlay eng.Update(Float(d))
The call to the Update
method of the engine is now part of the gmPlay
segment.
engine
class.eng.CollisionCheck(layerGame)
If KeyHit(KEY_ESCAPE) Then
layerTitle.SetActive(True) sndEngine.Stop()
gmMenu
.gameMode = gmMenu Endif
score
info text objects with the current score values.txtScore.SetText("Player: "+score) txtScoreC.SetText("Computer: "+scoreC)
gameMode
is equal to gmMenu
.Case gmMenu
If KeyHit(KEY_P) Then StartNewGame() Endif
Error
call.If KeyHit(KEY_ESCAPE) Then Error ("") Endif
gameMode
is equal to gmGameOver
.Case gmGameOver
If KeyHit(KEY_ESCAPE) Then
gameMode
to gmMenu
and activate the title layer.gameMode = gmMenu layerTitle.SetActive(True)
Select
statement.Endif End Endif Return 0 End
By detailing the OnUpdate
method of the class game
, we can now start a new game and also switch back to the title screen. The player can't control the plane for now, but we will implement this, later in this chapter.
If you build and run the game at this moment, and start a new game, the console should look like the following screenshot:
3.141.47.25