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 – creating an intro for our game


Use the following steps to add the intro scene:

  1. 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 called Collision which is a subclass of NSObject.

  2. Declare this static method in the Collision class, as shown in the following code:

    +(void) checkShipCollision: (Ship *) ship1 againstShip: (Ship *) ship2 withReferenceToSprite: (SPSprite *) sprite;
  3. Inside Collision.m, implement the checkShipCollision 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 ==...