diff --git a/include/Game/CBall.h b/include/Game/CBall.h index 9a7933f..17ebbaf 100644 --- a/include/Game/CBall.h +++ b/include/Game/CBall.h @@ -24,6 +24,8 @@ struct Ball : Component bool Sticky = false; glm::vec3 StickyPlacement = glm::vec3(0, 0, 0); glm::vec3 SavedSpeed = glm::vec3(0, 1, 0); + + int PosterBoy = 0; }; } diff --git a/include/Game/CBrick.h b/include/Game/CBrick.h index 7a5ae15..4e3a5af 100644 --- a/include/Game/CBrick.h +++ b/include/Game/CBrick.h @@ -20,6 +20,8 @@ struct Brick : Component int Type = 0; bool Removed = false; int Number = 100; // For the Kraken to keep track of which bricks needs replacing. + bool BeingGenerated = false; + glm::vec3 GenerationGoal; //What number of types each is. const int EmptyBrickSpace = 0; diff --git a/include/Game/CLife.h b/include/Game/CLife.h index aeca335..73266fd 100644 --- a/include/Game/CLife.h +++ b/include/Game/CLife.h @@ -13,10 +13,11 @@ namespace dd namespace Components { -struct Life : Component { - +struct Life : Component +{ int Number = 0; - + float SinusAltitude = 1; + bool Left = false; }; } diff --git a/include/Game/LifeSystem.h b/include/Game/LifeSystem.h index 249e9ee..2e7f0af 100644 --- a/include/Game/LifeSystem.h +++ b/include/Game/LifeSystem.h @@ -54,6 +54,7 @@ private: bool m_Pause = false; int m_Lives = 3; int m_PastLives = 3; + float m_LifeSpeed = 0.8; bool m_GodMode = false; diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index 016c2ab..273a67b 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -64,6 +64,13 @@ void dd::Systems::BallSystem::Initialize() auto transform2 = m_World->GetComponent(ent2); transform2->Position = glm::vec3(-0.f, 0.26f, -10.f); transform2->Velocity = glm::vec3(0.0f, -10.f, 0.f); + + /*auto PosterBoy = CreateBall(); + auto PosterBall = m_World->GetComponent(PosterBoy); + PosterBall->PosterBoy = 1; + auto Postertran = m_World->GetComponent(PosterBoy); + Postertran->Position = glm::vec3(-3.f, -3.f, -10.f); + Postertran->Velocity = glm::vec3(0.0f, 0.f, 0.f);*/ } SetReplaceBall(true); @@ -88,6 +95,11 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID if (templateCheck != nullptr){ return; } if (ballComponent != nullptr) { + auto transformBall = m_World->GetComponent(entity); + if (ballComponent->PosterBoy == 1) { + transformBall->Position = glm::vec3(-3, 3, -10); + } + if (ReplaceBall()) { m_First = true; SetReplaceBall(false); @@ -97,24 +109,21 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID ballComponent->SavedSpeed = glm::vec3(random, 1, 0.f); //ballComponent->SavedSpeed = glm::vec3(0.f, 1, 0.f); ballComponent->Waiting = true; - auto transform = m_World->GetComponent(entity); } if (ballComponent->Waiting) { if (!m_Waiting) { m_Restarting = false; ballComponent->Waiting = false; - auto transform = m_World->GetComponent(entity); /*std::uniform_real_distribution dist(-0.5f, 0.5f); float random = dist(m_RandomGenerator);*/ - transform->Velocity = glm::normalize(ballComponent->SavedSpeed) * ballComponent->Speed; + transformBall->Velocity = glm::normalize(ballComponent->SavedSpeed) * ballComponent->Speed; //transform->Velocity = glm::normalize(glm::vec3(0, 1, 0)) * ballComponent->Speed; } else if (!ballComponent->Sticky) { - auto transform = m_World->GetComponent(entity); - transform->Velocity = glm::vec3(0.f, 0.f, 0.f); + transformBall->Velocity = glm::vec3(0.f, 0.f, 0.f); //transform->Position = glm::vec3(0.0f, -3.f, -10.f); if (m_First) { - transform->Orientation = glm::quat(); + transformBall->Orientation = glm::quat(); m_First = false; } return; @@ -124,8 +133,7 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID //TODO - Ball can stick to same pad just after detaching. if (!m_Waiting) { - auto transform = m_World->GetComponent(entity); - transform->Velocity = ballComponent->SavedSpeed; + transformBall->Velocity = ballComponent->SavedSpeed; m_StickyCounter--; if (m_StickyCounter > 0) { m_Sticky = true; @@ -134,7 +142,6 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID } } - auto transformBall = m_World->GetComponent(entity); if (glm::abs(transformBall->Velocity.y) < 2) { if (transformBall->Velocity.y > 0) { transformBall->Velocity.y = 2; diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index de6ceb3..645deea 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -281,7 +281,19 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID auto brick = m_World->GetComponent(entity); if (brick != nullptr) { - auto transform = m_World->GetComponent(entity); + + auto transform = m_World->GetComponent(entity); + if (brick->BeingGenerated) { + if (transform->Position == brick->GenerationGoal) { + brick->BeingGenerated = false; + auto cPhys = m_World->AddComponent(entity); + cPhys->CollisionType = CollisionType::Type::Static; + cPhys->GravityScale = 0.f; + cPhys->Category = CollisionLayer::Type::Brick; + cPhys->Mask = static_cast(CollisionLayer::Type::Ball | CollisionLayer::Type::Projectile | CollisionLayer::Type::Wall | CollisionLayer::LifeBuoy); + } + } + //Removes bricks that falls out of the stage. if (transform->Position.y < -10) { if (brick->Type == StandardBrick) { @@ -480,6 +492,8 @@ bool dd::Systems::LevelSystem::BrickGenerating(const dd::Events::BrickGenerating auto ent = CreateBrick(i, j, SpaceBetweenBricks(), SpaceToEdge(), -3.2, 1, m_BrickSet[getter], m_ColorSet[getter]); if (ent != NULL) { auto brick = m_World->GetComponent(ent); + brick->BeingGenerated = true; + m_World->RemoveComponent(ent); brick->Number = getter; m_KrakenBricks[getter] = true; auto transform = m_World->GetComponent(ent); @@ -490,6 +504,7 @@ bool dd::Systems::LevelSystem::BrickGenerating(const dd::Events::BrickGenerating } else { transform->Position = event.Origin2; } + brick->GenerationGoal = e.GoalPosition; e.Entity = ent; e.Speed = 6; e.Queue = false; @@ -689,7 +704,11 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event) brick = m_World->GetComponent(entityBrick); if (brick == nullptr) { return false; - } + } + + if (brick->BeingGenerated) { + return false; + } if (entityShot != 0) { // For when a brick gets shot. @@ -1101,7 +1120,7 @@ void dd::Systems::LevelSystem::GetNextLevel() 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 6, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; color = {w, w, w, w, w, w, w, diff --git a/src/game/Game/LifeSystem.cpp b/src/game/Game/LifeSystem.cpp index 944ed1c..810ed35 100644 --- a/src/game/Game/LifeSystem.cpp +++ b/src/game/Game/LifeSystem.cpp @@ -47,10 +47,29 @@ void dd::Systems::LifeSystem::UpdateEntity(double dt, EntityID entity, EntityID auto templateCheck = m_World->GetComponent(entity); if (templateCheck != nullptr){ return; } + auto life = m_World->GetComponent(entity); - if (Lives() != PastLives()) { - auto life = m_World->GetComponent(entity); - if (life != nullptr) { + + if (life != nullptr) { + auto transform = m_World->GetComponent(entity); + if (life->Left) { + if (transform->Position.x > 3) { + life->Left = false; + transform->Velocity.x = m_LifeSpeed; + } + } else { + + if (transform->Position.x < -3) { + life->Left = true; + transform->Velocity.x = -m_LifeSpeed; + } + } + transform->Position.x += transform->Velocity.x * dt; + /*glm::vec2 dir = glm::normalize(glm::vec2(transform->Velocity.x, transform->Velocity.y)); + glm::vec2 up = glm::vec2(0.f, 1.f); + float angle = glm::acos(glm::dot(dir, up)) * glm::sign(dir.x); + transform->Orientation = glm::rotate(glm::quat(), angle, glm::vec3(0.f, 0.f, -1.f));*/ + if (Lives() != PastLives()) { if (life->Number + 1 == PastLives()) { m_World->RemoveEntity(entity); SetPastLives(Lives()); @@ -64,7 +83,9 @@ void dd::Systems::LifeSystem::CreateLife(int number) auto life = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(life); transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f); + //transform->Position = glm::vec3(-1.5f + number * 1.5f, -3.f, -10.f); transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f); + //transform->Scale = glm::vec3(0.2f, 0.2f, 0.2f); std::shared_ptr lifeNr = m_World->AddComponent(life); lifeNr->Number = number; @@ -81,7 +102,7 @@ bool dd::Systems::LifeSystem::OnLifeLost(const dd::Events::LifeLost &event) SetLives(Lives() - 1); return true; } - return false; + return true; } bool dd::Systems::LifeSystem::OnPause(const dd::Events::Pause &event)