diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-10-21 11:20:34 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-10-21 13:12:42 +0200 |
commit | 20b189455545db5688ed4f14d2966380137ee2db (patch) | |
tree | 7504e059147cfae54fa466b8a4c0073ecbbc582c /src/game.cpp | |
parent | 29d124b93125d7c9de762c45876f69df3acd549d (diff) |
Start working on path finding.
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/game.cpp b/src/game.cpp index d805c83..ffee87d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -4,8 +4,9 @@ namespace game { class unit_t : public world::entity_t { world::world_t *world; + v2f_t x; - void compute_bounds(v2f_t x) + void compute_bounds() { bounds[0] = x + size[0]; bounds[1] = x + size[1]; @@ -17,19 +18,19 @@ public: rectf_t size, render_size; struct { - world::tile_index_t pos; - bool moving; - std::list<world::tile_index_t*> path; - world::tile_index_t dest; + std::list<v2f_t> path; + v2f_t dst; } move; - void place(world::world_t *world, world::tile_index_t pos) + void place(world::world_t *world_, v2f_t x_) { - move.pos = pos; + world = world_; + x = x_; move.moving = false; + unlink(); - compute_bounds((v2f_t)pos + v2f_t(0.5f, 0.5f)); + compute_bounds(); link(world); } @@ -39,9 +40,22 @@ public: return; } - bool start_moving(world::tile_index_t dest) + bool start_moving(v2f_t dst_) { - return false; + if (!world) { + printf("unit_t::start_moving: entity is not linked\n"); + return false; + } + + move.dst = dst_; + move.path.clear(); + + if (world->find_path(x, move.dst, size, &move.path)) + move.moving = true; + else + move.moving = false; + + return move.moving; } }; @@ -65,7 +79,12 @@ void state_t::start(void) human.size[1] = v2f_t(+0.4f, +0.4f); human.render_size[0] = v2f_t(-0.5f, -1.0f); human.render_size[1] = v2f_t(+0.5f, +0.5f); - human.place(&world, world::tile_index_t(0, 0)); + human.place(&world, v2f_t(0.5f, 0.5f)); +} + +void state_t::debug_click(v2f_t x) +{ + human.start_moving(x); } void state_t::tick(void) |