From 2fb16357fa469363d6e902fc874a72b922484a7d Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Wed, 30 Sep 2015 10:32:17 +0200 Subject: [PATCH] Moved pad-creation to PadSystem. Pad now stops at sides. --- include/Core/Engine.h | 26 +++----------------------- include/Game/PadSystem.h | 3 +++ src/game/Game/PadSystem.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/include/Core/Engine.h b/include/Core/Engine.h index d2e1519..f556bc5 100644 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -111,10 +111,6 @@ public: m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); - m_World->SystemFactory.Register( - [this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); }); - m_World->AddSystem(); - m_World->SystemFactory.Register( [this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); }); m_World->AddSystem(); @@ -124,6 +120,9 @@ public: m_World->SystemFactory.Register( [this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); }); m_World->AddSystem(); + m_World->SystemFactory.Register( + [this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); }); + m_World->AddSystem(); m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); @@ -320,25 +319,6 @@ public: m_World->CommitEntity(rightWall); } - { - auto ent = m_World->CreateEntity(); - m_World->SetProperty(ent, "Name", "Pad"); - auto ctransform = m_World->AddComponent(ent); - ctransform->Position = glm::vec3(0.f, -3.5f, -10.f); - ctransform->Scale = glm::vec3(1.0f, 1.0f, 1.f); - auto rectangle = m_World->AddComponent(ent); - auto physics = m_World->AddComponent(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(ent); - cModel->ModelFile = "Models/Submarine2.obj"; - - auto pad = m_World->AddComponent(ent); - m_World->CommitEntity(ent); - } - //EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &Engine::OnGameStart); m_EGameStart = decltype(m_EGameStart)(std::bind(&Engine::OnGameStart, this, std::placeholders::_1)); diff --git a/include/Game/PadSystem.h b/include/Game/PadSystem.h index 9162083..6f2d13a 100755 --- a/include/Game/PadSystem.h +++ b/include/Game/PadSystem.h @@ -55,6 +55,8 @@ public: void SetLeft(const bool& left) { m_Left = left; } bool Right() const { return m_Right; } void SetRight(const bool& right) { m_Right = right; } + float Edge() const { return m_Edge; } + void SetEdge(const float& edge) { m_Edge = edge; } Components::Transform* Transform() const { return m_Transform; } void SetTransform(Components::Transform* transform) { m_Transform = transform; } @@ -66,6 +68,7 @@ private: glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f); bool m_Left = false; bool m_Right = false; + float m_Edge = 2.8f; Components::Transform* m_Transform; Components::Pad* m_Pad; diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp index 43c71e7..34e5bb9 100755 --- a/src/game/Game/PadSystem.cpp +++ b/src/game/Game/PadSystem.cpp @@ -27,6 +27,27 @@ void dd::Systems::PadSystem::Initialize() EVENT_SUBSCRIBE_MEMBER(m_EContact, &PadSystem::OnContact); EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp); EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared); + + { + auto ent = m_World->CreateEntity(); + m_World->SetProperty(ent, "Name", "Pad"); + auto ctransform = m_World->AddComponent(ent); + ctransform->Position = glm::vec3(0.f, -3.5f, -10.f); + ctransform->Scale = glm::vec3(1.0f, 1.0f, 1.f); + auto rectangle = m_World->AddComponent(ent); + auto physics = m_World->AddComponent(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(ent); + cModel->ModelFile = "Models/Submarine2.obj"; + + auto pad = m_World->AddComponent(ent); + m_World->CommitEntity(ent); + + SetEdge(3.2 - (ctransform->Scale.x / 2)); + } } void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -59,6 +80,11 @@ void dd::Systems::PadSystem::Update(double dt) transform->Velocity.x = pad->MaxSpeed; } transform->Position += transform->Velocity * (float)dt; + if (transform->Position.x > Edge()) { + transform->Position.x = Edge(); + } else if (transform->Position.x < -Edge()) { + transform->Position.x = -Edge(); + } transform->Velocity += acceleration * (float)dt; if (glm::abs(transform->Velocity.x) > 1 || (!Left() && !Right())) { transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float) dt;