In the OnUpdateLayer
method, we want to update emitters and enemies. Also we want to check whether all tiles were removed and start the next level. If all lives of the player's ball are gone, we want to display the Game Over text. Follow the given steps:
layerGame
.Method OnLayerUpdate:Int(layer:ftLayer) If layer = g.layerGame Then
FOR EACHIN
loop of the emitter list of the game
class:For Local emitter := Eachin g.emitterList
Update
method returns FALSE
. We will use the engine's current delta time as a parameter for the emitter's Update
call. If it is, then the emitter is done and we will remove it from the list:If emitter.Update(g.eng.GetDeltaTime()) = False Then g.emitterList.Remove(emitter) Endif Next
For EachIn
loop through the enemy list of the game
class:For Local enemy := Eachin g.enemyList
Update
method and check whether it returns FALSE:
If enemy.Update() = False Then
Local eo:ftObject = enemy.GetObj()
enemyList
, and then the object from the engine:g.enemyList.Remove(enemy) eo.Remove()
x
position:g.SpawnEnemy(Rnd(20,g.cw-20)) Endif Next
We handled particle emitters and enemy objects. Next will be the conditions to reach a new level, that is, when all tiles are destroyed.
gmPlay:
If g.tileCount <= 0 And g.gameMode = g.gmPlay Then
1
to the level number:g.CreateTiles() g.levelNum += 1
g.SpawnEnemy(Rnd(20,g.cw-20))
g.ball.Remove() g.CreateBall() Endif
Now, we should act on the fact that all lives are gone and the game is over.
gmPlay:
If g.lifes <= 0 And g.gameMode = g.gmPlay Then
g.txtGameOver.SetVisible(True)
gmGameOver:
g.gameMode = g.gmGameOver
tidGameOver:
If g.txtGameOver.GetTransitionCount()<= 0 Then g.txtGameOver.CreateTransScale(2.0,2000,False,g.tidGameOver) Endif Endif Return 0 End End
Now that we act on the layer update events, we control the particle emitters totally and also all enemies. Adding to that, we check whether a level is cleared and the game is over.
3.17.79.206