Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Johannes Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Johannes Stein

Overview of this book

Table of Contents (20 chapters)
Sparrow iOS Game Framework Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Afterword
Index

Time for action – the enemy should attack the player


For the enemy to attack the players' ship, use the following steps:

  1. Open the Ship.h file.

  2. Refactor our _juggler instance variable to be a property, as shown in the following line of code:

    @property SPJuggler *juggler;
  3. 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;
  4. Open the Ship.m file and move the contents of the shoot method into the shootWithBlock method.

  5. In the shootWithBlock method, invoke the callback as its last statement inside the complete listener of the currentClip variable.

  6. Update the shoot method to call the shootWithBlock method with nil.

  7. 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...