summaryrefslogtreecommitdiff
path: root/src/game.cpp
blob: 725d6f0df016f6f0f1a058144b766564cc7dfdf8 (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
64
65
#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.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);
	}
}

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