O'Reilly logo

Sparrow iOS Game Framework Beginner's Guide by Johannes Stein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required