From 48e564a32c266c8d4649c6f50bf4eac56f771c0d Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Fri, 2 Jul 2021 12:26:39 +0500 Subject: Added Respawn screen --- src/Game.hpp | 1 + src/GameState.cpp | 12 ++++++++---- src/GameState.hpp | 4 ++++ src/Plugin.cpp | 3 ++- src/Render.cpp | 4 ++++ 5 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Game.hpp b/src/Game.hpp index f7efd11..74eeea9 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -13,6 +13,7 @@ enum class State { Paused, Inventory, Chat, + NeedRespawn, }; void RunGame(); diff --git a/src/GameState.cpp b/src/GameState.cpp index bb93c45..50a9004 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -456,9 +456,8 @@ void GameState::UpdatePacket(std::shared_ptr ptr) { auto packet = std::static_pointer_cast(ptr); playerStatus.health = packet->Health; if (playerStatus.health <= 0) { - LOG(INFO) << "Player is dead. Respawning..."; - auto packetPerformRespawn = std::make_shared(0); - PUSH_EVENT("SendPacket", std::static_pointer_cast(packetPerformRespawn)); + LOG(INFO) << "Player is dead. Need respawn..."; + SetState(State::NeedRespawn); } break; } @@ -681,4 +680,9 @@ void GameState::PlaceBlock() { auto packet = std::static_pointer_cast(packetPlace); PUSH_EVENT("SendPacket", packet); -} \ No newline at end of file +} + +void GameState::PerformRespawn() { + auto packetPerformRespawn = std::make_shared(0); + PUSH_EVENT("SendPacket", std::static_pointer_cast(packetPerformRespawn)); +} diff --git a/src/GameState.hpp b/src/GameState.hpp index 0ca858f..ca2ea81 100644 --- a/src/GameState.hpp +++ b/src/GameState.hpp @@ -75,6 +75,8 @@ class GameState { bool receivedFirstPlayerPosAndLook = false; + std::shared_ptr packetRespawn; + public: void Update(double deltaTime); @@ -89,6 +91,8 @@ public: void PlaceBlock(); + void PerformRespawn(); + enum MoveType { FORWARD, BACKWARD, LEFT, RIGHT, JUMP }; diff --git a/src/Plugin.cpp b/src/Plugin.cpp index f759d5f..64fc00b 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -174,7 +174,8 @@ void PluginSystem::Init() { "GetGameStatus", &GameState::GetGameStatus, "GetPlayerStatus", &GameState::GetPlayerStatus, "GetSelectionStatus", &GameState::GetSelectionStatus, - "GetInventory", &GameState::GetInventory); + "GetInventory", &GameState::GetInventory, + "PerformRespawn", &GameState::PerformRespawn); lua.new_usertype("TimeStatus", "interpolatedTimeOfDay", &TimeStatus::interpolatedTimeOfDay, diff --git a/src/Render.cpp b/src/Render.cpp index bee8ffb..6aecd88 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -498,6 +498,10 @@ void Render::InitEvents() { PluginSystem::CallOnChangeState("Chat"); SetMouseCapture(false); break; + case State::NeedRespawn: + PluginSystem::CallOnChangeState("NeedRespawn"); + SetMouseCapture(false); + break; } }); -- cgit v1.2.3