summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-11-07 18:33:03 +0100
committerPaweł Redman <pawel.redman@gmail.com>2017-11-07 18:33:03 +0100
commit5186351345d43801ac45acde8b7e30734eea0349 (patch)
tree7c331bb3c34de2ce31a791f79e7bf783534870d0 /src/game.cpp
parentd0be87d32929c42502fb842aa2b0ab0233313b93 (diff)
Better unit say.
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 48047a4..5dc9af8 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -50,10 +50,14 @@ public:
float next_attempt;
} move;
- void say(std::string str)
+ const wchar_t *say_text;
+ double say_time = -INFINITY;
+
+ void say(const wchar_t *wstr, double now)
{
- //TODO
- std::cout << (void*)this << ": " << str << "\n";
+ say_text = wstr;
+ say_time = now;
+ std::cout << (void*)this << ": " << wstr << "\n";
}
void place(world::world_t *world_, v2f_t x_)
@@ -116,7 +120,7 @@ public:
move.next_attempt = now + 0.5f;
} else {
if ((x - move.dst).len() > 1.5f)
- say(text::unit_blocked);
+ say(text::unit_blocked, now);
move.moving = false;
}
break;
@@ -128,7 +132,7 @@ public:
link(world);
}
- bool start_moving(v2f_t dst_)
+ bool start_moving(v2f_t dst_, double now)
{
if (!world) {
printf("unit_t::start_moving: entity is not linked\n");
@@ -139,7 +143,7 @@ public:
move.path.clear();
if (!world->find_path(x, move.dst, &cmodel, this, &move.path)) {
- say(text::unit_no_path);
+ say(text::unit_no_path, now);
move.moving = false;
return false;
}
@@ -174,6 +178,17 @@ public:
if (move.moving && debug_draw_paths)
render->debug_path(&move.path);
+
+ if (say_time + 5.0 > render->now) {
+ v2f_t text_pos;
+ float height;
+
+ text_pos = render_bounds[0] + v2f_t(render_bounds.dim(0) / 2, -render_bounds.dim(1) * 0.1);
+ height = size.dim_min() * 0.20f;
+ render->render_text(text_pos, height, say_text,
+ render::ALIGN_CENTER_BOTTOM,
+ sf::Color::White);
+ }
}
};
@@ -199,7 +214,7 @@ void state_t::select(rectf_t x)
selection_cookie++;
selected_units.clear();
- for (world::entity_t *ent : world.get_render_entities(x, -1)) {
+ for (world::entity_t *ent : world.get_render_entities(x)) {
unit_t *unit;
if (ent->type != ET_UNIT)
@@ -214,13 +229,14 @@ void state_t::select(rectf_t x)
void state_t::command(v2f_t x)
{
for (unit_t *unit : selected_units)
- unit->start_moving(x);
+ unit->start_moving(x, now);
}
-void state_t::tick(double now)
+void state_t::tick(double now_)
{
- human.keep_moving(now);
- human2.keep_moving(now);
+ now = now_;
+ human.keep_moving(now_);
+ human2.keep_moving(now_);
}
} //namespace game