diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game/assets.cpp | 5 | ||||
-rw-r--r-- | src/game/game.hpp | 2 | ||||
-rw-r--r-- | src/game/interface.cpp | 76 | ||||
-rw-r--r-- | src/game/unit_soldier.cpp | 4 |
4 files changed, 55 insertions, 32 deletions
diff --git a/src/game/assets.cpp b/src/game/assets.cpp index d9f9740..f4ce68a 100644 --- a/src/game/assets.cpp +++ b/src/game/assets.cpp @@ -154,8 +154,11 @@ void load(void) ambients[AMBIENT_WATER].volume = 0.1f; ui.crystals.load("assets/ui/crystals_", 1); + ui.icon_health.load("assets/ui/icon_health_", 1); + ui.icon_grenade.load("assets/ui/icon_grenade_", 1); + ui.crystal_tick.load("assets/ui/crystal_tick.ogg"); - ui.crystal_tick.volume = 0.3f; + ui.crystal_tick.volume = 0.1f; } } // namespace game::assets diff --git a/src/game/game.hpp b/src/game/game.hpp index 50f903b..b072997 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -253,7 +253,7 @@ namespace game { } deco_assets_t; typedef struct { - render::animated_texture_t crystals; + render::animated_texture_t crystals, icon_health, icon_grenade; audio::sound_t crystal_tick; } ui_assets_t; diff --git a/src/game/interface.cpp b/src/game/interface.cpp index 9e43839..2e1d8ab 100644 --- a/src/game/interface.cpp +++ b/src/game/interface.cpp @@ -338,14 +338,43 @@ static sf::Color health_to_color(float frac,int alpha) return sf::Color(255, 0, 0, alpha); } +static void render_bar(render::state_t *render, rectf_t rect, size_t value, size_t max, + render::animated_texture_t *icon_image) +{ + rectf_t bar, icon; + std::string text; + v2f_t text_x; + float text_h; + + render->render_rect(rect, sf::Color(0, 0, 0, 128)); + + if (max) { + float frac = (float)value / max; + + bar = rect; + bar[1][0] = lerp(bar[0][0], bar[1][0], frac); + render->render_rect(bar, health_to_color(frac, 90)); + + text = std::to_string(value) + "/" + std::to_string(max); + } else + text = std::to_string(value); + + icon[0] = bar[0]; + icon[1] = bar[0] + v2f_t(1.0f, 1.0f) * bar.dim(1); + render->render(0.0, icon_image, icon); + + text_h = bar.dim(1); + text_x = v2f_t(bar[0][0] + text_h, bar[1][1] - text_h * 0.35f); + + render->render_text(text_x, text_h, text, render::ALIGN_LEFT_BOTTOM, sf::Color::White); +} + static void render_avatar(render::state_t *render, game::unit_t *unit, v2f_t at, v2f_t avatar_size, float em, bool large) { render::animated_texture_t *image; - rectf_t rect, bar; - v2f_t x; - std::string str; - float frac; + rectf_t rect, row; + v2f_t name_x; switch (unit->type) { case game::unit_t::UNIT_SOLDIER: @@ -372,35 +401,26 @@ static void render_avatar(render::state_t *render, game::unit_t *unit, v2f_t at, rect = rectf_t(at, at + avatar_size * em); render->render(0, image, rect, sf::Color::White); - frac = (float)unit->health / unit->max_health; + if (!large) + em *= 0.65f; - if (!large) { - bar = rect; - bar[0][1] = bar[1][1] - em; - render->render_rect(bar, sf::Color(0, 0, 0, 128)); + row = rect; + row[0][1] = row[1][1] - em; - bar[1][0] = lerp(bar[0][0], bar[1][0], frac); - render->render_rect(bar, health_to_color(frac, 90)); + render_bar(render, row, unit->health, unit->max_health, + &assets::ui.icon_health); + row[0][1] -= em; + row[1][1] -= em; - return; + if (unit->storage.max_grenades) { + render_bar(render, row, unit->storage.grenades, unit->storage.max_grenades, + &assets::ui.icon_grenade); + row[0][1] -= em; + row[1][1] -= em; } - x = v2f_t(rect[0][0], rect[1][1] - em / 2); - bar[0][0] = x[0]; - bar[0][1] = x[1] - 0.5f * em; - bar[1][0] = rect[1][0]; - bar[1][1] = bar[0][1] + 0.9f * em; - render->render_rect(bar, sf::Color(0, 0, 0, 128)); - - bar[1][0] = lerp(bar[0][0], bar[1][0], frac); - render->render_rect(bar, health_to_color(frac, 90)); - - str = std::to_string(unit->health) + "/" + std::to_string(unit->max_health); - render->render_text(x, em, str, render::ALIGN_LEFT_BOTTOM, sf::Color::White); - - x[1] -= em; - render->render_text(x + v2f_t(0.1, 0.1) * em, em, unit->name, render::ALIGN_LEFT_BOTTOM, sf::Color::Black); - render->render_text(x, em, unit->name, render::ALIGN_LEFT_BOTTOM, sf::Color::White); + name_x = v2f_t(row[0][0], row[1][1] - em * 0.35f); + render->render_text(name_x, em, unit->name, render::ALIGN_LEFT_BOTTOM, sf::Color::White); } void state_t::render_to(render::state_t *render) diff --git a/src/game/unit_soldier.cpp b/src/game/unit_soldier.cpp index 1e34d7c..f2caaf3 100644 --- a/src/game/unit_soldier.cpp +++ b/src/game/unit_soldier.cpp @@ -28,7 +28,7 @@ static std::string soldier_name(procgen::prng_t *prng) }; static const char *surnames[] = { "Kloss", "Schmidt", "Göring", "Fischer", "Müller", "Weber", - "Schulz", "Schäfer", "Klein", "Wofl", "Schröder", "Neumann", + "Schulz", "Schäfer", "Klein", "Wolf", "Schröder", "Neumann", "Zimmermann" }; @@ -57,7 +57,7 @@ unit_soldier_t::unit_soldier_t(game::state_t *game) : unit_t(game, UNIT_SOLDIER) controllable = true; health = max_health = 28; - storage.grenades = 3; + storage.max_grenades = storage.grenades = 3; } static v2f_t spread_aim(v2f_t x, v2f_t aim, float cof, procgen::prng_t *prng) |