Spawning the Aliens
Now that all the alien components as well as the ALienLaserSpawner
are coded we can put them all to work in the game. It will take three steps as follows:
- Update the
GameEngine
'sdeSpawnReSpawn
method to spawn some of each alien. - Update the
Level
class to add some aliens and alien lasers to theArrayList
of objects. - Update
GameObjectFactory
to handle instantiating the correct component classes (that we just coded) when the level class requests the various alienGameObject
instances be built.
Let's complete those steps now.
Updating GameEngine
Add this code to the end of the deSpawnReSpawn
method.
for (int i = Level.FIRST_ALIEN; i != Level.LAST_ALIEN + 1; i++) { objects.get(i).spawn(objects .get(Level.PLAYER_INDEX).getTransform()); }
This loops through the appropriate indexes of the objects ArrayList
and spawns the aliens. The alien lasers will be spawned by the spawnAlienLaser
method when requested by an alien (chaser or patroller).
Next, we will update...