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

Creating the game


Let's define the CreateGame function, which is called from the init function when GameWorld is created:

void GameWorld::CreateGame()
{
  // initialise counters & flags
  seconds_ = 0;
  enemies_killed_total_ = 0;
  enemies_killed_combo_ = 0;
  combo_timer_ = 0;
  score_ = 0;
  is_popup_active_ = false;

  // add the stars
  background_ = BackgroundManager::create();
  addChild(background_, E_LAYER_BACKGROUND);

  CreateBoundary();
  CreatePlayer();
  CreateContainers();
  CreateHUD();

  // initially add some enemies & a powerup
  AddEnemyFormation();
  AddPowerUp();

  // schedule the update and the tick
  scheduleUpdate();
  schedule(schedule_selector(GameWorld::Tick), 1.0f);
}

We start this function by initializing the following variables:

Variable

Description

seconds_

This is the amount of time the game has been active.

enemies_killed_total_

This is the total number of enemies killed.

enemies_killed_combo_

This is the number of enemies killed in the...