diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-10-14 15:54:01 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-10-14 15:54:01 +0200 |
commit | e4ca910e7731e2a12815a4a8de2582157f519898 (patch) | |
tree | 7bd9e2109bc39e26ea0f790c19b960cce5bd2246 /src/game.cpp | |
parent | bb0a7bfe31714ff56ce1c1ce428cdf240804db14 (diff) |
Correct entity drawing order.
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/src/game.cpp b/src/game.cpp index bb04ee7..58b56c6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -26,6 +26,7 @@ class human_t : public unit_t { public: float angle = 0.0f; bool walking = false; + float stalin = 0.0f; void render_to(render::state_t *render) { @@ -36,37 +37,43 @@ public: } }; -static human_t *human; +static std::list<human_t> humans; void state_t::start(void) { - human = new human_t; - human->bounds.left = 0.33f; - human->bounds.top = 0.0f; - human->bounds.width = 0.66f; - human->bounds.height = 1.0f; - human->link(&world); } void state_t::tick(void) { - static float stalin = 2.0f; + if (rand() % 5 == 0) { + humans.emplace(humans.end()); - stalin -= ((float)rand() / RAND_MAX) * 0.1f; + human_t &human = *(--humans.end()); - human->walking = false; - - if (stalin < 0) { - human->walking = true; - human->angle += (rand() & 2 ? 0.2f : -0.2f); - human->unlink(); - human->bounds.left += cos(human->angle) * 0.04; - human->bounds.top += sin(human->angle) * 0.04; - human->link(&world); + human.bounds.left = 0.33f; + human.bounds.top = 0; + human.bounds.width = 0.66f; + human.bounds.height = 1.0f; + human.link(&world); } - if (stalin < -4.0f) - stalin = 2.0f; + for (human_t &human : humans) { + human.stalin -= ((float)rand() / RAND_MAX) * 0.1f; + + human.walking = false; + + if (human.stalin < 0) { + human.walking = true; + human.angle += (rand() & 2 ? 0.2f : -0.2f); + human.unlink(); + human.bounds.left += cos(human.angle) * 0.04; + human.bounds.top += sin(human.angle) * 0.04; + human.link(&world); + } + + if (human.stalin < -4.0f) + human.stalin = 2.0f; + } } } //namespace game |