Book Image

Learning iPhone Game Development with Cocos2D 3.0

By : Kirill Muzykov
Book Image

Learning iPhone Game Development with Cocos2D 3.0

By: Kirill Muzykov

Overview of this book

Table of Contents (19 chapters)
Learning iPhone Game Development with Cocos2D 3.0
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – using states for the bird's life cycle


We're going to give our hunter several tries to hit the bird. This means that the bird will fly on the screen, then fly away, and then return. This sequence will repeat several times. This means we won't be able to use the flipX property to understand whether our bird is flying away completely or just making another pass.

Instead of using the flipX property as a flag, we're going to introduce a state's enum and change the bird's state during the bird's life cycle. Then, when we'll apply some action to the bird. We're going to check whether the bird is in the correct state for this action. Perform the following steps:

  1. Open the Bird.h file and make the following changes to add the new BirdState enum, new birdState property, and a turnaround method declaration:

    #import "CCSprite.h"
    
    typedef enum BirdType
    {
        BirdTypeBig,
        BirdTypeMedium,
        BirdTypeSmall
    } BirdType;
    
    typedef enum BirdState
    {
        BirdStateFlyingIn,
        BirdStateFlyingOut...