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 the base


Now that we have walls, let's create our first GameObject class that will represent the base platform. When I say base platform, I mean the trampoline the clown will be trying relentlessly to jump off at the start of the game. We define the CreateBasePlatform function in GameWorld.cpp:

void GameWorld::CreateBasePlatform()
{
  // base platform will be a static body
  b2BodyDef platform_def;
  platform_def.position.Set(SCREEN_TO_WORLD(416), 
    SCREEN_TO_WORLD(172));
  b2Body* base_platform_body = world_->CreateBody(&platform_def);

  // create an edge slightly above the bottom of the screen
  b2EdgeShape base_platform_shape;
  base_platform_shape.Set(b2Vec2(SCREEN_TO_WORLD(-SCREEN_SIZE.width), 
    0.45f), b2Vec2(SCREEN_TO_WORLD(SCREEN_SIZE.width), 0.45f));
  b2FixtureDef base_platform_fixture_def;
  base_platform_fixture_def.shape = &base_platform_shape;
  // give the base platform perfectly elastic collision response
  base_platform_fixture_def.restitution ...