summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp47
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