blob: 59b8ad945c28628ab2dacc6ca349ea70197419db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include "common.hpp"
namespace game {
class unit_t : public world::entity_t {
};
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)
{
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);
}
};
static std::list<human_t> humans;
void state_t::start(void)
{
for (size_t i = 0; i < 5; i++) {
humans.emplace(humans.end());
human_t &human = *(--humans.end());
human.bounds.left = 0.33f;
human.bounds.top = 0;
human.bounds.width = 0.66f;
human.bounds.height = 1.0f;
human.render_bounds = human.bounds;
human.link(&world);
}
}
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) {
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 = (float)rand() / RAND_MAX * 3.0f;
}
}
} //namespace game
|