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


All the gameplay entities in this game share a few things in common. They all need an axis aligned bounding box for collision detection, they all also possess some speed, and they also possess a type attribute. Thus, their parent class GameObject is defined as follows in GameObject.h:

class GameObject : public CCSprite
{
public:
  GameObject() : game_world_(NULL),
    type_(E_GAME_OBJECT_NONE),
    aabb_(CCRectZero),

#ifdef ICEMAN_DEBUG_MODE
    aabb_node_(NULL),
#endif

    speed_(CCPointZero) {}

  virtual ~GameObject()
  {}

  virtual void SetAABB(CCRect aabb)
  {
    aabb_ = aabb;

#ifdef ICEMAN_DEBUG_MODE
    // draw the AABB in debug mode only
    CCPoint vertices[4];
    vertices[0] = CCPointZero;
    vertices[1] = ccp(0, aabb_.size.height);
    vertices[2] = ccp(aabb_.size.width, aabb_.size.height);
    vertices[3] = ccp(aabb_.size.width, 0);
    
    aabb_node_ = CCDrawNode::create();
    aabb_node_->drawPolygon(vertices, 4, ccc4f(0, 0, 0, 0), 1, ccc4f(1...