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 and spawning the fish


We already know the different kinds of fish that will be available to the player within a specific level. We have extracted the value set into the ListOfFish custom property of the world and stored it in the fish_list_ variable of the GameWorld class. We now use this variable to create the various fishes in the CreateFish function of GameWorld.cpp:

void GameWorld::CreateFish()
{
  Fish* fish = NULL;
  // get integer list from comma separated string
  vector<int> fish_type_vec = GameGlobals::GetIntListFromString(fish_list_);
  // this list consists of throwable fish
  num_throwable_fish_ = fish_type_vec.size();
  // initially, we will only have throwable fish
  num_total_fish_ = num_throwable_fish_;

  for(int i = 0; i < num_throwable_fish_; ++i)
  {
    // create each type of fish
    EFishType fish_type = (EFishType)fish_type_vec[i];
    switch(fish_type)
    {
    case E_FISH_SIMPLE:
      fish = Fish::create(this);
      break;
    case E_FISH_SHOOTING...