In this section, we are going to implement a solution to detect collisions between our main character and the enemies to manage what happens when the zombie hits a human.
In GameScene.m
, add the following block of code at the end of the gamePadPushButton
method:
// Detect collision for (Human *human in _arrayOfHumans){ // Detect collision if (CGRectIntersectsRect(_zombie.boundingBox, human.humanSprite.boundingBox) && !_humanCollisionDetected && _zombie.position.y <= (human.humanSprite.position.y + 12) && _zombie.position.y >= (human.humanSprite.position.y - 12)) { // anchorpoint _humanCollisionDetected = TRUE; // Managing collisions [self manageCollisionForHuman:human]; break; } }
In this loop, we're just checking whether the zombie bounding box intersects with some of the humans. Also, we check that the y value is inside...