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 – adding more functionality to the ship class


Let's extend the ship class using the following steps:

  1. Open the Ship.h file.

  2. Add enum for the eight directions of the ship, as shown in the following code:

    typedef NS_ENUM(NSInteger, ShipDirection) {
        DirectionNorth,
        DirectionSouth,
        DirectionWest,
        DirectionEast,
        DirectionNorthWest,
        DirectionNorthEast,
        DirectionSouthWest,
        DirectionSouthEast
    };
  3. Add another enum for the type of the ship, as shown in the following code:

    typedef NS_ENUM(NSInteger, ShipType) {
        ShipPirate,
        ShipNormal
    };
  4. Change the _shootingClip instance variable to be a pointer to the NSArray class and remove the _idleImage instance variable, as shown in the following code:

    NSArray *_shootingClip;
  5. Add a property for the ship's hitpoints, as shown in the following line of code:

    @property int hitpoints;
  6. Add another property for type, as shown in the following line of code:

    @property ShipType type;
  7. The third property is the direction of the ship...