summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-12 21:48:19 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-12 21:48:19 +0200
commit8be509797bc38095eb2b2867a0dfc19d7d799b97 (patch)
tree4eac48486b2dd9deb585ce1c72b6ecfea6da073a /src
parent5aa31b0e7f1a5fa242457d5522e097cbd13f32d3 (diff)
Aim markers.
Diffstat (limited to 'src')
-rw-r--r--src/game/assets.cpp3
-rw-r--r--src/game/effects.cpp24
-rw-r--r--src/game/game.cpp1
-rw-r--r--src/game/game.hpp13
-rw-r--r--src/game/unit_soldier.cpp7
5 files changed, 45 insertions, 3 deletions
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)