O'Reilly logo

Beginning Android Tablet Games Programming by Jeremy Kerfs

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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[] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required