Nimbin[12]?SDL & Graphics / mapcreator / commits / a796126

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

Update better progress bar for collection

Christian Immanuel · 2026-02-17 15:53 · a7961267ff607878074713674eec74539c407636

 src/character/character.cpp | 29 +++++++++++++++++++++++++++--
 src/character/character.hpp |  4 ++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/character/character.cpp b/src/character/character.cpp
index 16ee25e..e65aba6 100644
--- a/src/character/character.cpp
+++ b/src/character/character.cpp
@@ -203,6 +203,32 @@ Character::draw_CircleProgress(SDL_Renderer* renderer, int cx, int cy, int radiu
     }
 }
 
+void
+Character::draw_HorizontalProgress(SDL_Renderer* renderer, float progress,
+                                   Uint8 fill_r, Uint8 fill_g, Uint8 fill_b, Uint8 fill_a,
+                                   Uint8 bg_r, Uint8 bg_g, Uint8 bg_b, Uint8 bg_a) {
+    float width = Scale(20);   // horizontal bar width
+    float height = Scale(2);   // bar thickness
+    float x = Scale(collider_world.x + Map::offset.x) - width/2;
+    float y = Scale(collider_world.y - collider.y*0.75 + Map::offset.y); // slightly above character
+
+    if (progress < 0.0f) progress = 0.0f;
+    if (progress > 1.0f) progress = 1.0f;
+
+    SDL_FRect bg_rect = { x, y, width, height };
+    SDL_FRect fill_rect = { x, y, width * progress, height };
+
+    SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
+
+    // Draw background
+    SDL_SetRenderDrawColor(renderer, bg_r, bg_g, bg_b, bg_a);
+    SDL_RenderFillRect(renderer, &bg_rect);
+
+    // Draw filled portion
+    SDL_SetRenderDrawColor(renderer, fill_r, fill_g, fill_b, fill_a);
+    SDL_RenderFillRect(renderer, &fill_rect);
+}
+
 void
 Character::Draw(SDL_Renderer* renderer) {
 #ifdef DEBUG_BUILD
@@ -285,8 +311,7 @@ Character::Draw(SDL_Renderer* renderer) {
             flip ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE);
     if (collecting_logic.is_collecting) {
         float collecting_progress = collecting_logic.duration / collecting_logic.duration_max;
-        size_t r = 6;
-        draw_CircleProgress(renderer, Scale(Character::x + Character::tile_size/2), Scale(Character::y + Character::tile_size/6), Scale(r), collecting_progress);
+        Character::draw_HorizontalProgress(renderer, collecting_progress);
     }
 
 
diff --git a/src/character/character.hpp b/src/character/character.hpp
index 73b9915..0b7cfc0 100644
--- a/src/character/character.hpp
+++ b/src/character/character.hpp
@@ -238,6 +238,10 @@ class Character {
     void
     draw_CircleProgress(SDL_Renderer* renderer, int cx, int cy, int radius, float progress,
                        Uint8 color_r=16, Uint8 color_g=47, Uint8 color_b=74, Uint8 color_a=210);
+    void
+    draw_HorizontalProgress(SDL_Renderer* renderer, float progress,
+                                   Uint8 fill_r = 16, Uint8 fill_g = 47, Uint8 fill_b = 144, Uint8 fill_a = 210,
+                                   Uint8 bg_r = 50, Uint8 bg_g = 50, Uint8 bg_b = 50, Uint8 bg_a = 100);
 
     void update_Animation(AnimationData& anim, float delta_time);
     void Draw(SDL_Renderer* renderer);