Now we turn our attention to the bullets and allowing our hero to shoot. Let's look at the simple ERBullet
class.
@interface ERBullet : CCSprite { BOOL isShootingRight; BOOL isHeroBullet; } @property (nonatomic, assign) BOOL isShootingRight; @property (nonatomic, assign) BOOL isHeroBullet; @end ERBullet.m: @implementation ERBullet @synthesize isShootingRight; @synthesize isHeroBullet; @end
Our ERBullet
class is nothing more than a subclass of the CCSprite
class with a couple of extra Boolean variables to track. The
isShootingRight
Boolean variable helps us keep track of direction of travel for the bullet. Since we are only designing the game to allow flat trajectories for the bullets, we really just need to know if it is going left or right. We also use the
isHeroBullet
variable so we can keep track of whose bullet it is, for collision detection purposes. We will not allow "friendly fire", so enemies won't kill other enemies in this...