From 5b425f27aec3d5576fcd7fbacfa9c181f57355e6 Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Tue, 6 Oct 2015 15:31:48 +0200 Subject: [PATCH] Fixed invisible item bug, maybe. Put 0.1 sec hitlag on impact with pad. Stable level loading? --- include/Game/BallSystem.h | 4 ++++ include/Game/CBrick.h | 2 -- include/Game/CPad.h | 3 --- src/game/Game/BallSystem.cpp | 23 ++++++++++++++++++++++- src/game/Game/LevelSystem.cpp | 27 +++++++++++++++------------ src/game/Physics/PhysicsSystem.cpp | 5 ++++- 6 files changed, 45 insertions(+), 19 deletions(-) diff --git a/include/Game/BallSystem.h b/include/Game/BallSystem.h index 682b1c9..1d06e6b 100644 --- a/include/Game/BallSystem.h +++ b/include/Game/BallSystem.h @@ -8,12 +8,14 @@ #include "Core/CTemplate.h" #include "Physics/CPhysics.h" #include "Physics/CCircleShape.h" +#include "Physics/CRectangleShape.h" #include "Physics/EContact.h" #include "Rendering/CModel.h" #include "Rendering/CPointLight.h" #include "Game/CBall.h" #include "Game/CPowerUp.h" #include "Game/CLife.h" +#include "Game/CBrick.h" #include "Game/ELifeLost.h" #include "Game/EComboEvent.h" #include "Game/EResetBall.h" @@ -22,6 +24,7 @@ #include "Game/EGameOver.h" #include "Game/EPause.h" #include "Game/EHitPad.h" +#include "Game/EHitLag.h" namespace dd { @@ -90,6 +93,7 @@ private: bool m_ReplaceBall = false; bool m_MultiBall = false; bool m_Pause = false; + EntityID m_LastCollision = 999999; glm::vec3 m_SavedSpeed; bool m_InitializePause = false; diff --git a/include/Game/CBrick.h b/include/Game/CBrick.h index d44ab02..893f157 100644 --- a/include/Game/CBrick.h +++ b/include/Game/CBrick.h @@ -15,8 +15,6 @@ namespace Components struct Brick : Component { - int Points = 10; - int Hits = 1; int Score = 50; bool Removed = false; }; diff --git a/include/Game/CPad.h b/include/Game/CPad.h index 15afebd..9d9c702 100644 --- a/include/Game/CPad.h +++ b/include/Game/CPad.h @@ -17,9 +17,6 @@ namespace Components struct Pad : Component { - int Lives; - int Points; - float SlowdownModifier = 5.f; float AccelerationSpeed = 40.f; float MaxSpeed = 5.f; diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index 21a32ca..7be7d8a 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -224,6 +224,23 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event) //TODO: Add support for power-up collisions } + auto brick = m_World->GetComponent(otherEntitiy); + if (brick != nullptr) { + auto transform = m_World->GetComponent(otherEntitiy); + auto physics = m_World->GetComponent(otherEntitiy); + auto rectangle = m_World->GetComponent(otherEntitiy); + int hey = 5; + } + + /*if (otherEntitiy == m_LastCollision) { + + if (brick != nullptr) { + return false; + } + } else { + m_LastCollision = otherEntitiy; + }*/ + //if this is a brick thats dead do not collide :) auto ballTransform = m_World->GetComponent(ballEntity); @@ -232,6 +249,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); auto padTransform = m_World->GetComponent(otherEntitiy); float x = (ballTransform->Position.x - padTransform->Position.x) * XMovementMultiplier(); @@ -260,7 +281,7 @@ EntityID dd::Systems::BallSystem::CreateBall() m_World->RemoveComponent(ent); - m_World->CommitEntity(ent); + //m_World->CommitEntity(ent); return ent; } diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index de9c2f6..c74c60b 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -164,32 +164,33 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe SetNumberOfBricks(NumberOfBricks() - 1); return; } - //auto brick = m_World->CloneEntity(m_BrickTemplate); - //m_World->RemoveComponent(brick); - //auto transform = m_World->GetComponent(brick); - //auto cBrick = m_World->GetComponent(brick); - //auto cPhys = m_World->GetComponent(brick); - auto brick = m_World->CreateEntity(); + auto brick = m_World->CloneEntity(m_BrickTemplate); + m_World->RemoveComponent(brick); + auto transform = m_World->GetComponent(brick); + auto cBrick = m_World->GetComponent(brick); + auto cPhys = m_World->GetComponent(brick); + + /*auto brick = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(brick); auto model = m_World->AddComponent(brick); std::shared_ptr cBrick = m_World->AddComponent(brick); std::shared_ptr cRec = m_World->AddComponent(brick); - std::shared_ptr cPhys = m_World->AddComponent(brick); + std::shared_ptr cPhys = m_World->AddComponent(brick);*/ //std::shared_ptr cTemplate = m_World->AddComponent(brick); cPhys->Static = false; cPhys->GravityScale = 0.f; cPhys->Category = CollisionLayer::Type::Brick; cPhys->Mask = CollisionLayer::Type::Ball; - model->ModelFile = "Models/Test/Brick/Brick.obj"; + //model->ModelFile = "Models/Test/Brick/Brick.obj"; /*if ((line == 1 && row == 4) || (line == 3 && row == 2) || (line == 5 && row == 2)) { std::shared_ptr cPow = m_World->AddComponent(brick); }*/ - transform->Scale = glm::vec3(0.8, 0.2, 0.2); - if (typeInt == 2) { + //transform->Scale = glm::vec3(0.8, 0.2, 0.2); + /*if (typeInt == 2) { std::shared_ptr cPow = m_World->AddComponent(brick); - } + }*/ float x = line * spacesBetweenBricks.x; float y = row * spacesBetweenBricks.y; transform->Scale = glm::vec3(0.8, 0.2, 0.2); @@ -245,7 +246,9 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event) EventBroker->Publish(e); } - if (!Restarting()) { + if (!Restarting() && !brick->Removed) { + brick->Removed = true; + // Hit brick with ball code. ball->Combo += 1; Events::ComboEvent ec; ec.Combo = ball->Combo; diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp index e585c57..f1f4030 100644 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -212,7 +212,10 @@ void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity) } if (physicsComponent) { - CreateBody(entity); + auto it = m_EntitiesToBodies.find(entity); + if(it == m_EntitiesToBodies.end()) { + CreateBody(entity); + } } else if (waterComponent) { CreateParticleGroup(entity); } else if (particleEmitterComponent) {