Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Stein

Overview of this book

An easy-to-follow guide full of descriptive step-by-step procedures on how to develop a game for iOS. With each topic, a new challenge will be tackled to get a deeper knowledge of the Sparrow game framework and gain the skills to develop a complete mobile experience. This book is aimed at those who have always wanted to create their own games for iOS devices. Perhaps you've already dabbled in game development and want to know how to develop games for the Apple App Store, or maybe you have developed Objective-C apps in the past but you are new to game development. In either case, this book will help with descriptive examples and teach you to develop a game throughout its course. Some experience in Objective-C and a basic understanding of object-oriented programming are required.
Table of Contents (15 chapters)
13
Afterword
14
Index

Time for action – letting cannonballs collide with ships


To check if cannonballs collide against the enemy ship, follow these steps:

  1. Open the Ship.h file.

  2. We need to add custom getters and setters to the hitpoints property, so let's make this property nonatomic and add an instance variable called _hitpoints.

  3. Declare the methods abortShooting and hit.

  4. Switch to the Ship.m file.

  5. The custom hitpoints getter just returns the instance variable _hitpoints.

  6. The custom setter for hitpoints contains the following code:

    -(void) setHitpoints:(int)hitpoints
    {
        _hitpoints = hitpoints;
        if (_hitpoints <= 0) {
            self.visible = NO;
        }
    }
  7. The abortShooting method consists of the following lines:

    -(void) abortShooting
    {
        _isShooting = NO;
        
        [Sparrow.juggler removeObjectsWithTarget:self.cannonBallLeft];
        [Sparrow.juggler removeObjectsWithTarget:self.cannonBallRight];
        
        self.cannonBallLeft.visible = NO;
        self.cannonBallRight.visible = NO;
    }
  8. The hit method has the following content...