Example #1
0
bool Paddle::init() {
  if (!Sprite::initWithFile(SPRITE_PADDLE)) {
    return false;
  }

  createPhysicsBody();

  return true;
}
Example #2
0
bool Ball::init() {
  if (!Sprite::initWithFile(SPRITE_BALL)) {
    return false;
  }

  createPhysicsBody();

  return true;
}
Example #3
0
bool Wall::init() {
    if (!Sprite::initWithFile(SPRITE_WALL)) {
        return false;
    }

    adjustScale();
    createPhysicsBody();

    return true;
}
Example #4
0
bool Level::init(std::string levelName, std::string collisionObjectGroupName)
{
	if (!TMXTiledMap::initWithTMXFile(levelName))
	{
		return false;
	}

	_collisionObjectGroup = getObjectGroup(collisionObjectGroupName);

	createPhysicsBody();
	
	return true;
}
ThreeDAnimation::ThreeDAnimation(const Track &track,
                                 const XMLNode &node)
               : AnimationBase(node)
{
    /** Save the initial position and rotation in the base animation object. */
    setInitialTransform(m_animated_node->getPosition(), m_animated_node->getRotation());

    m_body            = NULL;
    m_motion_state    = NULL;
    m_collision_shape = NULL;
    m_hpr = AnimationBase::m_animated_node->getRotation();
    std::string shape;
    node.get("shape", &shape);
    if(shape!="")
    {
        createPhysicsBody(shape);
    }
}   // ThreeDAnimation
Example #6
0
void InstanceObject::changeModel(std::shared_ptr<ObjectData> incoming)
{
	if( body ) {
		delete body;
		body = nullptr;
	}

	object = incoming;

	if( incoming ) {
		auto bod = new CollisionInstance;

		if( bod->createPhysicsBody(this, object->modelName, dynamics.get()) )
		{
			bod->body->setActivationState(ISLAND_SLEEPING);
			body = bod;
		}
	}
}
Example #7
0
b2Body* Game::createCircle(b2Vec2 position, float radius, float angle, b2BodyType bodyType, unsigned short category, unsigned short mask)
{
	b2BodyDef bodyDef;
	bodyDef.type = bodyType;
	bodyDef.position = position;
	bodyDef.angle = MathUtils::degressToRadians(angle);

	b2CircleShape circleShape;
	circleShape.m_radius = radius;

	b2FixtureDef fixtureDef;
	fixtureDef.shape = &circleShape;
	fixtureDef.density = 1.0f;
	fixtureDef.filter.categoryBits = category;
	fixtureDef.filter.maskBits = mask;

	b2Body* body = createPhysicsBody(&bodyDef, &fixtureDef);
	return body;
}
Example #8
0
b2Body* Game::createBox(b2Vec2 position, b2Vec2 size, float angle, b2BodyType bodyType, unsigned short category, unsigned short mask)
{
	b2BodyDef bodyDef;
	bodyDef.type = bodyType;
	bodyDef.position = position;
	bodyDef.angle = MathUtils::degressToRadians(angle);

	b2PolygonShape boxShape;
	boxShape.SetAsBox(size.x, size.y);

	b2FixtureDef fixtureDef;
	fixtureDef.shape = &boxShape;
	fixtureDef.density = 1.0f;
	fixtureDef.filter.categoryBits = category;
	fixtureDef.filter.maskBits = mask;

	b2Body* body = createPhysicsBody(&bodyDef, &fixtureDef);
	return body;
}
Example #9
0
void Game::load()
{
	switch (m_LoadStep)
	{
	case GameLoadStepInitial:
	{
		//TODO: Load game content required for future load steps here
	}
		break;

	case GameLoadStepWorld:
	{
		//Define the gravity vector.
		b2Vec2 gravity;
		gravity.Set(GAME_GRAVITY_X, GAME_GRAVITY_Y);

		//Construct the Box2d world object, which will
		//holds and simulates the rigid bodies
		m_World = new b2World(gravity);
		m_World->SetContinuousPhysics(GAME_PHYSICS_CONTINUOUS_SIMULATION);
		m_World->SetContactListener(this);

#if _DEBUG
		//Create the debug draw for Box2d
		m_DebugDraw = new b2DebugDraw(b2Helper::box2dRatio());

		//Set the debug draw flags
		uint32 flags = 0;
		flags += b2Draw::e_shapeBit;
		flags += b2Draw::e_jointBit;
		flags += b2Draw::e_centerOfMassBit;
		m_DebugDraw->SetFlags(flags);

		//Set the Box2d world debug draw instance
		m_World->SetDebugDraw(m_DebugDraw);
#endif
	}
		break;		

	case GameLoadStepSensors:
	{	
		
	}
		break;

	case GameLoadStepGround:
	{
		//Define the ground body.
		b2BodyDef groundBodyDef;
		groundBodyDef.position.Set(0.0f, 0.0f); // bottom-left corner

		//Define the ground box shape.
		b2EdgeShape groundShape;
		b2Vec2 vertex1 = b2Vec2(0.0f, 0.0f);
		b2Vec2 vertex2 = b2Helper::screenSpaceToBox2dSpace(getScreenWidth(), 0.0f);
		groundShape.Set(vertex1, vertex2);

		//Initialize the ground fixture def
		b2FixtureDef groundFixture;
		groundFixture.shape = &groundShape;
		groundFixture.friction = 1.0f;
		groundFixture.density = 0.0f;
		groundFixture.restitution = 0.2f;

		//Call the body factory which allocates memory for the ground body
		//from a pool and creates the ground box shape (also from a pool).
		//The body is also added to the world.
		b2Body* ground = createPhysicsBody(&groundBodyDef, &groundFixture);
		addGameObject(new Ground(ground));
	}
		break;
		
	case GameLoadStepPlatforms:
	{
		//cannon platform
		float x = getScreenWidth() * 0.01f;
		float y = getScreenHeight() * 0.1f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(5.5f, 2.0f)));
		
		//roof
		x = getScreenWidth() * 0.523f;
		y = getScreenHeight() * 0.99f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(19.0f, 0.2f), 180.0f));

		//far right pole pole
		x = getScreenWidth() * 0.95f;
		y = getScreenHeight() * 0.15f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(3.0f, 0.3f),  90.0f));

		//2nd from the right pole
		x = getScreenWidth() * 0.90f;
		y = getScreenHeight() * 0.15f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(3.0f, 0.3f),  90.0f));

		//3rd from the right pole
		x = getScreenWidth() * 0.83f;
		y = getScreenHeight() * 0.15f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(9.0f, 0.3f),  90.0f));

		//4th from the right pole
		x = getScreenWidth() * 0.78f;
		y = getScreenHeight() * 0.15f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(6.0f, 0.3f),  90.0f));
		
		//5th from the right
		x = getScreenWidth() * 0.70f;
		y = getScreenHeight() * 0.15f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(4.5f, 0.3f),  90.0f));
		
		//6th from the right
		x = getScreenWidth() * 0.64f;
		y = getScreenHeight() * 0.15f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(5.0f, 0.3f),  90.0f));
		
		//7th from the right
		x = getScreenWidth() * 0.56f;
		y = getScreenHeight() * 0.15f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(7.5f, 0.3f),  90.0f));
		
		//8th from the right
		x = getScreenWidth() * 0.50f;
		y = getScreenHeight() * 0.15f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(6.7f, 0.3f),  90.0f));
		
		//9th from the right
		x = getScreenWidth() * 0.43f;
		y = getScreenHeight() * 0.15f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(4.5f, 0.3f),  90.0f));
		
		//10th from the right
		x = getScreenWidth() * 0.36f;
		y = getScreenHeight() * 0.15f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(5.5f, 0.3f),  90.0f));
		
		//right wall
		x = getScreenWidth() * 0.999f;
		y = getScreenHeight() * 0.5f;
		addGameObject(new StaticPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(10.0f, 0.2f), 90.0f));
							
		x = getScreenWidth() * 0.5f;
		y = getScreenHeight() * 0.55f;
		float minX = getScreenWidth() * 0.350f;
		float maxX = getScreenWidth() * 0.650f;
		float minY = getScreenHeight() * 0.450f;
		float maxY = getScreenHeight() * 0.60f;
		addGameObject(new KinematicPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(2.0f, 0.2f), b2Vec2(2.5f, 0.0f), b2Vec2(minX, minY), b2Vec2(maxX, maxY)));

		x = getScreenWidth() * 0.7f;
		y = getScreenHeight() * 0.75f;
		 minX = getScreenWidth() * 0.40f;
		 maxX = getScreenWidth() * 0.750f;
		addGameObject(new KinematicPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(1.0f, 0.5f), b2Vec2(0.5f, 0.0f), b2Vec2(minX, y), b2Vec2(maxX, y)));

		x = getScreenWidth() *0.990f;
		y = getScreenHeight() * 0.50f;
	     minX = getScreenWidth() * 0.80f;
		 maxX = getScreenWidth() * 0.990f;
		addGameObject(new KinematicPlatform(b2Helper::screenSpaceToBox2dSpace(x, y), b2Vec2(2.0f, 0.5f), b2Vec2(2.5f, 0.0f), b2Vec2(minX, y), b2Vec2(maxX, y)));
	}

		break;

	case GameLoadStepTurret:
	{
		float x = getScreenWidth() * 0.0625f;
		float y = getScreenHeight() * 0.25f;
		m_Turret = new Turret(x, y);
		addGameObject(m_Turret);
	}
		break;

	case GameLoadStepFinal:
	{
		reset();
	}
		break;

	default:
		break;
	}

	//Increment the load step
	m_LoadStep++;
}
Example #10
0
Ground::Ground(PhysicsManager* _pm, btVector3 position, btVector3 _normal) : Entity(_pm)
{
  pm = _pm;
  normal = _normal;
  createPhysicsBody(position);
}