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

The Enemy class


The enemies in Iceman are represented by charming chocolate colored walruses. The one annoying attribute to these chubby creatures is that they rebuild any bricks the hero might have painstakingly broken. Other than that, these creatures are fairly harmless and one knock of the hero's shovel and they're dead meat.

The Enemy class, like the Hero class, will inherit from GameObject. The constructor for the Enemy class from the Enemy.cpp file looks like this:

Enemy::Enemy()
{
  type_ = E_GAME_OBJECT_ENEMY;
  state_ = E_ENEMY_STATE_NONE;
  tile_col_to_build_ = -1;
  tile_row_to_build_ = -1;
  must_be_removed_ = false;
}

We begin by defining the type as E_GAME_OBJECT_ENEMY and initialize the state_, column and row variables. These column and row variables will be used to identify which vacant areas of the map this enemy will reinforce. Finally, we have the must_be_removed_ flag that you have seen before in previous chapters. The enemies in this game, like the ones in previous chapters...