summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/game.cpp b/src/game.cpp
index ffee87d..2d9b67e 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -19,8 +19,9 @@ public:
struct {
bool moving;
- std::list<v2f_t> path;
v2f_t dst;
+
+ std::list<v2f_t> path;
} move;
void place(world::world_t *world_, v2f_t x_)
@@ -34,10 +35,47 @@ public:
link(world);
}
+ bool move_towards(v2f_t point, float *time)
+ {
+ bool partial;
+ v2f_t delta;
+
+ delta = point - x;
+
+ if (delta.len() >= *time) {
+ partial = true;
+ x += delta * *time / delta.len();
+ *time = 0.0f;
+ } else {
+ partial = false;
+ x = point;
+ *time -= delta.len();
+ }
+
+ return partial;
+ }
+
void keep_moving(void)
{
+ float time;
+
if (!move.moving)
return;
+
+ time = 0.15;
+
+ while (time > 0.0f) {
+ if (!move.path.size()) {
+ move.moving = false;
+ break;
+ }
+
+ if (!move_towards(*move.path.begin(), &time)) {
+ move.path.pop_front();
+ }
+ }
+
+ compute_bounds();
}
bool start_moving(v2f_t dst_)
@@ -68,6 +106,9 @@ public:
&assets::human.legs_idle), render_bounds, angle);
render->render(&assets::human.body_idle, render_bounds, angle);
render->render(&assets::human.head_idle, render_bounds, angle);
+
+ if (move.moving)
+ render->debug_path(&move.path);
}
};
@@ -89,6 +130,7 @@ void state_t::debug_click(v2f_t x)
void state_t::tick(void)
{
+ human.keep_moving();
}
} //namespace game