Game Development Reference
In-Depth Information
Chapter 8
Shoot 'em Up
What does a game of this kind need above all else? Something to shoot up and bullets to
evade. In this chapter, you'll be adding enemies to the game and even a boss monster.
Both enemies and player will use the new BulletCache class to shoot a variety of
bullets from the same pool. The cache class reuses inactive bullets to avoid constantly
allocating and releasing bullets from memory. Likewise, enemies will use their own
EnemyCache class because they, too, will appear in greater numbers on the screen.
Obviously the player will be able to shoot these enemies. I also introduce the concept of
component-based programming, which allows you to extend the game's actors in a mod-
ular way. Besides shooting and moving components, you also create a healthbar com-
ponent for the boss monster. After all, a boss monster should not be an ins tant kill but
require several hits before it is destroyed.
Adding the BulletCache Class
The BulletCache class is the one-stop shop for creating new bullets in the
ShootEmUp01 project. Previously all this code was in the GameLayer class, but it
shouldn't be the responsibility of the GameLayer to manage and create new bullets.
Listing 8-1 shows the new BulletCache header file, and it now contains the CCS-
priteBatchNode and the inactive bullets counter.
Listing 8-1. The @interface of the BulletCache Class
Search Nedrilad ::

Custom Search