Landers | Adding some pop.

The core mechanics of the game are now complete, but we can extend the development to embed what we have learned and create a better game. These extensions are presented in three levels of increasing difficulty we call, 'snap', 'crackle' and 'pop'. You are now on your own, but none of these extensions require you to learn anything new that was not introduced in this or previous tutorials. Challenge yourself to see how far you can get using the stages in the tutorials for reference.

  1. The invaders can fire back. Any invader in the bottom row can randomly fire downwards. The player loses a life if they are hit by an invader missile.

    You can determine if an invader is in the bottom row by storing the y position of an invader in a variable in the swarm update function. Iterate back over the invaders and any that have this y position can then spawn an invader missile.

    You learned how to iterate over invaders in stage 4. You learned how to use a factory to spawn multiple instances of a game object in Incoming stage 4. There is no need to put the invader missiles in a table because they behave completely independently. You learned about collision objects in stage 6b. You learned how to despawn missiles in stage 6c.

    Alternatively, if you want a real challenge then any invader that is in the bottom row of its column can fire, not just those on the bottom row. To achieve this you don't want to remove the invaders from the swarm_table when they are shot, just assign them to "dead" instead. You can then use a loop to check all the invaders beneath and if they are all dead the invader must be on the bottom row of its column. Determining the number of the invader beneath is achieved by adding the number that started in the row.
  2. The game should reset if the player loses all their lives or is hit by an invader.