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
66
67
68
69
70
71
72
|
#include "common.hpp"
namespace game {
class unit_t : public world::entity_t {
};
struct {
struct {
render::oriented_sprite_4M_t head_idle, body_idle;
render::oriented_sprite_4M2_t legs_idle, legs_walking;
} human;
} assets;
bool load_assets(void)
{
assets.human.head_idle.load("assets/units/human/head_idle", 1, 1, 1);
assets.human.body_idle.load("assets/units/human/body_idle", 2, 2, 2);
assets.human.legs_idle.load("assets/units/human/legs_idle", 2, 2);
assets.human.legs_walking.load("assets/units/human/legs_walking", 2, 2);
return true;
}
class human_t : public unit_t {
public:
float angle = 0.0f;
bool walking = false;
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 human_t *human;
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;
stalin -= ((float)rand() / RAND_MAX) * 0.1f;
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);
}
if (stalin < -4.0f)
stalin = 2.0f;
}
} //namespace game
|