Merge remote-tracking branch 'origin/master' into LevelSystemAndSuch
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
# Blender MTL File: 'Lifebuoy.blend'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl Material.001
|
||||||
|
Ns 96.078431
|
||||||
|
Ka 0.000000 0.000000 0.000000
|
||||||
|
Kd 0.640000 0.640000 0.640000
|
||||||
|
Ks 0.500000 0.500000 0.500000
|
||||||
|
Ni 1.000000
|
||||||
|
d 1.000000
|
||||||
|
illum 2
|
||||||
|
map_Kd LifebuoyTexture.png
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 122 B |
@@ -273,6 +273,8 @@ public:
|
|||||||
rectangleShape->Dimensions = glm::vec2(20.f, 0.5f);
|
rectangleShape->Dimensions = glm::vec2(20.f, 0.5f);
|
||||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(BottomWall);
|
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(BottomWall);
|
||||||
physics->CollisionType = CollisionType::Type::Static;
|
physics->CollisionType = CollisionType::Type::Static;
|
||||||
|
physics->Category = CollisionLayer::Wall;
|
||||||
|
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::LifeBuoy);
|
||||||
transform->Sticky = true;
|
transform->Sticky = true;
|
||||||
m_World->CommitEntity(BottomWall);
|
m_World->CommitEntity(BottomWall);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "Game/EHitPad.h"
|
#include "Game/EHitPad.h"
|
||||||
#include "Game/EHitLag.h"
|
#include "Game/EHitLag.h"
|
||||||
#include "Game/EActionButton.h"
|
#include "Game/EActionButton.h"
|
||||||
|
#include "Game/CLifebuoy.h"
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -52,6 +52,16 @@ private:
|
|||||||
bool OnContact(const dd::Events::Contact &event);
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
bool OnPause(const dd::Events::Pause &event);
|
bool OnPause(const dd::Events::Pause &event);
|
||||||
bool OnLifebuoy(const dd::Events::Lifebuoy &event);
|
bool OnLifebuoy(const dd::Events::Lifebuoy &event);
|
||||||
|
|
||||||
|
struct LifeBuoyInfo
|
||||||
|
{
|
||||||
|
EntityID Entity;
|
||||||
|
float TimeToLive = 15.f;
|
||||||
|
};
|
||||||
|
|
||||||
|
float m_LeftEdge = -3.8f;
|
||||||
|
float m_RightEdge = 3.8f;
|
||||||
|
std::list<LifeBuoyInfo> m_LifeBuoys;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ enum Type
|
|||||||
PowerUp = 1 << 4,
|
PowerUp = 1 << 4,
|
||||||
Other = 1 << 5,
|
Other = 1 << 5,
|
||||||
Wall = 1 << 6,
|
Wall = 1 << 6,
|
||||||
|
LifeBuoy = 1 << 7,
|
||||||
Projectile = 1 << 8
|
Projectile = 1 << 8
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ enum Type
|
|||||||
|
|
||||||
bool Calculate = false;
|
bool Calculate = false;
|
||||||
float GravityScale = 0.f;
|
float GravityScale = 0.f;
|
||||||
float Density = 10.f;
|
float Density = 20.f;
|
||||||
|
|
||||||
|
|
||||||
CollisionLayer::Type Category = CollisionLayer::Type::Other;
|
CollisionLayer::Type Category = CollisionLayer::Type::Other;
|
||||||
@@ -52,6 +52,7 @@ enum Type
|
|||||||
| CollisionLayer::Water
|
| CollisionLayer::Water
|
||||||
| CollisionLayer::PowerUp
|
| CollisionLayer::PowerUp
|
||||||
| CollisionLayer::Wall
|
| CollisionLayer::Wall
|
||||||
|
| CollisionLayer::LifeBuoy
|
||||||
| CollisionLayer::Other
|
| CollisionLayer::Other
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ void dd::Systems::BallSystem::Initialize()
|
|||||||
std::shared_ptr<Components::Template> ballTemplate = m_World->AddComponent<Components::Template>(ent);
|
std::shared_ptr<Components::Template> ballTemplate = m_World->AddComponent<Components::Template>(ent);
|
||||||
physics->CollisionType = CollisionType::Type::Dynamic;
|
physics->CollisionType = CollisionType::Type::Dynamic;
|
||||||
physics->Category = CollisionLayer::Type::Ball;
|
physics->Category = CollisionLayer::Type::Ball;
|
||||||
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall);
|
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall | CollisionLayer::LifeBuoy);
|
||||||
physics->Calculate = true;
|
physics->Calculate = true;
|
||||||
transform->Sticky = true;
|
transform->Sticky = true;
|
||||||
|
|
||||||
@@ -247,13 +247,13 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
//TODO: Add support for power-up collisions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
auto ballTransform = m_World->GetComponent<Components::Transform>(ballEntity);
|
auto ballTransform = m_World->GetComponent<Components::Transform>(ballEntity);
|
||||||
glm::vec2 ballVelocity = glm::vec2(ballTransform->Velocity.x, ballTransform->Velocity.y);
|
glm::vec2 ballVelocity = glm::vec2(ballTransform->Velocity.x, ballTransform->Velocity.y);
|
||||||
|
|
||||||
|
|
||||||
if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Pad") {
|
if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Pad") {
|
||||||
auto padTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
|
auto padTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
|
||||||
|
|
||||||
@@ -294,8 +294,11 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
|||||||
ec.Ball = ballEntity;
|
ec.Ball = ballEntity;
|
||||||
EventBroker->Publish(ec);
|
EventBroker->Publish(ec);
|
||||||
//std::cout << "Combo: " << ballComponent->Combo << std::endl;
|
//std::cout << "Combo: " << ballComponent->Combo << std::endl;
|
||||||
}
|
} // Lifebuoy should always reflect the ball upwards
|
||||||
else {
|
else if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Lifebuoy"){
|
||||||
|
ballTransform->Velocity = glm::vec3(ballTransform->Velocity.x, abs(ballTransform->Velocity.y), ballTransform->Velocity.z);
|
||||||
|
|
||||||
|
} else {
|
||||||
auto it = m_Contacts.find(ballEntity);
|
auto it = m_Contacts.find(ballEntity);
|
||||||
if (it == m_Contacts.end()) {
|
if (it == m_Contacts.end()) {
|
||||||
std::list<glm::vec2> normalList;
|
std::list<glm::vec2> normalList;
|
||||||
@@ -316,20 +319,13 @@ void dd::Systems::BallSystem::ResolveContacts()
|
|||||||
{
|
{
|
||||||
|
|
||||||
for (auto c : m_Contacts) {
|
for (auto c : m_Contacts) {
|
||||||
int count = 0;
|
|
||||||
EntityID entity = c.first;
|
EntityID entity = c.first;
|
||||||
std::list<glm::vec2> contactNormals = c.second;
|
std::list<glm::vec2> contactNormals = c.second;
|
||||||
glm::vec2 finalNormal = glm::vec2(0.f);
|
glm::vec2 finalNormal = glm::vec2(0.f);
|
||||||
for (auto it = contactNormals.begin(); it != contactNormals.end(); it++) {
|
for (auto it = contactNormals.begin(); it != contactNormals.end(); it++) {
|
||||||
finalNormal = finalNormal + (*it);
|
finalNormal = finalNormal + (*it);
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
finalNormal = glm::normalize(finalNormal);
|
finalNormal = glm::normalize(finalNormal);
|
||||||
|
|
||||||
if (count > 1) {
|
|
||||||
LOG_INFO("MultiCollision %i", count);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
glm::vec2 velocity = glm::vec2(transform->Velocity.x, transform->Velocity.y);
|
glm::vec2 velocity = glm::vec2(transform->Velocity.x, transform->Velocity.y);
|
||||||
glm::vec2 reflectedVelocity = glm::reflect(velocity, finalNormal);
|
glm::vec2 reflectedVelocity = glm::reflect(velocity, finalNormal);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ void dd::Systems::LevelSystem::Initialize()
|
|||||||
cPhys->CollisionType = CollisionType::Type::Static;
|
cPhys->CollisionType = CollisionType::Type::Static;
|
||||||
cPhys->GravityScale = 0.f;
|
cPhys->GravityScale = 0.f;
|
||||||
cPhys->Category = CollisionLayer::Type::Brick;
|
cPhys->Category = CollisionLayer::Type::Brick;
|
||||||
cPhys->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Type::Ball | CollisionLayer::Type::Projectile);
|
cPhys->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Type::Ball | CollisionLayer::Type::Projectile | CollisionLayer::Type::Wall | CollisionLayer::LifeBuoy);
|
||||||
transform->Sticky = false;
|
transform->Sticky = false;
|
||||||
|
|
||||||
model->ModelFile = "Models/Brick/WhiteBrick.obj";
|
model->ModelFile = "Models/Brick/WhiteBrick.obj";
|
||||||
|
|||||||
@@ -21,16 +21,16 @@ void dd::Systems::LifebuoySystem::Initialize()
|
|||||||
ctransform->Position = glm::vec3(50.f, -4.8f, -10.f);
|
ctransform->Position = glm::vec3(50.f, -4.8f, -10.f);
|
||||||
auto rectangleShape = m_World->AddComponent<Components::RectangleShape>(ent);
|
auto rectangleShape = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||||
auto lifebuoyTemplate = m_World->AddComponent<Components::Template>(ent);
|
auto lifebuoyTemplate = m_World->AddComponent<Components::Template>(ent);
|
||||||
rectangleShape->Dimensions = glm::vec2(1.f, 0.1f);
|
rectangleShape->Dimensions = glm::vec2(0.9f, 0.19f);
|
||||||
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
||||||
physics->CollisionType = CollisionType::Type::Static;
|
physics->CollisionType = CollisionType::Type::Static;
|
||||||
physics->Category = CollisionLayer::Type::Other;
|
physics->Category = CollisionLayer::LifeBuoy;
|
||||||
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::Pad | CollisionLayer::Wall | CollisionLayer::Water);
|
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::Brick | CollisionLayer::LifeBuoy | CollisionLayer::Pad | CollisionLayer::Water);
|
||||||
physics->Density = 0.001;
|
physics->Density = 1.0f;
|
||||||
physics->GravityScale = 1;
|
physics->GravityScale = 1;
|
||||||
ctransform->Sticky = true;
|
ctransform->Sticky = true;
|
||||||
auto cModel = m_World->AddComponent<Components::Model>(ent);
|
auto cModel = m_World->AddComponent<Components::Model>(ent);
|
||||||
cModel->ModelFile = "Models/Ship/Ship.obj";
|
cModel->ModelFile = "Models/Lifebuoy/Lifebuoy.obj";
|
||||||
auto lifebuoy = m_World->AddComponent<Components::Lifebuoy>(ent);
|
auto lifebuoy = m_World->AddComponent<Components::Lifebuoy>(ent);
|
||||||
|
|
||||||
m_World->CommitEntity(ent);
|
m_World->CommitEntity(ent);
|
||||||
@@ -43,7 +43,24 @@ void dd::Systems::LifebuoySystem::Initialize()
|
|||||||
|
|
||||||
void dd::Systems::LifebuoySystem::Update(double dt)
|
void dd::Systems::LifebuoySystem::Update(double dt)
|
||||||
{
|
{
|
||||||
|
for (auto it = m_LifeBuoys.begin(); it != m_LifeBuoys.end();) {
|
||||||
|
it->TimeToLive -= dt;
|
||||||
|
if (it->TimeToLive < 0.f) {
|
||||||
|
m_World->RemoveEntity(it->Entity);
|
||||||
|
m_LifeBuoys.erase(it++);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto transformComponent = m_World->GetComponent<Components::Transform>(it->Entity);
|
||||||
|
|
||||||
|
if (transformComponent->Position.x > m_RightEdge) {
|
||||||
|
transformComponent->Position = glm::vec3(m_LeftEdge + 0.1f, transformComponent->Position.y, transformComponent->Position.z);
|
||||||
|
}
|
||||||
|
else if (transformComponent->Position.x < m_LeftEdge) {
|
||||||
|
transformComponent->Position = glm::vec3(m_RightEdge - 0.1f, transformComponent->Position.y, transformComponent->Position.z);
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::LifebuoySystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
void dd::Systems::LifebuoySystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
@@ -79,10 +96,16 @@ bool dd::Systems::LifebuoySystem::OnContact(const dd::Events::Contact &event)
|
|||||||
bool dd::Systems::LifebuoySystem::OnLifebuoy(const dd::Events::Lifebuoy &event)
|
bool dd::Systems::LifebuoySystem::OnLifebuoy(const dd::Events::Lifebuoy &event)
|
||||||
{
|
{
|
||||||
auto ent = m_World->CloneEntity(m_Template);
|
auto ent = m_World->CloneEntity(m_Template);
|
||||||
|
m_World->SetProperty(ent, "Name", "Lifebuoy");
|
||||||
m_World->RemoveComponent<Components::Template>(ent);
|
m_World->RemoveComponent<Components::Template>(ent);
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(ent);
|
auto transform = m_World->GetComponent<Components::Transform>(ent);
|
||||||
auto physics = m_World->GetComponent<Components::Physics>(ent);
|
auto physics = m_World->GetComponent<Components::Physics>(ent);
|
||||||
physics->CollisionType = CollisionType::Type::Dynamic;
|
physics->CollisionType = CollisionType::Type::Dynamic;
|
||||||
transform->Position = glm::vec3(event.Transform->Position.x, transform->Position.y, -10.f);
|
transform->Position = glm::vec3(event.Transform->Position.x, transform->Position.y + 2.f, -10.f);
|
||||||
|
transform->Velocity = glm::vec3(20.f, 3.f, 0.f);
|
||||||
|
LifeBuoyInfo info;
|
||||||
|
info.Entity = ent;
|
||||||
|
m_LifeBuoys.push_back(info);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,9 +38,9 @@ void dd::Systems::PadSystem::Initialize()
|
|||||||
auto rectangleShape = m_World->AddComponent<Components::RectangleShape>(ent);
|
auto rectangleShape = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||||
rectangleShape->Dimensions = glm::vec2(1.f, 0.1f);
|
rectangleShape->Dimensions = glm::vec2(1.f, 0.1f);
|
||||||
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
||||||
physics->CollisionType = CollisionType::Type::Dynamic;
|
physics->CollisionType = CollisionType::Type::Kinematic;
|
||||||
physics->Category = CollisionLayer::Type::Pad;
|
physics->Category = CollisionLayer::Type::Pad;
|
||||||
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::PowerUp);
|
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Ball | CollisionLayer::PowerUp | CollisionLayer::LifeBuoy);
|
||||||
physics->Calculate = true;
|
physics->Calculate = true;
|
||||||
ctransform->Sticky = true;
|
ctransform->Sticky = true;
|
||||||
auto cModel = m_World->AddComponent<Components::Model>(ent);
|
auto cModel = m_World->AddComponent<Components::Model>(ent);
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ void dd::Systems::PhysicsSystem::ContactListener::BeginContact(b2Contact* contac
|
|||||||
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
||||||
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
|
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
|
||||||
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
|
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
|
||||||
|
|
||||||
m_PhysicsSystem->EventBroker->Publish(e);
|
m_PhysicsSystem->EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,10 +28,17 @@ void dd::Systems::PhysicsSystem::ContactListener::PreSolve(b2Contact* contact, c
|
|||||||
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
|
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
|
||||||
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
|
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
|
||||||
|
|
||||||
|
|
||||||
|
std::string propertyA = m_PhysicsSystem->m_World->GetProperty<std::string>(entityA, "Name");
|
||||||
|
std::string propertyB = m_PhysicsSystem->m_World->GetProperty<std::string>(entityB, "Name");
|
||||||
|
|
||||||
if (physicsComponentA != nullptr && physicsComponentB != nullptr) {
|
if (physicsComponentA != nullptr && physicsComponentB != nullptr) {
|
||||||
if (physicsComponentA->Calculate || physicsComponentB->Calculate) {
|
if (physicsComponentA->Calculate || physicsComponentB->Calculate) {
|
||||||
// Turn of collisions
|
// Turn of collisions
|
||||||
contact->SetEnabled(false);
|
if ((propertyA != "Lifebuoy" && propertyB != "Pad") || (propertyA != "Pad" && propertyB != "Lifebuoy")) {
|
||||||
|
contact->SetEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,10 +34,9 @@ void dd::Systems::PhysicsSystem::InitializeWater()
|
|||||||
b2ParticleSystemDef m_ParticleSystemDef;
|
b2ParticleSystemDef m_ParticleSystemDef;
|
||||||
m_ParticleSystemDef.radius = radius;
|
m_ParticleSystemDef.radius = radius;
|
||||||
m_ParticleSystemDef.gravityScale = gravityScale;
|
m_ParticleSystemDef.gravityScale = gravityScale;
|
||||||
|
m_ParticleSystemDef.density = 4.f;
|
||||||
|
|
||||||
m_WaterParticleSystem = m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
m_WaterParticleSystem = m_PhysicsWorld->CreateParticleSystem(&m_ParticleSystemDef);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
|
bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
|
||||||
|
|||||||
Reference in New Issue
Block a user