Nimbin[12]?SDL & Graphics / mapcreator / commits / 5b4e228

mapcreator git · master

SDL3 2.5D game and engine using assets, with map editor

sdl3 c++ game engine map-editor cmake · first commit 2025-10-31 · last commit 2026-09-07 (1 month ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-spieleentwicklung/map_creator

C++ 99.3%
git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gz

New health fix so i dont die

Christian Immanuel · 2026-02-15 13:28 · 5b4e228cb2209a34989b58b0c04f974ead2af525

 src/character/character.cpp | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/src/character/character.cpp b/src/character/character.cpp
index 76da0a5..524279e 100644
--- a/src/character/character.cpp
+++ b/src/character/character.cpp
@@ -708,8 +708,41 @@ Character::add_ToStatsBonus(InventoryObjectType object_type,
 
 void
 Character::reduce_StatsBonus() {
-    for (auto it = stats_bonus.begin(); it != stats_bonus.end(); ) {
+    for (auto it = stats_bonus.begin(); it != stats_bonus.end(); )
+    {
+        float total_duration = it->stats.duration;
+        if (total_duration <= 0.0f)
+        {
+            it = stats_bonus.erase(it);
+            continue;
+        }
+
+        float previous_ratio = it->duration / total_duration;
+
         it->duration -= Default::delta_time;
+        if (it->duration < 0.0f)
+            it->duration = 0.0f;
+
+        float new_ratio = it->duration / total_duration;
+
+        float scale = (previous_ratio > 0.0f)
+            ? (new_ratio / previous_ratio)
+            : 0.0f;
+
+        float oh = it->stats.health;
+        float os = it->stats.stamina;
+        it->stats.health  *= scale;
+        it->stats.stamina *= scale;
+        it->stats.thirst  *= scale;
+        it->stats.demage  *= scale;
+
+        stats.health_reduced  -= (oh - it->stats.health);
+        if (stats.health_reduced <= 0.0f)
+            stats.health_reduced = 0.0f;
+
+        stats.stamina_reduced -= (os - it->stats.stamina);
+        if (stats.stamina_reduced <= 0.0f)
+            stats.stamina_reduced = 0.0f;
 
         if (it->duration <= 0.0f)
             it = stats_bonus.erase(it);