summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-10-18 19:53:51 +0200
committerPaweł Redman <pawel.redman@gmail.com>2017-10-18 19:53:51 +0200
commit29d124b93125d7c9de762c45876f69df3acd549d (patch)
treed940787ca232a9d0587dc83856f054b9aa401e23 /src/game.cpp
parentef5273d2c2ab801b11eb435a04bff96f6e778b1c (diff)
Render bounds are now working. Start working on unit movement.
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp92
1 files changed, 51 insertions, 41 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 725d6f0..d805c83 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -3,63 +3,73 @@
namespace game {
class unit_t : public world::entity_t {
-};
+ world::world_t *world;
-class human_t : public unit_t {
+ void compute_bounds(v2f_t x)
+ {
+ bounds[0] = x + size[0];
+ bounds[1] = x + size[1];
+ render_bounds[0] = x + render_size[0];
+ render_bounds[1] = x + render_size[1];
+ }
public:
- float angle = 0.0f;
- bool walking = false;
- float stalin = 0.0f;
+ 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;
+ } move;
+
+ void place(world::world_t *world, world::tile_index_t pos)
+ {
+ move.pos = pos;
+ move.moving = false;
+ unlink();
+ compute_bounds((v2f_t)pos + v2f_t(0.5f, 0.5f));
+ link(world);
+ }
+
+ void keep_moving(void)
+ {
+ if (!move.moving)
+ return;
+ }
+
+ bool start_moving(world::tile_index_t dest)
+ {
+ return false;
+ }
+};
+class human_t : public unit_t {
+public:
void render_to(render::state_t *render)
{
- render->render((walking ? &assets::human.legs_walking :
- &assets::human.legs_idle), bounds, angle);
- render->render(&assets::human.body_idle, bounds, angle);
- render->render(&assets::human.head_idle, bounds, angle);
+ float angle = 0;
+ render->render((move.moving ? &assets::human.legs_walking :
+ &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);
}
};
-static std::list<human_t> humans;
+static human_t human;
void state_t::start(void)
{
- for (size_t i = 0; i < 5; i++) {
- humans.emplace(humans.end());
-
- human_t &human = *(--humans.end());
-
- human.bounds.v[0] = v2f_t(0.33f, 0);
- human.bounds.v[1] = human.bounds.v[0] + v2f_t(0.66f, 1.0f);
- human.render_bounds = human.bounds;
- human.link(&world);
- }
+ human.size[0] = v2f_t(-0.4f, -0.4f);
+ 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));
}
void state_t::tick(void)
{
- for (human_t &human : humans) {
- human.stalin -= ((float)rand() / RAND_MAX) * 0.1f;
-
- human.walking = false;
-
- if (human.stalin < 0) {
- v2f_t delta;
-
- human.walking = true;
- human.angle += (rand() & 2 ? 0.2f : -0.2f);
- human.unlink();
- delta = v2f_t(cos(human.angle), sin(human.angle)) * 0.04;
- human.bounds[0] += delta;
- human.bounds[1] += delta;
- human.render_bounds = human.bounds;
- human.link(&world);
- }
-
- if (human.stalin < -4.0f)
- human.stalin = (float)rand() / RAND_MAX * 3.0f;
- }
}
} //namespace game