Falling bricks and collision filters
This commit is contained in:
+14
-1
@@ -135,6 +135,9 @@ public:
|
||||
ball->Speed = 5.f;
|
||||
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;
|
||||
|
||||
auto plight = m_World->AddComponent<Components::PointLight>(ent);
|
||||
plight->Radius = 2.f;
|
||||
@@ -176,6 +179,8 @@ public:
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
|
||||
physics->Static = true;
|
||||
physics->Category = CollisionLayer::Type::Wall;
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
|
||||
|
||||
m_World->CommitEntity(topWall);
|
||||
}
|
||||
@@ -192,6 +197,8 @@ public:
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(leftWall);
|
||||
physics->Static = true;
|
||||
physics->Category = CollisionLayer::Type::Wall;
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
|
||||
|
||||
m_World->CommitEntity(leftWall);
|
||||
}
|
||||
@@ -208,6 +215,8 @@ public:
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(rightWall);
|
||||
physics->Static = true;
|
||||
physics->Category = CollisionLayer::Type::Wall;
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
|
||||
|
||||
m_World->CommitEntity(rightWall);
|
||||
}
|
||||
@@ -221,8 +230,12 @@ public:
|
||||
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->Static = false;
|
||||
physics->Category = CollisionLayer::Type::Pad;
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::PowerUp;
|
||||
physics->Calculate = true;
|
||||
auto cModel = m_World->AddComponent<Components::Model>(ent);
|
||||
cModel->ModelFile = "Models/Submarine.obj";
|
||||
cModel->ModelFile = "Models/Submarine2.obj";
|
||||
|
||||
auto pad = m_World->AddComponent<Components::Pad>(ent);
|
||||
m_World->CommitEntity(ent);
|
||||
}
|
||||
|
||||
@@ -4,18 +4,40 @@
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace CollisionLayer
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
Pad = 1 << 0,
|
||||
Ball = 1 << 1,
|
||||
Brick = 1 << 2,
|
||||
Water = 1 << 3,
|
||||
PowerUp = 1 << 4,
|
||||
Other = 1 << 5,
|
||||
Wall = 1 << 6
|
||||
};
|
||||
}
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Physics: public Component
|
||||
{
|
||||
//idk if anything should be here :)
|
||||
bool Static = true;
|
||||
bool Calculate = false;
|
||||
float GravityScale = 0.f;
|
||||
CollisionLayer::Type Category = CollisionLayer::Type::Other;
|
||||
CollisionLayer::Type Mask =
|
||||
CollisionLayer::Type::Pad |
|
||||
CollisionLayer::Type::Ball |
|
||||
CollisionLayer::Type::Brick |
|
||||
CollisionLayer::Type::Water |
|
||||
CollisionLayer::Type::PowerUp |
|
||||
CollisionLayer::Type::Wall |
|
||||
CollisionLayer::Type::Other;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_CPHYSICS_H
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "Physics/CCircleShape.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Game/CPad.h"
|
||||
#include "Game/CBall.h"
|
||||
|
||||
|
||||
namespace dd
|
||||
@@ -102,16 +103,19 @@ private:
|
||||
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
|
||||
{
|
||||
EntityID entityA = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
||||
EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
||||
EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
||||
|
||||
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
|
||||
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
|
||||
|
||||
if (physicsComponentA != nullptr || physicsComponentB != nullptr) {
|
||||
// Turn of collisions
|
||||
contact->SetEnabled(false);
|
||||
if (physicsComponentA != nullptr && physicsComponentB != nullptr) {
|
||||
if (physicsComponentA->Calculate || physicsComponentB->Calculate) {
|
||||
// Turn of collisions
|
||||
contact->SetEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user