Skip to Main Content
Learning iPhone Game Development with Cocos2D 3.0
book

Learning iPhone Game Development with Cocos2D 3.0

by Kirill Muzykov
June 2014
Beginner to intermediate content levelBeginner to intermediate
434 pages
9h 49m
English
Packt Publishing
Content preview from Learning iPhone Game Development with Cocos2D 3.0

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

James Goodwill, Wesley Matlock

Publisher Resources

ISBN: 9781782160144Supplemental Content