summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-12-19 20:19:01 +0100
committerPaweł Redman <pawel.redman@gmail.com>2017-12-19 20:22:32 +0100
commit7d0b6babe9906df0990028e41e0f895fab605498 (patch)
treee5fca214d7acfc1a1135b21bde54db4b5c813a6d
parenta284014075b0abac2b65e3064eac152e8a62bc15 (diff)
Better selection markers.
-rw-r--r--assets/units/selected_0.pngbin817 -> 872 bytes
-rw-r--r--assets/units/selected_halo_0.pngbin0 -> 792 bytes
-rw-r--r--src/common.hpp1
-rw-r--r--src/game/assets.cpp2
-rw-r--r--src/game/game.hpp13
-rw-r--r--src/game/units.cpp36
-rw-r--r--src/render.cpp7
7 files changed, 41 insertions, 18 deletions
diff --git a/assets/units/selected_0.png b/assets/units/selected_0.png
index 621b6a3..19a7a2e 100644
--- a/assets/units/selected_0.png
+++ b/assets/units/selected_0.png
Binary files differ
diff --git a/assets/units/selected_halo_0.png b/assets/units/selected_halo_0.png
new file mode 100644
index 0000000..1cabbc3
--- /dev/null
+++ b/assets/units/selected_halo_0.png
Binary files differ
diff --git a/src/common.hpp b/src/common.hpp
index 7b2f24a..c249db4 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -162,6 +162,7 @@ namespace world {
void unlink();
virtual void render_to(render::state_t *render) = 0;
+ virtual void render_late_to(render::state_t *render) = 0;
};
typedef struct {
diff --git a/src/game/assets.cpp b/src/game/assets.cpp
index 046934b..66d3bc8 100644
--- a/src/game/assets.cpp
+++ b/src/game/assets.cpp
@@ -9,6 +9,7 @@ fx_assets_t fx;
deco_assets_t deco;
render::animated_texture_t unit_selected;
+render::animated_texture_t unit_selected_halo;
void load(void)
{
@@ -36,6 +37,7 @@ void load(void)
deco.spike_small.load("assets/deco/spike_small_", 1);
unit_selected.load("assets/units/selected_", 1);
+ unit_selected_halo.load("assets/units/selected_halo_", 1);
world::register_tile(TILE_DIRT, 0);
render::register_tile(TILE_DIRT, "assets/tiles/dirt.png", NULL, 0.0f);
diff --git a/src/game/game.hpp b/src/game/game.hpp
index 456a8ea..7adc307 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -59,7 +59,8 @@ namespace game {
extern nest_assets_t nest;
extern fx_assets_t fx;
extern deco_assets_t deco;
- extern render::animated_texture_t unit_selected;
+ extern render::animated_texture_t unit_selected;
+ extern render::animated_texture_t unit_selected_halo;
void load(void);
}
@@ -182,15 +183,15 @@ namespace game {
double say_time = -INFINITY;
void say(std::string str);
- void render_to_pre(render::state_t *render);
void render_to(render::state_t *render);
-
};
class unit_soldier_t : public unit_t {
double last_target_time = -INFINITY;
v2f_t last_target_x;
+ sf::Color selection_color;
+
double next_fear_test = -INFINITY;
size_t willpower_bonus;
size_t fear_dc;
@@ -206,6 +207,7 @@ namespace game {
unit_soldier_t(game::state_t *game_);
~unit_soldier_t(void) {};
void render_to(render::state_t *render);
+ void render_late_to(render::state_t *render);
void on_think(void);
void on_spawn(void) {};
@@ -218,6 +220,7 @@ namespace game {
unit_spider_t(game::state_t *game_);
~unit_spider_t(void) {};
void render_to(render::state_t *render);
+ void render_late_to(render::state_t *render) {};
void target_and_attack(void);
@@ -234,6 +237,7 @@ namespace game {
unit_nest_t(game::state_t *game_);
~unit_nest_t(void) {};
void render_to(render::state_t *render);
+ void render_late_to(render::state_t *render) {};
void on_think(void);
void on_spawn(void);
@@ -251,6 +255,8 @@ namespace game {
void on_think(void);
void on_spawn(void) {};
void on_wake(void) {};
+
+ void render_late_to(render::state_t *render) {};
};
class fx_tracer_t : public effect_t {
@@ -290,6 +296,7 @@ namespace game {
deco_t(game::state_t *game, deco_type_t type_);
void render_to(render::state_t *render);
+ void render_late_to(render::state_t *render) {};
void on_think(void) {};
void on_spawn(void) {};
diff --git a/src/game/units.cpp b/src/game/units.cpp
index e7f5e81..214861b 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -7,12 +7,6 @@ unit_t::unit_t(game::state_t *game_, unit_t::type_t type_) : game::entity_t(game
type = type_;
}
-void unit_t::render_to_pre(render::state_t *render)
-{
- if (!dead && selected == selection_cookie)
- render->render(0.0, &assets::unit_selected, cmodel.bounds);
-}
-
void unit_t::render_to(render::state_t *render)
{
if (!dead && health < max_health)
@@ -440,8 +434,6 @@ void unit_soldier_t::on_think(void)
void unit_soldier_t::on_death(void)
{
- game->selected_units.erase(this);
-
render_size[0] = v2f_t(-0.75f, -0.5f);
render_size[1] = v2f_t(+0.75f, +0.5f);
render_layer = -1;
@@ -451,7 +443,23 @@ void unit_soldier_t::on_death(void)
void unit_soldier_t::render_to(render::state_t *render)
{
- unit_t::render_to_pre(render);
+ sf::Color selection_color;
+
+ if (selected == selection_cookie) {
+ if (health == max_health)
+ selection_color = sf::Color::Green;
+ else if (health >= max_health / 2)
+ selection_color = sf::Color::Yellow;
+ else if (dead)
+ selection_color = sf::Color::Black;
+ else
+ selection_color = sf::Color::Red;
+
+ if (panic && (game->now - floor(game->now) > 0.5))
+ selection_color = sf::Color::Blue;
+
+ render->render(0.0, &assets::unit_selected, cmodel.bounds, selection_color);
+ }
if (!dead) {
render::oriented_sprite_t *legs, *body;
@@ -489,6 +497,12 @@ void unit_soldier_t::render_to(render::state_t *render)
unit_t::render_to(render);
}
+void unit_soldier_t::render_late_to(render::state_t *render)
+{
+ if (selected == selection_cookie)
+ render->render(0.0, &assets::unit_selected_halo, cmodel.bounds, selection_color);
+}
+
unit_spider_t::unit_spider_t(game::state_t *game) : unit_t(game, UNIT_SPIDER)
{
size[0] = v2f_t(-0.2f, +0.0f);
@@ -561,8 +575,6 @@ void unit_spider_t::render_to(render::state_t *render)
{
bool moving;
- unit_t::render_to_pre(render);
-
moving = move.moving && !move.blocked;
if (!dead)
@@ -640,8 +652,6 @@ void unit_nest_t::on_death(void)
void unit_nest_t::render_to(render::state_t *render)
{
- unit_t::render_to_pre(render);
-
if (!dead)
render->render(game->now, &assets::nest.idle, render_bounds);
else
diff --git a/src/render.cpp b/src/render.cpp
index 6c47ab7..a640ecc 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -271,9 +271,12 @@ void state_t::render(game::state_t *game)
}
}
- if (debug_draw_cmodels)
- for (world::entity_t *ent : ents)
+ for (world::entity_t *ent : ents) {
+ ent->render_late_to(this);
+
+ if (debug_draw_cmodels)
drender_entity(ent);
+ }
}
void state_t::render(double phase, animated_texture_t *anim, rectf_t bounds, sf::Color color, bool mirror){