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 – getting the enemy ship to move around

In order for the enemy ship to move around, we need to use the following steps:

  1. Open our Xcode project if it's not already open.
  2. Open the Battlefield.h file.
  3. Define all AI states as enum, as shown in the following code:
    typedef NS_ENUM(NSInteger, AIState) {
        StateWanderAround,
        StateMoveToPlayer,
        StateAttack,
        StateRecuperate
    };
  4. Inside the Battlefield scene, add a new instance variable called _aiState, which is of the AIState type.
  5. Open the Ship.h file.
  6. Add a callback block type, as shown in the following line of code:
    typedef void(^ShipCallback)(void);
  7. Declare three new methods for the Ship class, as shown in the following code:
    -(void) moveToX:(float)x andY:(float)y withBlock:(ShipCallback) block;
    -(float) checkDistanceToShip:(Ship *)ship;
    -(void) moveToShip:(Ship *)ship withBlock:(ShipCallback) block;
  8. Open the Ship.m file.
  9. Move the contents of the -(void) moveToX:(float) x andY:(float) y method into the -(void) moveToX...