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 Hero class


The Hero class will inherit from GameObject and will be responsible for handling the state machine of the hero and collision response, among a few other things. The constructor for the Hero class looks something like this:

Hero::Hero()
{
  type_ = E_GAME_OBJECT_HERO;
  state_ = E_HERO_STATE_NONE;
  is_on_ground_ = false;
  current_ground_height_ = 0.0f;
  platform_below_ = NULL;
}

We start off by setting the type_ of this object to E_GAME_OBJECT_HERO. We then initialize the member variables. The state_ variable (like you saw in Chapter 5, Let's Get Physical!) is the key to maintaining the state machine for the hero's behavior. We also have an is_on_ground_ flag that indicates when the hero is standing on a surface, which could be either a brick or a moving platform. So, we can set the appropriate state accordingly. We also have a current_ground_height_ variable that measures the height the hero has managed to reach and is at currently. This increases as the hero moves higher...