Time for action – creating an intro for our game
Use the following steps to add the intro scene:
This is as good a time as any to move the collision detection code into a separate file. Create a new group called
Logic
and add a class inside this group calledCollision
which is a subclass ofNSObject
.Declare this static method in the
Collision
class, as shown in the following code:+(void) checkShipCollision: (Ship *) ship1 againstShip: (Ship *) ship2 withReferenceToSprite: (SPSprite *) sprite;
Inside
Collision.m
, implement thecheckShipCollision
method with the following lines of code:SPRectangle *enemyShipBounds = [ship1 boundsInSpace:sprite]; SPRectangle *ball1 = [ship2.cannonBallLeft boundsInSpace:sprite]; SPRectangle *ball2 = [ship2.cannonBallRight boundsInSpace:sprite]; if ([enemyShipBounds intersectsRectangle:ball1] || [enemyShipBounds intersectsRectangle:ball2]) { if (ship2.cannonBallLeft.visible || ship2.cannonBallRight.visible) { [ship2 abortShooting]; if (ship1.type ==...