Falling bricks and collision filters
This commit is contained in:
@@ -60,9 +60,10 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||
return false;
|
||||
}
|
||||
|
||||
//Which is the ball?
|
||||
|
||||
EntityID ballEntity, otherEntitiy;
|
||||
|
||||
//Which is the ball?
|
||||
if (ballComponent1 != nullptr) {
|
||||
ballEntity = event.Entity1;
|
||||
otherEntitiy = event.Entity2;
|
||||
@@ -78,6 +79,8 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||
//TODO: Add support for power-up collisions
|
||||
}
|
||||
|
||||
//if this is a brick thats dead do not collide :)
|
||||
|
||||
auto ballTransform = m_World->GetComponent<Components::Transform>(ballEntity);
|
||||
glm::vec2 ballVelocity = glm::vec2(ballTransform->Velocity.x, ballTransform->Velocity.y);
|
||||
|
||||
@@ -85,7 +88,6 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||
auto padTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
|
||||
float x = ballTransform->Position.x - padTransform->Position.x;
|
||||
|
||||
float movementMultiplier = 5.0f;
|
||||
float y = glm::cos((abs(x) / (1.6f)) * glm::pi<float>() / 2.f) + 1.f;
|
||||
|
||||
ballTransform->Velocity = glm::normalize(glm::vec3(x, y ,0.f)) * ballComponent->Speed;
|
||||
|
||||
@@ -176,6 +176,9 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
||||
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(brick);
|
||||
cPhys->Static = false;
|
||||
cPhys->GravityScale = 0.f;
|
||||
cPhys->Category = CollisionLayer::Type::Brick;
|
||||
cPhys->Mask = CollisionLayer::Type::Ball;
|
||||
|
||||
std::string fileName = "Textures/Bricks/";
|
||||
fileName.append(std::to_string(num));
|
||||
fileName.append(".png");
|
||||
@@ -270,6 +273,20 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entityBrick);
|
||||
physicsComponent->GravityScale = 1.f;
|
||||
physicsComponent->Mask = CollisionLayer::Type::Water | CollisionLayer::Type::Wall;
|
||||
|
||||
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick);
|
||||
auto transformComponentBall = m_World->GetComponent<Components::Transform>(entityBall);
|
||||
|
||||
Events::SetImpulse e;
|
||||
e.Entity = entityBrick;
|
||||
|
||||
glm::vec2 point = glm::vec2(transformComponentBrick->Position.x + ((transformComponentBrick->Position.x - transformComponentBall->Position.x)/4), transformComponentBrick->Position.y + ((transformComponentBrick->Position.y - transformComponentBall->Position.y )/4));
|
||||
|
||||
e.Impulse = glm::normalize(point)/2.f;
|
||||
e.Point = point;
|
||||
EventBroker->Publish(e);
|
||||
//TODO: Bricks dont collide with walls D=
|
||||
|
||||
SetNumberOfBricks(NumberOfBricks() - 1);
|
||||
if (NumberOfBricks() <= 0) {
|
||||
@@ -279,7 +296,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
es.Score = brick->Score;
|
||||
EventBroker->Publish(es);
|
||||
|
||||
std::cout << NumberOfBricks() << std::endl;
|
||||
// std::cout << NumberOfBricks() << std::endl;
|
||||
//std::cout << "Score: " << Score() << std::endl;
|
||||
}
|
||||
|
||||
@@ -313,8 +330,12 @@ bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &
|
||||
auto model = m_World->AddComponent<Components::Model>(powerUp);
|
||||
std::shared_ptr<Components::CircleShape> cRec = m_World->AddComponent<Components::CircleShape>(powerUp);
|
||||
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(powerUp);
|
||||
std::shared_ptr<Components::PowerUp> cPow = m_World->AddComponent<Components::PowerUp>(powerUp);
|
||||
cPhys->Static = false;
|
||||
cPhys->Category = CollisionLayer::Type::PowerUp;
|
||||
cPhys->Mask = CollisionLayer::Type::Pad;
|
||||
|
||||
std::shared_ptr<Components::PowerUp> cPow = m_World->AddComponent<Components::PowerUp>(powerUp);
|
||||
|
||||
|
||||
transform->Position = event.Position;
|
||||
transform->Scale = glm::vec3(0.2, 0.2, 0.2);
|
||||
|
||||
@@ -108,7 +108,9 @@ EntityID dd::Systems::PadSystem::CreateBall()
|
||||
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->Static = false;
|
||||
|
||||
physics->Category = CollisionLayer::Type::Ball;
|
||||
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
|
||||
physics->Calculate = true;
|
||||
cball->Speed = 5.f;
|
||||
|
||||
m_World->CommitEntity(ent);
|
||||
@@ -234,9 +236,9 @@ bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
|
||||
return false;
|
||||
}
|
||||
|
||||
m_World->RemoveComponent<Components::PowerUp>(entityPower);
|
||||
m_World->RemoveComponent<Components::CircleShape>(entityPower);
|
||||
m_World->RemoveComponent<Components::Physics>(entityPower);
|
||||
// m_World->RemoveComponent<Components::PowerUp>(entityPower);
|
||||
// m_World->RemoveComponent<Components::CircleShape>(entityPower);
|
||||
// m_World->RemoveComponent<Components::Physics>(entityPower);
|
||||
m_World->RemoveEntity(entityPower);
|
||||
Events::PowerUpTaken ep;
|
||||
ep.Name = "Something";
|
||||
|
||||
Reference in New Issue
Block a user