diff options
author | LaG1924 <lag1924@gmail.com> | 2021-07-02 09:26:39 +0200 |
---|---|---|
committer | LaG1924 <lag1924@gmail.com> | 2021-07-03 10:36:56 +0200 |
commit | 48e564a32c266c8d4649c6f50bf4eac56f771c0d (patch) | |
tree | 34fbd849a2b0f1ded8ab8d87c1e4a300107b2e0e /src | |
parent | Added Loading screen (diff) | |
download | AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar.gz AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar.bz2 AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar.lz AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar.xz AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.tar.zst AltCraft-48e564a32c266c8d4649c6f50bf4eac56f771c0d.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/Game.hpp | 1 | ||||
-rw-r--r-- | src/GameState.cpp | 12 | ||||
-rw-r--r-- | src/GameState.hpp | 4 | ||||
-rw-r--r-- | src/Plugin.cpp | 3 | ||||
-rw-r--r-- | src/Render.cpp | 4 |
5 files changed, 19 insertions, 5 deletions
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<Packet> ptr) { auto packet = std::static_pointer_cast<PacketUpdateHealth>(ptr); playerStatus.health = packet->Health; if (playerStatus.health <= 0) { - LOG(INFO) << "Player is dead. Respawning..."; - auto packetPerformRespawn = std::make_shared<PacketClientStatus>(0); - PUSH_EVENT("SendPacket", std::static_pointer_cast<Packet>(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<Packet>(packetPlace); PUSH_EVENT("SendPacket", packet); -}
\ No newline at end of file +} + +void GameState::PerformRespawn() { + auto packetPerformRespawn = std::make_shared<PacketClientStatus>(0); + PUSH_EVENT("SendPacket", std::static_pointer_cast<Packet>(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> 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>("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; } }); |