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


The collectibles for this game will be represented by the Collectible class that inherits from GameObject and will be used to represent all three types of collectibles: the simple collectible, the rocket, and the balloon. It will possess a score value and a flag that marks whether it has been collected. It will possess functions to manage life events that we will discuss in this section, starting with the SetBody function:

void Collectible::SetBody(b2Body* body)
{
  b2PolygonShape collectible_shape;

  // create different box shapes for different collectibles
  switch(type_)
  {
  case E_GAME_OBJECT_COLLECTIBLE:
    collectible_shape.SetAsBox(SCREEN_TO_WORLD(
      m_obContentSize.width/2), SCREEN_TO_WORLD(
      m_obContentSize.height/2));
    break;
  case E_GAME_OBJECT_ROCKET:
  case E_GAME_OBJECT_BALLOON:
    collectible_shape.SetAsBox(SCREEN_TO_WORLD(
      m_obContentSize.width/2), SCREEN_TO_WORLD(
      m_obContentSize.height/4), b2Vec2(0, SCREEN_TO_WORLD(
  ...