Time for action – the enemy should attack the player
For the enemy to attack the players' ship, use the following steps:
Open the
Ship.h
file.Refactor our
_juggler
instance variable to be a property, as shown in the following line of code:@property SPJuggler *juggler;
Using the following line of code, add a method called
shootWithBlock
that should shoot and have a callback as its parameter:-(void) shootWithBlock:(ShipCallback) block;
Open the
Ship.m
file and move the contents of theshoot
method into theshootWithBlock
method.In the
shootWithBlock
method, invoke the callback as its last statement inside the complete listener of thecurrentClip
variable.Update the
shoot
method to call theshootWithBlock
method withnil
.Open the
Battlefield.m
file and add a method for collision detection, as shown in the following code:-(void) checkShipCollision: (Ship *) ship1 againstShip: (Ship *) ship2 { SPRectangle *enemyShipBounds = [ship1 boundsInSpace:self]; SPRectangle *ball1 = [ship2.cannonBallLeft...