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 |
---|---|
|
This is the amount of time the game has been active. |
|
This is the total number of enemies killed. |
|
This is the number of enemies killed in the... |