summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-25 18:27:13 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-25 18:27:13 +0200
commite4be331008ca5e64ef2d42f51c5cf5799dd61abc (patch)
treeb451e3f0740ab5685e311f50645e6c81a8939e02 /src/game
parent7103fffc57798ac0bd0ce0819a86b8411cf2c1ae (diff)
Ammunition mechanic for soldiers.
Diffstat (limited to 'src/game')
-rw-r--r--src/game/assets.cpp3
-rw-r--r--src/game/game.hpp5
-rw-r--r--src/game/interface.cpp9
-rw-r--r--src/game/unit_soldier.cpp9
4 files changed, 23 insertions, 3 deletions
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) {