diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2018-04-12 21:48:19 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2018-04-12 21:48:19 +0200 |
commit | 8be509797bc38095eb2b2867a0dfc19d7d799b97 (patch) | |
tree | 4eac48486b2dd9deb585ce1c72b6ecfea6da073a | |
parent | 5aa31b0e7f1a5fa242457d5522e097cbd13f32d3 (diff) |
Aim markers.
-rw-r--r-- | assets/units/aim_marker_0.png | bin | 0 -> 4002 bytes | |||
-rw-r--r-- | assets/units/aim_marker_1.png | bin | 0 -> 4040 bytes | |||
-rw-r--r-- | assets/units/aim_marker_2.png | bin | 0 -> 4041 bytes | |||
-rw-r--r-- | assets/units/aim_marker_3.png | bin | 0 -> 4020 bytes | |||
-rw-r--r-- | assets/units/aim_marker_4.png | bin | 0 -> 3853 bytes | |||
-rw-r--r-- | assets_src/aim_marker.blend | bin | 0 -> 517396 bytes | |||
-rw-r--r-- | src/game/assets.cpp | 3 | ||||
-rw-r--r-- | src/game/effects.cpp | 24 | ||||
-rw-r--r-- | src/game/game.cpp | 1 | ||||
-rw-r--r-- | src/game/game.hpp | 13 | ||||
-rw-r--r-- | src/game/unit_soldier.cpp | 7 |
11 files changed, 45 insertions, 3 deletions
diff --git a/assets/units/aim_marker_0.png b/assets/units/aim_marker_0.png Binary files differnew file mode 100644 index 0000000..0f180b3 --- /dev/null +++ b/assets/units/aim_marker_0.png diff --git a/assets/units/aim_marker_1.png b/assets/units/aim_marker_1.png Binary files differnew file mode 100644 index 0000000..9314071 --- /dev/null +++ b/assets/units/aim_marker_1.png diff --git a/assets/units/aim_marker_2.png b/assets/units/aim_marker_2.png Binary files differnew file mode 100644 index 0000000..5ad2e09 --- /dev/null +++ b/assets/units/aim_marker_2.png diff --git a/assets/units/aim_marker_3.png b/assets/units/aim_marker_3.png Binary files differnew file mode 100644 index 0000000..dec3cca --- /dev/null +++ b/assets/units/aim_marker_3.png diff --git a/assets/units/aim_marker_4.png b/assets/units/aim_marker_4.png Binary files differnew file mode 100644 index 0000000..317d849 --- /dev/null +++ b/assets/units/aim_marker_4.png diff --git a/assets_src/aim_marker.blend b/assets_src/aim_marker.blend Binary files differnew file mode 100644 index 0000000..606eab3 --- /dev/null +++ b/assets_src/aim_marker.blend diff --git a/src/game/assets.cpp b/src/game/assets.cpp index c4e9f41..f38b6ef 100644 --- a/src/game/assets.cpp +++ b/src/game/assets.cpp @@ -29,7 +29,7 @@ audio::ambient_t ambients[AMBIENT_COUNT]; render::animated_texture_t unit_selected; render::animated_texture_t unit_selected_halo; -render::animated_texture_t move_marker; +render::animated_texture_t move_marker, aim_marker; void load(void) { @@ -76,6 +76,7 @@ void load(void) unit_selected.load("assets/units/selected_", 1); unit_selected_halo.load("assets/units/selected_halo_", 1); move_marker.load("assets/units/move_marker_", 8); + aim_marker.load("assets/units/aim_marker_", 5); world::register_tile(TILE_DIRT, 0); render::register_tile(TILE_DIRT, "assets/tiles/dirt.png", NULL, 0.0f); diff --git a/src/game/effects.cpp b/src/game/effects.cpp index 96d04d1..f56c065 100644 --- a/src/game/effects.cpp +++ b/src/game/effects.cpp @@ -138,4 +138,28 @@ void fx_move_marker_t::render_to(render::state_t *render) render->render(game->now * 2, &assets::move_marker, render_bounds, sf::Color::White); } +fx_aim_marker_t::fx_aim_marker_t(state_t *game_, v2f_t x_) : effect_t(game_) +{ + x = x_; + render_bounds[0] = x + v2f_t(-0.2, -0.2); + render_bounds[1] = x + v2f_t(0.2, 0.2); + render_layer = 100; + cmodel.bounds = render_bounds; + cmodel.cflags = 0; + + ignore_waking = true; + link(&game->world); +} + +fx_aim_marker_t::~fx_aim_marker_t(void) +{ + unlink(); + sleep(); +} + +void fx_aim_marker_t::render_to(render::state_t *render) +{ + render->render(game->now * 2, &assets::aim_marker, render_bounds, sf::Color::White); +} + } // namespace game diff --git a/src/game/game.cpp b/src/game/game.cpp index 8deadd6..2a944af 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -225,6 +225,7 @@ static void command_soldier(unit_soldier_t *soldier, v2f_t x, int number) soldier->stop_moving(); soldier->manual_firing = false; soldier->say(text::get(text::SAY_STOPPING)); + soldier->aim_marker.reset(); break; case COMMAND_FIRE: diff --git a/src/game/game.hpp b/src/game/game.hpp index 5cf4494..321fc0c 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -98,7 +98,7 @@ namespace game { extern audio::ambient_t ambients[AMBIENT_COUNT]; extern render::animated_texture_t unit_selected; extern render::animated_texture_t unit_selected_halo; - extern render::animated_texture_t move_marker; + extern render::animated_texture_t move_marker, aim_marker; void load(void); } @@ -155,6 +155,7 @@ namespace game { }; class fx_move_marker_t; + class fx_aim_marker_t; unit_t *find_target(world::world_t *world, v2f_t x, float r, bool friendly); @@ -223,6 +224,7 @@ namespace game { v2f_t last_target_x; std::unique_ptr<fx_move_marker_t> move_marker; + std::unique_ptr<fx_aim_marker_t> aim_marker; sf::Color selection_color; @@ -345,6 +347,15 @@ namespace game { void render_to(render::state_t *render); }; + class fx_aim_marker_t : public effect_t { + v2f_t x; + + public: + fx_aim_marker_t(game::state_t *game_, v2f_t x_); + ~fx_aim_marker_t(void); + + void render_to(render::state_t *render); + }; typedef enum { DECO_STONE, diff --git a/src/game/unit_soldier.cpp b/src/game/unit_soldier.cpp index b3e93d1..7dca7ff 100644 --- a/src/game/unit_soldier.cpp +++ b/src/game/unit_soldier.cpp @@ -123,14 +123,18 @@ void unit_soldier_t::target_and_attack(void) next_targetting = game->now + 0.2; target = find_target(world, x, 5.0f, false); - if (!target) + if (!target) { + aim_marker.reset(); return; + } aim = target->x; last_target_time = game->now; last_target_x = target->x; skip_targetting: + aim_marker = std::make_unique<fx_aim_marker_t>(game, aim); + if (last_attack + game->prng.next_float(1.4f, 1.6f) > game->now) return; @@ -167,6 +171,7 @@ void unit_soldier_t::on_death(void) controllable = false; game->selected_units.erase(this); move_marker.reset(); + aim_marker.reset(); } void unit_soldier_t::render_to(render::state_t *render) |