The update process will determine the current delta time, reset the collision markers, and do the collision checks. It also will check the buttons of the game pad.
Select
statement inside the If
statement that depends on the field gameMode
.Method OnUpdate:Int() Local d:Float = Float(eng.CalcDeltaTime())/60.0 If isSuspended = False then Select gameMode
gmPlay
.Case gmPlay
OnTarget = 0
hitWall = False hitWall2 = False hitCrate = Null hitCrate2 = Null
eng.CollisionCheck(layerGame) eng.Update(Float(d))
While playing a level, we want the player to be able to switch back to the titlescreen.
If KeyHit(KEY_X) Or JoyHit(JOY_X) Then
gameMode
to gmMenu
.g.layerTitle.SetActive(True) g.gameMode = g.gmMenu Endif
In a former chapter we check for the winning conditions inside the engines
callback methods. This time, we implement it inside the update process of the game class. It is all a matter of preference. There is no strict rule for anything.
PLAY
mode.If crateNum = onTarget And gameMode = gmPlay Then
gmNextLevel
.gameMode = gmNextLevel
2000
milliseconds. It will also have a transition ID attached to it so we can react to it when the transition is done.layerGame.CreateTransAlpha(0.01,2000,False,tidNextLevel) Endif
gameMode
is equal to gmMenu
.Case gmMenu
If KeyHit(KEY_A) Or JoyHit(JOY_A) Or TouchHit(0) Then StartNewGame() Endif
If KeyHit(KEY_Y) Or JoyHit(JOY_Y) Then Error("") Endif
gameMode
is equal to gmNextLevel
.Case gmNextLevel
OnUpdate
method.eng.Update(Float(d)/60)
Select
statement.End
OnUpdate
method.txtCrates.SetText("Crates on target: "+onTarget+"/"+crateNum) Endif Return 0 End
Congratulate yourself. We just finalized the OnUpdate
method of the game class. It will control the game flow by checking against the gameMode variable and also check whether certain keys are hit. We still can't control the player's machine, and collision detection is not implemented so far. But we will get there soon.
Save the script and run it. If you hit the A key, you should see the level as shown in the image at the beginning of the section The level maps—loading the tiles, in this chapter.
3.138.33.87