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 ...