diff --git a/include/Game/Systems/PlayerDeathSystem.h b/include/Game/Systems/PlayerDeathSystem.h index e4f96114..5a82f999 100644 --- a/include/Game/Systems/PlayerDeathSystem.h +++ b/include/Game/Systems/PlayerDeathSystem.h @@ -25,6 +25,7 @@ private: EventRelay m_EEntityDeleted; bool OnEntityDeleted(Events::EntityDeleted& e); + void setSpectatorCamera(); void createDeathEffect(EntityWrapper player); }; diff --git a/src/Game/Systems/PlayerDeathSystem.cpp b/src/Game/Systems/PlayerDeathSystem.cpp index cbf0927f..bb9a807c 100644 --- a/src/Game/Systems/PlayerDeathSystem.cpp +++ b/src/Game/Systems/PlayerDeathSystem.cpp @@ -1,4 +1,5 @@ #include "Systems/PlayerDeathSystem.h" +#include "Core/ELockMouse.h" PlayerDeathSystem::PlayerDeathSystem(SystemParams params) : System(params) @@ -33,10 +34,10 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player) //components that we need from player auto playerModel = player.FirstChildByName("PlayerModel"); - if (!playerModel.Valid()) { - return; - } - if (!playerModel.HasComponent("Model") || !playerModel.HasComponent("Animation")) { + if (!playerModel.Valid() || !playerModel.HasComponent("Model") || !playerModel.HasComponent("Animation")) { + if (player == LocalPlayer) { + setSpectatorCamera(); + } return; } auto playerEntityModel = playerModel["Model"]; @@ -46,9 +47,7 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player) playerEntityModel.Copy(deathEffectEW["Model"]); playerEntityAnimation.Copy(deathEffectEW["Animation"]); //freeze the animation - deathEffectEW["Animation"]["Speed1"] = 0.0; - deathEffectEW["Animation"]["Speed2"] = 0.0; - deathEffectEW["Animation"]["Speed3"] = 0.0; + deathEffectEW["Animation"]["Speed"] = 0.0; //copy the models position,orientation deathEffectEW["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"]; @@ -73,13 +72,20 @@ bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e) return false; } + setSpectatorCamera(); + return true; +} + +void PlayerDeathSystem::setSpectatorCamera() +{ // Look for the spectator camera entity in the level. EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera"); if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera") || LocalPlayer.Valid()) { - return false; + return; } Events::SetCamera eSetCamera; eSetCamera.CameraEntity = spectatorCam; m_EventBroker->Publish(eSetCamera); - return true; + Events::UnlockMouse unlock; + m_EventBroker->Publish(unlock); } diff --git a/src/Game/Systems/PlayerSpawnSystem.cpp b/src/Game/Systems/PlayerSpawnSystem.cpp index 10632c0a..7692b0a7 100644 --- a/src/Game/Systems/PlayerSpawnSystem.cpp +++ b/src/Game/Systems/PlayerSpawnSystem.cpp @@ -1,4 +1,5 @@ #include "Systems/PlayerSpawnSystem.h" +#include "Core/ELockMouse.h" PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params) : System(params) @@ -100,6 +101,8 @@ void PlayerSpawnSystem::Update(double dt) e.Player = player; e.Spawner = spawner; m_EventBroker->Publish(e); + Events::LockMouse lock; + m_EventBroker->Publish(lock); ++numSpawnedPlayers; it = m_SpawnRequests.erase(it); break; diff --git a/src/Game/Systems/SpectatorCameraSystem.cpp b/src/Game/Systems/SpectatorCameraSystem.cpp index bf78cfb0..58f25155 100644 --- a/src/Game/Systems/SpectatorCameraSystem.cpp +++ b/src/Game/Systems/SpectatorCameraSystem.cpp @@ -1,5 +1,6 @@ #include "Systems/SpectatorCameraSystem.h" #include "Rendering/ESetCamera.h" +#include "Core/ELockMouse.h" SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params) : System(params) @@ -19,6 +20,8 @@ void SpectatorCameraSystem::Update(double dt) Events::SetCamera eSetCamera; eSetCamera.CameraEntity = spectatorCam; m_EventBroker->Publish(eSetCamera); + Events::UnlockMouse unlock; + m_EventBroker->Publish(unlock); } } } @@ -60,6 +63,8 @@ bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e) Events::SetCamera eSetCamera; eSetCamera.CameraEntity = spectatorCam; m_EventBroker->Publish(eSetCamera); + Events::UnlockMouse unlock; + m_EventBroker->Publish(unlock); } return true;