Time for action — spawning an enemy

This new method called SpawnEnemy will create one enemy and initialize its position and the path to follow:

  1. Create a new method called SpawnEnemy, inside the game class. It will have the x position as a parameter. The y position will be fixed and always on top.
    Method SpawnEnemy:Int (x:Float)
    
  2. Add a new instance of the Enemy class to the enemyList field of the game class. The y position is always 0 and there are 25 path nodes to be created:
    enemyList.AddLast(New Enemy(x,0.0,25))
    Return 0
    End
    

What just happened?

This method created an enemy with 25 path nodes and stored it inside the enemy list of the game class.

Starting a new game

Things that should be done multiple times inside a game should be placed inside a function or a method. Starting a new game will be one of these things.

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

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