Game Development Reference
In-Depth Information
+(id) bullet;
-(void) shootBulletFrom:(CGPoint)startPosition
velocity:(CGPoint)vel
frameName:(NSString*)frameName
isPlayerBullet:(BOOL)playerBullet;
@end
Accordingly the shootBulletFrom method in the Bullet class implementation
has been extended to receive the isPlayerBullet parameter:
@synthesize velocity, isPlayerBullet;
. . .
-(void) shootBulletFrom:(CGPoint)startPosition
velocity:(CGPoint)vel
frameName:(NSString*)frameName
isPlayerBullet:(BOOL)playerBullet;
{
self.velocity = vel;
self.position = startPosition;
self.visible = YES;
self.isPlayerBullet = playerBullet;
. . .
}
In the exact same fashion, the shootBulletFrom method in the BulletCache
class needs to be extended to receive the isPlayerBullet parameter and then pass
it on to the Bullet class. Both InputLayer and StandardShootComponent
make use of the shootBulletFrom method, and they need to pass in the isPlay-
erBullet parameter. The one in InputLayer sets it to YES , because that code is
responsible for shooting with the ship. The StandardShootComponent sets
isPlayerBullet to NO because the component is used for enemies.
The EnemyCache class holding all Enemy objects is the perfect place to call the new
collision-detection methods to check whether any enemy was hit by a player bullet.
The class has a new checkForBulletCollisions method, which is called from
its update method as seen in Listing 8-16 .
 
Search Nedrilad ::




Custom Search