Time for action — detailing the OnLayerUpdate method

The OnLayerUpdate method has the layer as a parameter.

  1. Check if the layer is equal to g.layerGame.
    Method OnLayerUpdate:Int(layer:ftLayer)
    If layer = g.layerGame Then
    
  2. Check if g.lifes are equal to or below 0.
    If g.lifes <= 0 Then 'GameOVER
    
  3. Set gameMode to g.gmGameOver.
    g.gameMode = g.gmGameOver
    
  4. Activate the layer g.layerTitle.
    g.layerTitle.SetActive(True)
    
  5. Add g.score to the high score list of the engine.
    g.eng.scoreList.AddScore(g.score,"---")
    
  6. Deactivate the player object.
    g.player.SetActive(False)
    
  7. Remove all particle objects and all remaining comets using their ID values.
    g.layerFX.RemoveAllObjects()
    layer.RemoveAllObjectsByID(g.grpComet)
    
  8. Save the high score list via g.SaveHighScore. Then Return from the method.
    g.SaveHighScore()
    Return 0
    Endif
    
  9. Check if all comets are destroyed and g.gameMode still equals g.gmPlay.
    'All comets destroyed-> next level
    If g.cometCount <= 0 And g.gameMode = g.gmPlay Then
    
  10. Activate the player shield.
    ActivateShield()
    
  11. Raise the level number, and spawn new comets. Also, add a player life.
    g.levelNumber += 1
    g.SpawnComets(3 + g.levelNumber)
    g.lifes += 1
    Endif
    Endif
    Return 0
    End
    

What just happened?

In the preceding four methods, we basically set all the controls and condition checks for our gameplay.

Of course there are other ways to handle all this. Remember, this is just one way to do it. The whole game code is about 450-500 lines. That is not much. But fantomEngine took a lot of work from us. You could easily add another 800-1000 lines to the game if you had to create all this yourself.

Have a go hero — adding an enemy ship

One thing that is missing from an Asteroids clone is the enemy ship that showed up randomly and shot at your ship. You could also try to destroy it, and if you hit it you get a good amount of points rewarded to you. It would be a good challenge for you to add an enemy ship. If you look at the sprite sheet, then you will find a green enemy ship right there. Try it, it is easy!

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

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