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

Get Learning iPhone Game Development with Cocos2D 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.