Firing the Cannons

After the user input, the bullets are the most complex portion of the game. Keeping track of 50 sprites that can move in four different directions and may or may not be alive at the current moment is tricky. The cannons are about to get a lot more exciting. In this section, you add the bullets and write the code that handles how and when the cannons fire their volleys of shots.

Follow these steps:

1. Add the code in Listing 9-14 to the GameView constructor. This code handles the new bullets the cannons shoot. The number of bullets onscreen is limited to 50 to keep things simple. There are two arrays: one contains the bullet sprites (bullets[]) and the other holding the list of bullets that aren’t currently in use (available_bullet[] ...

Get Beginning Android Tablet Games Programming now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.