Game Development Reference
In-Depth Information
Shooting Things
I almost forgot—you actually want to shoot the enemies, right? Well, in the
ShootEmUp03 project, you can!
The ideal starting point to check whether a bullet has hit something is in the Bul-
letCache class. I've added just the method to do that. Actually, I've added three
methods, two of them public; the third is private to the class and combines the common
code (see Listing 8-15 ) .
Listing 8-15. Checking for Collisions with Bullets
-(BOOL) isPlayerBulletCollidingWithRect:(CGRect)rect
{
return [self isBulletCollidingWithRect:rect usePlayerBullets:YES];
}
-(BOOL) isEnemyBulletCollidingWithRect:(CGRect)rect
{
return [self isBulletCollidingWithRect:rect usePlayerBullets:NO];
}
-(BOOL) isBulletCollidingWithRect:(CGRect)rect usePlayerBullets:(bool)usePlayerBullets
{
BOOL isColliding = NO;
for (Bullet* bullet in batch.children)
{
if (bullet.visible && usePlayerBullets == bullet.isPlayerBullet)
{
if (CGRectIntersectsRect([bullet boundingBox], rect))
{
isColliding = YES;
// remove the bullet
bullet.visible = NO;
break;
}
 
 
Search Nedrilad ::




Custom Search