Book Image

Cocos2d-X Game Development Blueprints

By : Karan Sequeira
Book Image

Cocos2d-X Game Development Blueprints

By: Karan Sequeira

Overview of this book

Table of Contents (17 chapters)
Cocos2d-x Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

On to the game world


We'll start by looking at the CreateGame function that is called from the init function when GameWorld is created:

void GameWorld::CreateGame()
{
  // player starts off with 30 seconds
  time_left_ = 30;

  // create & add the first set of hills at 0
  terrain_ = Terrain::create(world_, 0);
  addChild(terrain_, E_LAYER_FOREGROUND);
  
  // create & add the sky
  sky_ = Sky::create();
  addChild(sky_, E_LAYER_BACKGROUND);

  // create & add the penguin to the hills
  penguin_ = Penguin::create(this, "penguin_1.png");
  terrain_->addChild(penguin_, E_LAYER_FOREGROUND);

  CreateHUD();

  // enable touch and schedule two selectors; the seconds 
    ticker and the update
  setTouchEnabled(true);
  schedule(schedule_selector(GameWorld::Tick), 1.0f);
  scheduleUpdate();
}

We begin this function by initializing a variable called time_left_ to 30. This means that the player starts off with 30 seconds to take the penguin as far as possible. We then create the hills...