O'Reilly logo

Learning iPhone Game Development with Cocos2D 3.0 by Kirill Muzykov

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 – winning or losing the game

In most games, we can win or lose. This makes the game interesting. In our game, we will win the game if we avoid losing. To be more specific, we will lose if we allow some number of the birds to fly away, for example, 3 birds out of 20. If we'll hit more than 17 birds, then we'll win.

Let's add the code to win and lose the game:

  1. Open the GameScene.h file and add enum with game states and a property to hold the current state, as shown in the following code:
    #import "CCScene.h"
    
    typedef enum GameState
    {
        GameStateUninitialized,
        GameStatePlaying,
        GameStatePaused,
        GameStateWon,
        GameStateLost
        
    } GameState;
    
    @interface GameScene : CCScene
    
    @property (nonatomic, assign) GameState gameState;
    
    @end
  2. Switch to the ...

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