diff --git a/src/Events/FlagCaptured.h b/src/Events/FlagCaptured.h new file mode 100644 index 0000000..fbb0a85 --- /dev/null +++ b/src/Events/FlagCaptured.h @@ -0,0 +1,15 @@ +#ifndef Events_FlagCaptured_h__ +#define Events_FlagCaptured_h__ + +#include "Entity.h" +#include "EventBroker.h" + +namespace Events +{ + struct FlagCaptured : Event + { + EntityID Player; + }; +} + +#endif // Events_FlagCaptured_h__ \ No newline at end of file diff --git a/src/Events/FlagDropped.h b/src/Events/FlagDropped.h new file mode 100644 index 0000000..eee5bbf --- /dev/null +++ b/src/Events/FlagDropped.h @@ -0,0 +1,15 @@ +#ifndef Events_FlagDropped_h__ +#define Events_FlagDropped_h__ + +#include "Entity.h" +#include "EventBroker.h" + +namespace Events +{ + struct FlagDropped : Event + { + EntityID Player; + }; +} + +#endif // Events_FlagDropped_h__ \ No newline at end of file diff --git a/src/Events/FlagPickup.h b/src/Events/FlagPickup.h new file mode 100644 index 0000000..d1ad727 --- /dev/null +++ b/src/Events/FlagPickup.h @@ -0,0 +1,15 @@ +#ifndef Events_FlagPickup_h__ +#define Events_FlagPickup_h__ + +#include "Entity.h" +#include "EventBroker.h" + +namespace Events +{ + struct FlagPickup : Event + { + EntityID Player; + }; +} + +#endif // Events_FlagPickup_h__ \ No newline at end of file diff --git a/src/Events/FlagReturned.h b/src/Events/FlagReturned.h new file mode 100644 index 0000000..9bdc55e --- /dev/null +++ b/src/Events/FlagReturned.h @@ -0,0 +1,15 @@ +#ifndef Events_FlagReturned_h__ +#define Events_FlagReturned_h__ + +#include "Entity.h" +#include "EventBroker.h" + +namespace Events +{ + struct FlagReturned : Event + { + EntityID Player; + }; +} + +#endif // Events_FlagReturned_h__ \ No newline at end of file diff --git a/src/Events/GameOver.h b/src/Events/GameOver.h new file mode 100644 index 0000000..b544954 --- /dev/null +++ b/src/Events/GameOver.h @@ -0,0 +1,15 @@ +#ifndef Events_GameOver_h__ +#define Events_GameOver_h__ + +#include "Entity.h" +#include "EventBroker.h" + +namespace Events +{ + struct GameOver : Event + { + EntityID Winner; + }; +} + +#endif // Events_GameOver_h__ \ No newline at end of file diff --git a/src/Events/GameStart.h b/src/Events/GameStart.h new file mode 100644 index 0000000..3d54dd1 --- /dev/null +++ b/src/Events/GameStart.h @@ -0,0 +1,15 @@ +#ifndef Events_GameStart_h__ +#define Events_GameStart_h__ + +#include "Entity.h" +#include "EventBroker.h" + +namespace Events +{ + struct GameStart : Event + { + + }; +} + +#endif // Events_GameStart_h__ \ No newline at end of file diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h index ba99851..ae28f1f 100644 --- a/src/GUI/Frame.h +++ b/src/GUI/Frame.h @@ -36,6 +36,7 @@ public: : EventBroker(eventBroker) , ResourceManager(resourceManager) , Rectangle() + , m_Parent(nullptr) , m_Name("UIParent") , m_Layer(0) , m_Hidden(false) @@ -46,12 +47,28 @@ public: : m_Name(name) , m_Layer(0) , m_Hidden(false) - { SetParent(std::shared_ptr(parent)); Initialize(); } + { SetParent(parent); Initialize(); } + + ~Frame() + { + /*for (auto layer : m_Children) + { + for (auto child : layer.second) + { + delete child.second; + } + } + + if (m_Parent) + { + m_Parent->RemoveChild(this); + }*/ + } ::RenderQueuePair RenderQueue; - std::shared_ptr Parent() const { return m_Parent; } - void SetParent(std::shared_ptr parent) + Frame* Parent() const { return m_Parent; } + void SetParent(Frame* parent) { if (parent == nullptr) { @@ -62,13 +79,13 @@ public: Width = parent->Width; Height = parent->Height; m_Layer = parent->Layer() + 1; - parent->AddChild(std::shared_ptr(this)); + parent->AddChild(this); m_Parent = parent; EventBroker = parent->EventBroker; ResourceManager = parent->ResourceManager; } - void AddChild(std::shared_ptr child) + void AddChild(Frame* child) { m_Children[child->m_Layer].insert(std::make_pair(child->Name(), child)); if (m_Parent) @@ -77,7 +94,19 @@ public: } } - typedef std::map>::const_iterator FrameChildrenIterator; + void RemoveChild(Frame* child) + { + auto it = m_Children.find(child->m_Layer); + if (it != m_Children.end()) + { + m_Children.erase(it); + } + + if (m_Parent) + { + m_Parent->RemoveChild(child); + } + } std::string Name() const { return m_Name; } void SetName(std::string val) { m_Name = val; } @@ -89,8 +118,14 @@ public: else return m_Hidden; } - void Hide() { m_Hidden = true; } - void Show() { m_Hidden = false; } + + bool Visible() const + { + return !Hidden(); + } + + virtual void Hide() { m_Hidden = true; } + virtual void Show() { m_Hidden = false; } int Left() const override { @@ -144,9 +179,6 @@ public: void UpdateLayered(double dt) { - if (this->Hidden()) - return; - // Update ourselves this->Update(dt); @@ -157,8 +189,6 @@ public: for (auto &pairChild : children) { auto child = pairChild.second; - if (child->Hidden()) - continue; child->Update(dt); } } @@ -200,8 +230,8 @@ protected: int m_Layer; bool m_Hidden; - std::shared_ptr m_Parent; - typedef std::multimap> Children_t; // name -> frame + Frame* m_Parent; + typedef std::multimap Children_t; // name -> frame std::map m_Children; // layer -> Children_t virtual bool OnKeyDown(const Events::KeyDown &event) { return false; } diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index b0d446a..56d0391 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -2,13 +2,15 @@ #define GUI_GameFrame_h__ #include "GUI/Frame.h" +#include "GUI/MainMenuFrame.h" #include "GUI/WorldFrame.h" #include "GUI/Viewport.h" #include "GUI/TextureFrame.h" #include "GUI/PlayerHUD.h" -#include "VehicleSelection.h" #include "GameWorld.h" +#include "Events/GameStart.h" +#include "Events/GameOver.h" namespace GUI { @@ -18,37 +20,59 @@ class GameFrame : public Frame public: GameFrame(Frame* parent, std::string name) : Frame(parent, name) + , m_GameOver(false) { + EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &GUI::GameFrame::OnGameStart); + EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &GUI::GameFrame::OnGameOver); + m_World = std::make_shared(EventBroker, ResourceManager); - auto worldFrame = new WorldFrame(this, "GameWorldFrame", m_World); + m_WorldFrame = new WorldFrame(this, "GameWorldFrame", m_World); { - vp1 = new Viewport(worldFrame, "Viewport1", m_World); + vp1 = new Viewport(m_WorldFrame, "Viewport1", m_World); vp1->X = 0; vp1->Width = this->Width / 2.f; - //new PlayerHUD(vp1, "PlayerHUD", m_World, 1); - new VehicleSelection(vp1, "VehicleSelection", m_World, 1); + new PlayerHUD(vp1, "PlayerHUD", m_World, 1); - vp2 = new Viewport(worldFrame, "Viewport2", m_World); + vp2 = new Viewport(m_WorldFrame, "Viewport2", m_World); vp2->X = vp1->Right(); vp2->Width = this->Width / 2.f; - //new PlayerHUD(vp2, "PlayerHUD", m_World, 2); - new VehicleSelection(vp2, "VehicleSelection", m_World, 2); + new PlayerHUD(vp2, "PlayerHUD", m_World, 2); - - m_FreeCamViewport = new Viewport(worldFrame, "ViewportFreeCam", m_World); + m_FreeCamViewport = new Viewport(m_WorldFrame, "ViewportFreeCam", m_World); m_FreeCamViewport->Hide(); } + //m_WorldFrame->Hide(); + //m_MainMenuFrame = new MainMenuFrame(this, "MainMenu"); + m_World->Initialize(); } private: - EventRelay m_EKeyUp; + EventRelay m_EGameStart; + bool OnGameStart(const Events::GameStart &event) + { + m_WorldFrame->Show(); + + return true; + } + EventRelay m_EGameOver; + bool OnGameOver(const Events::GameOver &event) + { + m_GameOver = true; + + return true; + } std::shared_ptr m_World; + + MainMenuFrame* m_MainMenuFrame; + WorldFrame* m_WorldFrame; Viewport* vp1; Viewport* vp2; Viewport* m_FreeCamViewport; + bool m_GameOver; + bool OnKeyUp(const Events::KeyUp &event) override { if (event.KeyCode == GLFW_KEY_1) diff --git a/src/GUI/GameOverFrame.h b/src/GUI/GameOverFrame.h new file mode 100644 index 0000000..7d943fd --- /dev/null +++ b/src/GUI/GameOverFrame.h @@ -0,0 +1,41 @@ +#ifndef GUI_GameOverFrame_h__ +#define GUI_GameOverFrame_h__ + +#include "GUI/Frame.h" +#include "GUI/HealthOverlay.h" + +namespace GUI +{ + + class GameOverFrame : public Frame + { + public: + GameOverFrame(Frame* parent, std::string name) + : Frame(parent, name) + { + //Hide(); + m_Background = new TextureFrame(this, "Background"); + m_Background->SetTexture("Textures/GUI/black.png"); + m_Background->SetColor(glm::vec4(1.f, 1.f, 1.f, 0.6f)); + m_Text = new TextureFrame(this, "Message"); + m_Text->SetTexture("Textures/GUI/GloriousVictory.png"); + } + + void Show(bool victory) + { + if (victory) + m_Text->SetTexture("Textures/GUI/GloriousVictory.png"); + else + m_Text->SetTexture("Textures/GUI/ShamefulDefeat.png"); + + Frame::Show(); + } + + protected: + bool m_Victory; + TextureFrame* m_Background; + TextureFrame* m_Text; + }; +} + +#endif // GUI_GameOverFrame_h__ diff --git a/src/GUI/MainMenuFrame.h b/src/GUI/MainMenuFrame.h new file mode 100644 index 0000000..ff43254 --- /dev/null +++ b/src/GUI/MainMenuFrame.h @@ -0,0 +1,100 @@ +#ifndef GUI_MainMenuFrame_h__ +#define GUI_MainMenuFrame_h__ + +#include "GUI/Frame.h" +#include "GUI/HealthOverlay.h" + +#include "Events/GameStart.h" + +namespace GUI +{ + +class MainMenuFrame : public Frame +{ +public: + MainMenuFrame(Frame* parent, std::string name) + : Frame(parent, name) + { + m_CurrentSelection = 0; + + //Hide(); + m_Background = new TextureFrame(this, "Background"); + m_Background->SetTexture("Textures/GUI/MainMenu/BackGround.png"); + + m_Buttons = new TextureFrame(this, "Message"); + m_Buttons->SetTexture("Textures/GUI/MainMenu/Buttons.png"); + m_CurrentCoordinate = -m_SelectionCoordinates[0] * Scale(); + m_TargetCoordinate = m_CurrentCoordinate; + m_Buttons->X = m_CurrentCoordinate.x; + m_Buttons->Y = m_CurrentCoordinate.y; + } + + void Update(double dt) override + { + if (Hidden()) + return; + + glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate; + m_CurrentCoordinate += posDiff * 4.f * (float)dt; + + m_Buttons->X = m_CurrentCoordinate.x; + m_Buttons->Y = m_CurrentCoordinate.y; + } + +protected: + bool m_Victory; + TextureFrame* m_Background; + TextureFrame* m_Buttons; + + int m_CurrentSelection; + static glm::vec2 m_SelectionCoordinates[2]; + glm::vec2 m_CurrentCoordinate; + glm::vec2 m_TargetCoordinate; + + bool OnCommand(const Events::InputCommand &event) override + { + if (Hidden()) + return false; + + const float deadzone = 0.5f; + + if (event.Command == "interface_horizontal") + { + if (event.Value > deadzone) + m_CurrentSelection++; + else if (event.Value < -deadzone) + m_CurrentSelection--; + } + m_CurrentSelection = (m_CurrentSelection < 0) ? 0 : ((m_CurrentSelection > 1) ? 1 : m_CurrentSelection); + m_TargetCoordinate = -m_SelectionCoordinates[m_CurrentSelection] * Scale(); + + if (event.Command == "interface_confirm" && event.Value > 0) + { + // Play + if (m_CurrentSelection == 0) + { + Hide(); + Events::GameStart e; + EventBroker->Publish(e); + } + // Quit + else if (m_CurrentSelection == 1) + { + exit(EXIT_SUCCESS); + } + } + + return false; + } + + +}; + +glm::vec2 MainMenuFrame::m_SelectionCoordinates[2] = { + glm::vec2(0, 0), + glm::vec2(193, 0), +}; + +} + +#endif // GUI_MainMenuFrame_h__ diff --git a/src/GUI/PlayerHUD.h b/src/GUI/PlayerHUD.h index 7ea4dda..63aaf14 100644 --- a/src/GUI/PlayerHUD.h +++ b/src/GUI/PlayerHUD.h @@ -3,6 +3,11 @@ #include "GUI/Frame.h" #include "GUI/HealthOverlay.h" +#include "GUI/VehicleSelection.h" +#include "GUI/GameOverFrame.h" + +#include "Events/GameOver.h" +#include "Components/Player.h" namespace GUI { @@ -15,7 +20,10 @@ namespace GUI , m_World(world) , m_PlayerID(playerID) { + EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &GUI::PlayerHUD::OnGameOver) + m_HealthOverlay = new HealthOverlay(this, "HealthOverlay", m_World, m_PlayerID); + m_Crosshair = new TextureFrame(this, "Crosshair"); m_Crosshair->Width = 45; m_Crosshair->Height = 45; @@ -23,6 +31,10 @@ namespace GUI m_Crosshair->Y = this->Height / 2.f - m_Crosshair->Height / 2.f; m_Crosshair->SetTexture("Textures/GUI/crosshair.png"); m_Crosshair->SetColor(glm::vec4(1.f, 1.f, 1.f, 0.75f)); + + m_VehicleSelection = new VehicleSelection(this, "VehicleSelection", m_World, m_PlayerID); + + m_GameOverFrame = new GameOverFrame(this, "GameOver"); } protected: @@ -31,6 +43,42 @@ namespace GUI HealthOverlay* m_HealthOverlay; TextureFrame* m_Crosshair; + VehicleSelection* m_VehicleSelection; + GameOverFrame* m_GameOverFrame; + + EventRelay m_EGameOver; + bool OnGameOver(const Events::GameOver &event) + { + auto playerComponent = m_World->GetComponent(event.Winner); + if (!playerComponent) + { + LOG_ERROR("Winner is not a valid player!"); + return false; + } + + if (m_PlayerID == playerComponent->ID) + m_GameOverFrame->Show(true); + else + m_GameOverFrame->Show(false); + + return true; + } + + bool OnCommand(const Events::InputCommand &event) + { + if (event.PlayerID != m_PlayerID) + return false; + + if (event.Command == "interface_confirm" && event.Value > 0) + { + if (m_GameOverFrame->Visible()) + { + m_GameOverFrame->Hide(); + } + } + + return true; + } }; } diff --git a/src/GUI/VehicleSelection.h b/src/GUI/VehicleSelection.h index 9a2ec18..add2122 100644 --- a/src/GUI/VehicleSelection.h +++ b/src/GUI/VehicleSelection.h @@ -40,6 +40,9 @@ namespace GUI void Update(double dt) override { + if (Hidden()) + return; + glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate; m_CurrentCoordinate += posDiff * 2.f * (float)dt; @@ -77,28 +80,30 @@ namespace GUI if (event.PlayerID != m_PlayerID) return false; + const float deadzone = 0.5f; + // Menu movement if (event.Command == "interface_horizontal" || event.Command == "interface_vertical") { // Horizontal scrolling if (event.Command == "interface_horizontal") { - if (event.Value > 0) + if (event.Value > deadzone) m_CurrentSelection++; - else if (event.Value < 0) + else if (event.Value < -deadzone) m_CurrentSelection--; } // Vertical scrolling to switch between "rows" in an intuitive way else if (event.Command == "interface_vertical") { - if (event.Value > 0) + if (event.Value > deadzone) { if (m_CurrentSelection == 0) m_CurrentSelection++; else if (m_CurrentSelection == 3) m_CurrentSelection--; } - else if (event.Value < 0) + else if (event.Value < -deadzone) { if (m_CurrentSelection == 1) m_CurrentSelection--; diff --git a/src/GUI/WorldFrame.h b/src/GUI/WorldFrame.h index 03b9708..ca69fb1 100644 --- a/src/GUI/WorldFrame.h +++ b/src/GUI/WorldFrame.h @@ -145,7 +145,7 @@ private: auto itpair = m_Children[m_Layer + 1].equal_range(event.ViewportFrame); for (auto it = itpair.first; it != itpair.second; ++it) { - auto viewportFrame = std::dynamic_pointer_cast(it->second); + auto viewportFrame = dynamic_cast(it->second); if (!viewportFrame) continue; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index a0e6373..55bb69c 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -98,8 +98,6 @@ void GameWorld::Initialize() EventBroker->Publish(e); } - CreateTerrain(); - #pragma region Wall_Debris_Template { @@ -270,12 +268,14 @@ void GameWorld::Initialize() auto shape = CreateEntity(debri); auto shapetransform = AddComponent(shape); auto shapemesh = AddComponent(shape); - shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDestroyed.obj"; //Lägg in ny collision modell + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDestroyedColosion.obj"; m_WallDebrisTemplates.push_back(debri); } #pragma endregion Region for wall debris + CreateTerrain(); + /*EntityID tank1 = CreateTank(1); { auto transform = GetComponent(tank1); @@ -873,7 +873,7 @@ void GameWorld::CreateTerrain() } CreateBase(glm::quat(), 1); - CreateBase(glm::quat(glm::vec3(0, glm::pi(), 0)), 2); + //CreateBase(glm::quat(glm::vec3(0, glm::pi(), 0)), 2); { auto tree = CreateEntity(); @@ -1106,14 +1106,13 @@ void GameWorld::CreateBase(glm::quat orientation, int playerID) #pragma endregion Terrain CreateGate(base, glm::vec3(273.f, 40.185f, 0.06f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - CreateWall(base, glm::vec3(273.f, 40.3f, -55.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - CreateWall(base, glm::vec3(273.f, 40.3f, -45.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - CreateWall(base, glm::vec3(273.f, 40.3f, -35.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - CreateWall(base, glm::vec3(273.f, 40.3f, -25.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - CreateWall(base, glm::vec3(273.f, 40.3f, -15.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - CreateWall(base, glm::vec3(273.f, 40.3f, 15.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - CreateWall(base, glm::vec3(273.f, 40.3f, 25.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + //CreateWall(base, glm::vec3(273.f, 40.3f, -45.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + //CreateWall(base, glm::vec3(273.f, 40.3f, -35.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + //CreateWall(base, glm::vec3(273.f, 40.3f, -25.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + //CreateWall(base, glm::vec3(273.f, 40.3f, -15.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + //CreateWall(base, glm::vec3(273.f, 40.3f, 15.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + //CreateWall(base, glm::vec3(273.f, 40.3f, 25.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); CreateGarage(base, glm::vec3(323.2f, 41.4f, -10.2f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0)), playerID); } diff --git a/src/InputController.h b/src/InputController.h index 39c26b1..1f3fa81 100644 --- a/src/InputController.h +++ b/src/InputController.h @@ -6,29 +6,63 @@ #include "EventBroker.h" #include "Events/InputCommand.h" #include "Events/MouseMove.h" +#include "Events/GameStart.h" +#include "Events/GameOver.h" template class InputController { public: InputController(std::shared_ptr<::EventBroker> eventBroker) - : EventBroker(eventBroker) { Initialize(); } + : EventBroker(eventBroker) + , InGame(true) + { Initialize(); } virtual void Initialize() { - EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &InputController::OnCommand); - EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &InputController::OnMouseMove); + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &InputController::_OnCommand); + EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &InputController::_OnMouseMove); + EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &InputController::OnGameStart); + EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &InputController::OnGameOver); } virtual bool OnCommand(const Events::InputCommand &event) { return false; } virtual bool OnMouseMove(const Events::MouseMove &event) { return false; } + virtual bool OnGameStart(const Events::GameStart &event) + { + InGame = true; + return true; + } + virtual bool OnGameOver(const Events::GameOver &event) + { + InGame = false; + return true; + } protected: std::shared_ptr<::EventBroker> EventBroker; + bool InGame; private: EventRelay m_EInputCommand; EventRelay m_EMouseMove; + EventRelay m_EGameStart; + EventRelay m_EGameOver; + + virtual bool _OnCommand(const Events::InputCommand &event) + { + if (InGame || event.Value == 0) + return OnCommand(event); + else + return false; + } + virtual bool _OnMouseMove(const Events::MouseMove &event) + { + if (InGame) + return OnMouseMove(event); + else + return false; + } }; #endif // InputController_h__ diff --git a/src/Model.cpp b/src/Model.cpp index 352c7f6..eb689c0 100755 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -93,7 +93,7 @@ Model::Model(std::shared_ptr rm, OBJ &obj) if (Vertices.size() > 0) { CreateTangents(); - getSimilarVertexIndex(); + //getSimilarVertexIndex(); CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords); } else @@ -223,7 +223,7 @@ void Model::getSimilarVertexIndex() { glm::vec3 tempNormal, tempTangent, tempBiTangent; - if(glm::dot(Normals[i], Normals[t]) > 0) + if(glm::dot(Normals[i], Normals[t]) > .4f) { tempNormal = Normals[i] + Normals[t]; tempTangent = TangentNormals[i] + TangentNormals[t]; diff --git a/src/Systems/DamageSystem.cpp b/src/Systems/DamageSystem.cpp index f894fd2..53be57c 100644 --- a/src/Systems/DamageSystem.cpp +++ b/src/Systems/DamageSystem.cpp @@ -18,12 +18,12 @@ bool Systems::DamageSystem::OnDamage( const Events::Damage &event ) return false; auto health = m_World->GetComponent(event.Entity); health->Amount -= event.Amount; - if(health->Amount <= 0) - { - Events::OnDead e; - e.Entity = event.Entity; - EventBroker->Publish(e); - } + //if(health->Amount <= 0) + //{ + // Events::OnDead e; + // e.Entity = event.Entity; + // EventBroker->Publish(e); + //} LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->Amount); return true; } \ No newline at end of file diff --git a/src/Systems/GameStateSystem.cpp b/src/Systems/GameStateSystem.cpp new file mode 100644 index 0000000..ca17bd3 --- /dev/null +++ b/src/Systems/GameStateSystem.cpp @@ -0,0 +1,19 @@ +#include "PrecompiledHeader.h" +#include "GameStateSystem.h" +#include "World.h" + +void Systems::GameStateSystem::Initialize() +{ + EVENT_SUBSCRIBE_MEMBER(m_EFlagCaptured, &Systems::GameStateSystem::OnFlagCaptured); +} + +bool Systems::GameStateSystem::OnFlagCaptured(const Events::FlagCaptured &event) +{ + m_InGame = false; + + Events::GameOver e; + e.Winner = event.Player; + EventBroker->Publish(e); + + return true; +} \ No newline at end of file diff --git a/src/Systems/GameStateSystem.h b/src/Systems/GameStateSystem.h new file mode 100644 index 0000000..ac9d46e --- /dev/null +++ b/src/Systems/GameStateSystem.h @@ -0,0 +1,37 @@ +#ifndef GameStateSystem_h__ +#define GameStateSystem_h__ + +#include + +#include "System.h" +#include "Components/Transform.h" +#include "Components/Player.h" +#include "Events/FlagCaptured.h" +#include "Events/GameOver.h" + +namespace Systems +{ + +class GameStateSystem : public System +{ +public: + + GameStateSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager) + : System(world, eventBroker, resourceManager) + , m_InGame(true) + { } + + void Initialize() override; + + bool InGame() const { return m_InGame; } + +private: + bool m_InGame; + + EventRelay m_EFlagCaptured; + bool OnFlagCaptured(const Events::FlagCaptured &event); +}; + +} + +#endif // GameStateSystem_h__ diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index 78ad3e4..c4f24c4 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -48,6 +48,7 @@ #include "Components/Input.h" #include "Events/SetViewportCamera.h" +#include "Events/GameOver.h" namespace Systems { diff --git a/src/Systems/WallSystem.cpp b/src/Systems/WallSystem.cpp index 4f50c68..73f1eaa 100644 --- a/src/Systems/WallSystem.cpp +++ b/src/Systems/WallSystem.cpp @@ -25,30 +25,29 @@ bool Systems::WallSystem::Damage( const Events::Damage &event ) { return false; } - - - LOG_INFO("You are dead"); - auto transformComponent = m_World->GetComponent(event.Entity); + LOG_INFO("Entity %i is dead", event.Entity); + //auto transformComponent = m_World->GetComponent(event.Entity); + Components::Transform transformComponent = m_World->GetSystem()->AbsoluteTransform(event.Entity); for(auto d : wallComponent->Walldebris) { auto debris = m_World->CloneEntity(d); auto transform = m_World->GetComponent(debris); - transform->Position += transformComponent->Position; - - // DO STUFF! :D - float distance = glm::distance(transform->Position, transformComponent->Position); - float radius = 5.f; - float strength = (1.f - pow(distance / radius, 2)) * 500.f; - glm::vec3 direction = glm::normalize(transformComponent->Position - transform->Position); - - Events::ApplyPointImpulse e; - e.Entity = debris; - e.Impulse = direction * strength; - e.Position = transformComponent->Position; - EventBroker->Publish(e); + transform->Orientation = transform->Orientation * transformComponent.Orientation; + transform->Position = transform->Orientation * transform->Position + transformComponent.Position; + + //DO STUFF! :D + float distance = glm::distance(transform->Position, transformComponent.Position); + float radius = 5.f; + float strength = (1.f - pow(distance / radius, 2)) * 20.f; + glm::vec3 direction = glm::normalize(transformComponent.Position - transform->Position); + Events::ApplyPointImpulse e; + e.Entity = debris; + e.Impulse = direction * strength; + e.Position = transformComponent.Position; + EventBroker->Publish(e); } m_World->RemoveEntity(event.Entity); diff --git a/src/Systems/WallSystem.h b/src/Systems/WallSystem.h index 986c7b8..84e5972 100644 --- a/src/Systems/WallSystem.h +++ b/src/Systems/WallSystem.h @@ -3,6 +3,7 @@ #include "System.h" +#include "Systems/TransformSystem.h" #include "Events/OnDead.h" #include "Events/Damage.h" #include "Events/ApplyPointImpulse.h" diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 4f89884..8329afb 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -113,6 +113,7 @@ + @@ -192,8 +193,14 @@ + + + + + + @@ -218,7 +225,9 @@ + + @@ -241,6 +250,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 1c02897..622a11b 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -85,6 +85,7 @@ Audio + @@ -571,6 +572,35 @@ + + GUI + + + Game\Systems + + + Game\Events + + + Game\Events + + + Game\Events + + + Game\Events + + + Game\Events + + + GUI + + + Game\Events + + +