diff --git a/include/Core/Engine.h b/include/Core/Engine.h index 27c7d6a..d58488c 100644 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -237,51 +237,22 @@ public: //TODO: Why does the ball not collide with these bricks? //BottomBox { - auto topWall = m_World->CreateEntity(); - auto transform = m_World->AddComponent(topWall); - transform->Position = glm::vec3(0.f, -6.f, -9.9f); - transform->Scale = glm::vec3(10.f, 0.5f, 1.f); - std::shared_ptr sprite = m_World->AddComponent(topWall); + auto BottomWall = m_World->CreateEntity(); + auto transform = m_World->AddComponent(BottomWall); + transform->Position = glm::vec3(0.f, -6.f, -10.f); + transform->Scale = glm::vec3(20.f, 0.5f, 1.f); + std::shared_ptr sprite = m_World->AddComponent(BottomWall); sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; - std::shared_ptr rectangleShape = m_World->AddComponent(topWall); - rectangleShape->Dimensions = glm::vec2(10.f, 0.5f); - std::shared_ptr physics = m_World->AddComponent(topWall); + std::shared_ptr rectangleShape = m_World->AddComponent(BottomWall); + rectangleShape->Dimensions = glm::vec2(20.f, 0.5f); + std::shared_ptr physics = m_World->AddComponent(BottomWall); physics->CollisionType = CollisionType::Type::Static; - m_World->CommitEntity(topWall); + m_World->CommitEntity(BottomWall); } - //SideBox -// { -// auto topWall = m_World->CreateEntity(); -// std::shared_ptr transform = m_World->AddComponent(topWall); -// transform->Position = glm::vec3(3.f, -3.0f, -9.9f); -// transform->Scale = glm::vec3(0.5f, 3.f, 1.f); -// std::shared_ptr sprite = m_World->AddComponent(topWall); -// sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; -// std::shared_ptr boxShape = m_World->AddComponent( -// topWall); -// std::shared_ptr physics = m_World->AddComponent(topWall); -// physics->Static = true; -// m_World->CommitEntity(topWall); -// } -// //OtherSideBox -// { -// auto topWall = m_World->CreateEntity(); -// std::shared_ptr transform = m_World->AddComponent(topWall); -// transform->Position = glm::vec3(-4.f, -3.0f, -9.9f); -// transform->Scale = glm::vec3(0.5f, 3.0f, 1.f); -// std::shared_ptr sprite = m_World->AddComponent(topWall); -// sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; -// std::shared_ptr boxShape = m_World->AddComponent( -// topWall); -// std::shared_ptr physics = m_World->AddComponent(topWall); -// physics->Static = true; -// m_World->CommitEntity(topWall); -// } { auto topWall = m_World->CreateEntity(); - std::shared_ptr transform = m_World->AddComponent( - topWall); + std::shared_ptr transform = m_World->AddComponent(topWall); transform->Position = glm::vec3(0.f, 6.f, -10.f); transform->Scale = glm::vec3(20.f, 0.5f, 1.f); diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index b5a86c7..4026bfe 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -72,6 +72,8 @@ void dd::Systems::BallSystem::Update(double dt) void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { + //TODO: When the ball collides with 2 bricks on the same frame it is reflected and then reflected again, make it reflect only once like a list or something? + auto ballComponent = m_World->GetComponent(entity); if (IsPaused()) { if (ballComponent != nullptr) { @@ -128,7 +130,8 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID EventBroker->Publish(e); return; } - } else if (transformBall->Position.x > EdgeX()) { + } //Removing this made the wall collisions work again + /*else if (transformBall->Position.x > EdgeX()) { if (transformBall->Velocity.x > 0) { glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(1, 0)); transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f); @@ -143,7 +146,7 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(0, 1)); transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f); } - } + }*/ } if (Lives() != PastLives()) { @@ -250,10 +253,10 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event) if (m_World->GetProperty(otherEntitiy, "Name") == "Pad"){ Events::HitPad e; EventBroker->Publish(e); - Events::HitLag el; - el.Time = 0.1f; - el.Type = "All"; - EventBroker->Publish(el); + // Events::HitLag el; + // el.Time = 0.1f; + //el.Type = "All"; + // EventBroker->Publish(el); auto padTransform = m_World->GetComponent(otherEntitiy); float x = (ballTransform->Position.x - padTransform->Position.x) * XMovementMultiplier(); diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp index 9365048..b24f2d8 100644 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -27,9 +27,8 @@ void dd::Systems::PhysicsSystem::InitializeWater() bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event) { - b2Body* body = m_EntitiesToBodies[event.Entity]; - - if (body == nullptr) { + auto it = m_EntitiesToBodies.find(event.Entity); + if(it == m_EntitiesToBodies.end()) { LOG_ERROR("Entity: %i, Tried to set an impulse on a body that does not exsist", event.Entity); return false; } @@ -43,7 +42,7 @@ bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event) point.y = event.Point.y; Impulse i; - i.Body = body; + i.Body = it->second; i.Impulse = impulse; i.Point = point; @@ -244,21 +243,21 @@ void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity) void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity) { - auto physics = m_World->GetComponent(entity); + /* auto physics = m_World->GetComponent(entity); if (physics == nullptr) { return; - } + }*/ - b2Body* body = m_EntitiesToBodies[entity]; - if (body == nullptr) { + auto it = m_EntitiesToBodies.find(entity); + if(it == m_EntitiesToBodies.end()) { LOG_ERROR("Trying to remove non-exsisting body, Entity: %i", entity); return; } + LOG_INFO("Removing entity %i", entity); + it->second->GetWorld()->DestroyBody(it->second); + m_BodiesToEntities.erase(it->second); m_EntitiesToBodies.erase(entity); - m_BodiesToEntities.erase(body); - - body->GetWorld()->DestroyBody(body); //delete body; }