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
|
#include "Battle.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <utility>
#include <raylib.h>
#include <kurator/battles/components.h>
#include <kurator/battles/Battle.h>
#include <kurator/battles/scenarios.h>
#include <kurator/universe/ShipType.h>
#include "Session.h"
#include "Title.h"
namespace kurator
{
Battle::Battle(std::shared_ptr<Session> _session) :
session {std::move(_session)},
battle {battles::prepare(battles::scenarios::example())}
{
}
void
Battle::update(const float dt)
{
battle->update(dt);
if (IsKeyPressed(KEY_SPACE))
session->set(std::make_shared<Title>(session));
}
void
Battle::draw() const
{
ClearBackground(BLACK);
const int width = GetScreenWidth();
const int height = GetScreenHeight();
const double scale = std::min(width/10.0, height/10.0);
auto view = battle->registry().view<const universe::ShipType, const battles::Team, const battles::Transform>();
for (auto [entity, ship_type, team, transform] : view.each()) {
(void) entity;
const auto color = team.id == 1 ? RED : GREEN;
const int x = width/2 + transform.position.x*scale;
const int y = height/2 + transform.position.y*scale;
DrawCircle(x, y, 5, color);
DrawLine(x, y, x + 6 * std::cos(transform.angle), y + 6 * std::sin(transform.angle), WHITE);
DrawText(ship_type.name.c_str(), x+10, y-10, 20.0f, GRAY);
}
}
} // namespace kurator
|