summaryrefslogtreecommitdiff
path: root/src/game/game.cpp
blob: e58b8d519f87c5cd9cf897a2127fee82055d9a71 (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
#include "game.hpp"

namespace game {

size_t selection_cookie = 1;

void state_t::start(void)
{
	human_t *human;

	world.generator = worldgen;

	human = new human_t;
	human->place(&world, v2f_t(0.5, 0.5));
	units.insert(human);
}

void state_t::stop(void)
{
	// FIXME
	/*
	for (unit_t *unit : units)
		delete unit;
	*/
}

void state_t::select(rectf_t x)
{
	selection_cookie++;
	selected_units.clear();

	for (world::entity_t *ent : world.get_render_entities(x)) {
		unit_t *unit;

		if (ent->type != ET_UNIT)
			continue;

		unit = (unit_t*)ent;
		unit->selected = selection_cookie;
		selected_units.insert(unit);
	}
}

void state_t::command(v2f_t x)
{
	v2f_t snap;

	snap[0] = std::round(x[0] - 0.5f) + 0.5f;
	snap[1] = std::round(x[1] - 0.5f) + 0.5f;

	for (unit_t *unit : selected_units)
		unit->start_moving(snap, now);
}

void state_t::tick(double now_, double dt_)
{
	now = now_;
	dt = dt_;

	for (unit_t *unit : units)
		unit->keep_moving(now, dt);
}

bool load_assets(void)
{
	assets::load();
	return true;
}

} //namespace game