void PowerShieldPhysicsComponent::init() { b2BodyDef bodyDef; bodyDef.type = b2_staticBody; // Adjust offsets here yo bodyDef.position.Set(gameObjectRef->posX + 40, gameObjectRef->posY); bodyDef.angle = 0;// ... which direction it's facing GameWorld* gameWorld = GameWorld::getInstance(); mBody = gameWorld->getPhysicsWorld()->CreateBody(&bodyDef); /// Hitbox instantiation b2PolygonShape box; /// Set Box Shape box.SetAsBox(1, 1); // look up other functions for polygons // boxFixtureDef.shape = &box; boxFixtureDef.density = 1; // Create Fixture mFixture = mBody->CreateFixture(&boxFixtureDef); mBody->SetUserData(gameObjectRef); mBody->SetTransform(b2Vec2(gameObjectRef->posX/worldScale, gameObjectRef->posY/worldScale), 0); setCollisionFilter(COLLISION_POWERSHIELD, COLLISION_FEATHER); }
void MinionPhysicsComponent::init(){ if (!mBody){ b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(gameObjectRef->posX, gameObjectRef->posY); bodyDef.angle = 0;// ... which direction it's facing GameWorld* gameWorld = GameWorld::getInstance(); mBody = gameWorld->getPhysicsWorld()->CreateBody(&bodyDef); b2PolygonShape box; box.SetAsBox(.8f, .8f); // look up other functions for polygons boxFixtureDef.shape = &box; boxFixtureDef.density = 1; mFixture = mBody->CreateFixture(&boxFixtureDef); mBody->SetUserData(gameObjectRef); } mBody->SetTransform(b2Vec2(gameObjectRef->posX/worldScale, gameObjectRef->posY/worldScale), 0); float rando[10] = { -285, 285, -100, 50, -25, 160, -240, 60, -130, 250 }; float yForce = rando[(gameObjectRef->ID%10)]; if (gameObjectRef->team == TEAM_YELLOW){ mBody->SetLinearVelocity(b2Vec2(7, 0)); mBody->ApplyForce(b2Vec2(50, yForce), mBody->GetWorldCenter(), true); } else if (gameObjectRef->team == TEAM_PURPLE){ mBody->SetLinearVelocity(b2Vec2(-7, 0)); mBody->ApplyForce(b2Vec2(-50, yForce), mBody->GetWorldCenter(), true); } setCollisionFilter(COLLISION_MINION, COLLISION_FEATHER | COLLISION_MINION | COLLISION_BASE | COLLISION_MINE | COLLISION_FAN | COLLISION_PLATFORM | COLLISION_BOOMERANG); blownForce = b2Vec2(0.0f, 0.0f); savedYForce = 0.0f; }
void PlatformPhysicsComponent::init() { b2BodyDef bodyDef; bodyDef.type = b2_staticBody; bodyDef.position.Set(gameObjectRef->posX, gameObjectRef->posY); bodyDef.angle = 0;// ... which direction it's facing GameWorld* gameWorld = GameWorld::getInstance(); mBody = gameWorld->getPhysicsWorld()->CreateBody(&bodyDef); /// Hitbox instantiation b2PolygonShape box; /// Set Box Shape box.SetAsBox(12.0f, .9f);// look up other functions for polygons // boxFixtureDef.shape = &box; boxFixtureDef.density = 1; // Create Fixture mFixture = mBody->CreateFixture(&boxFixtureDef); mBody->SetUserData(gameObjectRef); mBody->SetTransform(b2Vec2(gameObjectRef->posX/worldScale, gameObjectRef->posY/worldScale), 0); setCollisionFilter(COLLISION_PLATFORM, COLLISION_PLAYER | COLLISION_MINION | COLLISION_MINE); }