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()); ...
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.