commit 98d17390
Now respawns player after 10 seconds after dead
Changed files
| M | src/saland/Game.cpp before |
| M | src/saland/Game.hpp before |
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp
index 3b7cbcd..1be46d3 100644
--- a/src/saland/Game.cpp
+++ b/src/saland/Game.cpp
@@ -308,6 +308,16 @@ bool Game::IsActive() {
return data->isActive;
}
+void Game::RespawnPlayer() {
+ data->human->health = 100;
+ data->human->diedAt = 0;
+ ResetWorld(0, 0, false);
+}
+
+void Game::ActionPostDeath() {
+ RespawnPlayer();
+}
+
static void SetLengthToOne(float& x, float& y) {
float currentLength = std::sqrt(x*x + y*y);
x = x/currentLength;
@@ -639,6 +649,9 @@ void Game::Update() {
killPlayer = false;
data->human->direction = 'S';
}
+ if (data->human->diedAt && data->human->diedAt + 10000 < SDL_GetTicks()) {
+ ActionPostDeath();
+ }
if (openTiled) {
openTiled = false;
for (const sago::tiled::TileSet& org_ts : data->gameRegion.world.tm.tileset) {
diff --git a/src/saland/Game.hpp b/src/saland/Game.hpp
index be5477f..b9f3b75 100644
--- a/src/saland/Game.hpp
+++ b/src/saland/Game.hpp
@@ -41,6 +41,12 @@ private:
std::unique_ptr<GameImpl> data;
void ResetWorld(int region_x, int region_y, bool forceResetWorld);
void ResetWorldNoSave(int region_x, int region_y, bool forceResetWorld);
+ void RespawnPlayer();
+ /**
+ * @brief Respawns the player or any other dead action.
+ *
+ */
+ void ActionPostDeath();
};
#endif /* GAME_HPP */