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:

  1. Update the GameEngine's deSpawnReSpawn method to spawn some of each alien.
  2. Update the Level class to add some aliens and alien lasers to the ArrayList of objects.
  3. Update GameObjectFactory to handle instantiating the correct component classes (that we just coded) when the level class requests the various alien GameObject 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()); ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.