From e4be331008ca5e64ef2d42f51c5cf5799dd61abc Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Wed, 25 Apr 2018 18:27:13 +0200 Subject: Ammunition mechanic for soldiers. --- assets/ui/icon_grenade_0.png | Bin 886 -> 0 bytes assets/ui/icon_grenades_0.png | Bin 0 -> 886 bytes assets/ui/icon_shells_0.png | Bin 0 -> 974 bytes src/game/assets.cpp | 3 ++- src/game/game.hpp | 5 ++++- src/game/interface.cpp | 9 ++++++++- src/game/unit_soldier.cpp | 9 +++++++++ 7 files changed, 23 insertions(+), 3 deletions(-) delete mode 100644 assets/ui/icon_grenade_0.png create mode 100644 assets/ui/icon_grenades_0.png create mode 100644 assets/ui/icon_shells_0.png diff --git a/assets/ui/icon_grenade_0.png b/assets/ui/icon_grenade_0.png deleted file mode 100644 index f7f7e12..0000000 Binary files a/assets/ui/icon_grenade_0.png and /dev/null differ diff --git a/assets/ui/icon_grenades_0.png b/assets/ui/icon_grenades_0.png new file mode 100644 index 0000000..f7f7e12 Binary files /dev/null and b/assets/ui/icon_grenades_0.png differ diff --git a/assets/ui/icon_shells_0.png b/assets/ui/icon_shells_0.png new file mode 100644 index 0000000..9c97aac Binary files /dev/null and b/assets/ui/icon_shells_0.png differ diff --git a/src/game/assets.cpp b/src/game/assets.cpp index f4ce68a..22cd88f 100644 --- a/src/game/assets.cpp +++ b/src/game/assets.cpp @@ -155,7 +155,8 @@ void load(void) 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.icon_shells.load("assets/ui/icon_shells_", 1); + ui.icon_grenades.load("assets/ui/icon_grenades_", 1); ui.crystal_tick.load("assets/ui/crystal_tick.ogg"); ui.crystal_tick.volume = 0.1f; diff --git a/src/game/game.hpp b/src/game/game.hpp index b072997..19fda52 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -253,8 +253,10 @@ namespace game { } deco_assets_t; typedef struct { - render::animated_texture_t crystals, icon_health, icon_grenade; + render::animated_texture_t crystals; audio::sound_t crystal_tick; + + render::animated_texture_t icon_health, icon_grenades, icon_shells; } ui_assets_t; extern soldier_assets_t soldier; @@ -304,6 +306,7 @@ namespace game { unit_t *find_target(world::world_t *world, v2f_t x, float r, bool friendly); typedef struct { + size_t shells, max_shells = 0; size_t grenades, max_grenades = 0; } storage_t; diff --git a/src/game/interface.cpp b/src/game/interface.cpp index 2e1d8ab..1c2d7b5 100644 --- a/src/game/interface.cpp +++ b/src/game/interface.cpp @@ -412,9 +412,16 @@ static void render_avatar(render::state_t *render, game::unit_t *unit, v2f_t at, row[0][1] -= em; row[1][1] -= em; + if (unit->storage.max_shells) { + render_bar(render, row, unit->storage.shells, unit->storage.max_shells, + &assets::ui.icon_shells); + row[0][1] -= em; + row[1][1] -= em; + } + if (unit->storage.max_grenades) { render_bar(render, row, unit->storage.grenades, unit->storage.max_grenades, - &assets::ui.icon_grenade); + &assets::ui.icon_grenades); row[0][1] -= em; row[1][1] -= em; } diff --git a/src/game/unit_soldier.cpp b/src/game/unit_soldier.cpp index f2caaf3..4747060 100644 --- a/src/game/unit_soldier.cpp +++ b/src/game/unit_soldier.cpp @@ -57,6 +57,7 @@ unit_soldier_t::unit_soldier_t(game::state_t *game) : unit_t(game, UNIT_SOLDIER) controllable = true; health = max_health = 28; + storage.max_shells = storage.shells = 20; storage.max_grenades = storage.grenades = 3; } @@ -112,6 +113,14 @@ void unit_soldier_t::fire_shotgun(v2f_t aim) if (next_attack && game->time < next_attack) return; + if (!storage.shells) { + next_attack = game->time + SEC(1); + say("Keine Munition mehr!"); + return; + } + + storage.shells--; + trace = world->ray_v_all_p3d(x, aim, CF_SOLID|CF_BODY|CF_BODY_SMALL, -1, this); if (!manual_firing && trace.hit && trace.ent && trace.ent->type == ET_UNIT) { -- cgit