We need to be able to check for three different types of collisions. We need to be able to have bullets hit the enemies. We need the hero to get hit. We also need to react when the hero runs into an enemy. Let's look at the method for this, which is in two parts.
Filename:
ERPlayfieldLayer.m
(checkCollisions
, part 1)
-(void) checkCollisions { BOOL isHeroHit = NO; for (ERBullet *bullet in bulletArray) { // Enemy bullets if (bullet.isHeroBullet == NO) { if (CGRectIntersectsRect(hero.boundingBox, bullet.boundingBox)) { // Hero got hit [bulletsToDelete addObject:bullet]; [bullet removeFromParentAndCleanup:YES]; isHeroHit = YES; break; } } else { // Hero bullets // Check all enemies to see if they got hit for (EREnemy *anEnemy in enemyArray) { ...