summaryrefslogtreecommitdiff
path: root/src/game/game.hpp
blob: fa75da1c3db16900058b96adb0cd7a901bf9fc3b (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
66
67
68
69
70
71
72
73
#include "../common.hpp"

namespace game {
	enum {
		ET_UNIT
	};

	enum {
		TILE_NONE,
		TILE_DIRT,
		TILE_WALL
	};

	extern size_t selection_cookie;

	void worldgen(world::tile_t *tile, world::tile_index_t x,
	              procgen::perlin_noise_t *perlin);

	namespace assets {
		typedef struct {
			render::oriented_sprite_4M_t head_idle, body_idle;
			render::oriented_sprite_4M2_t legs_idle, legs_walking;
		} human_assets_t;

		extern human_assets_t human;
		extern sf::Texture tile_dirt;
		extern sf::Texture tile_wall;

		void load(void);
	}

	class unit_t : public world::entity_t {
	protected:
		world::world_t *world;

		world::cmodel_t make_cmodel(v2f_t at);
		void compute_bounds();

	public:
		v2f_t x;
		rectf_t size, render_size;
		world::cflags_t cflags;
		size_t selected = 0;

		unit_t();

		struct {
			bool moving = false;
			v2f_t dst;
			float angle = 0.0f;

			std::list<v2f_t> path;

			bool blocked;
			size_t attempts_left;
			float next_attempt;
		} move;

		const wchar_t *say_text;
		double say_time = -INFINITY;

		void say(const wchar_t *wstr, double now);
		void place(world::world_t *world_, v2f_t x_);
		void keep_moving(double now, double dt);
		bool start_moving(v2f_t dst_, double now);
	};

	class human_t : public unit_t {
	public:
		human_t();
		void render_to(render::state_t *render);
	};
};