summaryrefslogtreecommitdiff
path: root/battles/src/Battle.cpp
blob: 454cbfd7a2ad3f32a1dd962b97949d23273e8f3d (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
#include <kurator/battles/Battle.h>

#include <random>

#include <kurator/battles/components.h>
#include <kurator/battles/Scenario.h>
#include <kurator/universe/ShipType.h>


namespace kurator
{
namespace battles
{


Battle::Battle(Scenario scenario)
{
	std::random_device dev;
	std::uniform_real_distribution<> pos{-2.5, 2.5};
	for (const auto& ship : scenario.ships) {
		const auto entity = registry.create();
		registry.emplace<universe::ShipType>(entity, ship.type);
		registry.emplace<Team>(entity, ship.team);
		registry.emplace<Transform>(entity, Point{pos(dev), pos(dev)}, Point{0.0, 0.0});
	}
}


void
Battle::update(const float dt)
{
	auto view = registry.view<Transform, Team>();
	for (auto&& [entity, transform, team] : view.each())
		transform.position.x += 0.1 * dt * (team.id * 2 - 1);
}


}  // namespace battles
}  // namespace kurator