From 40ae2b8cbbe5bb72d5ed24578930ad6ef396e5e2 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Fri, 12 Feb 2016 00:52:58 +0100 Subject: [PATCH] DefaultInput key 'K' to kill player, since we can't respawn when alive. Also moved TakeDamage InputCommand to HealthSystem. --- include/Game/Systems/HealthSystem.h | 5 ++++- resources/DefaultInput.ini | 3 ++- src/Game/Systems/HealthSystem.cpp | 12 ++++++++++++ src/Game/Systems/SoundSystem.cpp | 6 ------ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/Game/Systems/HealthSystem.h b/include/Game/Systems/HealthSystem.h index b66d8eb0..21a52330 100644 --- a/include/Game/Systems/HealthSystem.h +++ b/include/Game/Systems/HealthSystem.h @@ -9,6 +9,7 @@ #include "Core/EPlayerDamage.h" #include "Core/EPlayerHealthPickup.h" #include "Core/EPlayerDeath.h" +#include "../Engine/Input/EInputCommand.h" #include #include @@ -28,7 +29,9 @@ private: bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e); EventRelay m_EPlayerHealthPickup; bool HealthSystem::OnPlayerHealthPickup(Events::PlayerHealthPickup& e); - + EventRelay m_InputCommand; + bool HealthSystem::OnInputCommand(Events::InputCommand& e); + //vector which will keep track of health changes std::vector> m_DeltaHealthVector; diff --git a/resources/DefaultInput.ini b/resources/DefaultInput.ini index 683d48e2..d5489c3a 100644 --- a/resources/DefaultInput.ini +++ b/resources/DefaultInput.ini @@ -24,4 +24,5 @@ F1=ToggleEditor C=ConnectToServer N=SwitchToServer M=SwitchToClient -P=SwitchToPlayer \ No newline at end of file +P=SwitchToPlayer +K=TakeDamage,1500 \ No newline at end of file diff --git a/src/Game/Systems/HealthSystem.cpp b/src/Game/Systems/HealthSystem.cpp index 29d8790d..0fc113b9 100644 --- a/src/Game/Systems/HealthSystem.cpp +++ b/src/Game/Systems/HealthSystem.cpp @@ -7,6 +7,7 @@ HealthSystem::HealthSystem(SystemParams params) //subscribe/listenTo playerdamage,healthpickup events (using the eventBroker) EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &HealthSystem::OnPlayerDamaged); EVENT_SUBSCRIBE_MEMBER(m_EPlayerHealthPickup, &HealthSystem::OnPlayerHealthPickup); + EVENT_SUBSCRIBE_MEMBER(m_InputCommand, &HealthSystem::OnInputCommand); } void HealthSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) @@ -29,6 +30,17 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e) return true; } +bool HealthSystem::OnInputCommand(Events::InputCommand& e) +{ + if (e.Command == "TakeDamage" && e.Value > 0 && LocalPlayer.Valid()) { + Events::PlayerDamage ev; + ev.Victim = LocalPlayer; + ev.Damage = e.Value; + m_EventBroker->Publish(ev); + } + return true; +} + bool HealthSystem::OnPlayerHealthPickup(Events::PlayerHealthPickup& e) { ComponentWrapper cHealth = e.Player["Health"]; diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index db3575ab..59fd4a7f 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -52,12 +52,6 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e) return true; } } - if (e.Command == "TakeDamage" && e.Value > 0 && LocalPlayer.Valid()) { - Events::PlayerDamage ev; - ev.Victim = LocalPlayer; - ev.Damage = e.Value; - m_EventBroker->Publish(ev); - } return false; }