summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--battles/src/Battle.cpp8
-rw-r--r--kurator/src/Battle.cpp26
-rw-r--r--kurator/src/Battle.h5
3 files changed, 20 insertions, 19 deletions
diff --git a/battles/src/Battle.cpp b/battles/src/Battle.cpp
index 699b9c4..e59f951 100644
--- a/battles/src/Battle.cpp
+++ b/battles/src/Battle.cpp
@@ -1,5 +1,10 @@
#include <kurator/battles/Battle.h>
+#include <cmath>
+#include <random>
+
+#include <entt/entity/entity.hpp>
+
#include <kurator/battles/components.h>
#include <kurator/battles/Scenario.h>
#include <kurator/universe/ShipType.h>
@@ -13,12 +18,15 @@ namespace battles
Battle::Battle(Scenario scenario)
{
+ std::random_device dev;
+ std::uniform_real_distribution<> pos{-5.0, 5.0};
int team = 0;
for (const auto& ships : scenario.teams) {
for (const auto& ship : ships) {
const auto entity = registry.create();
registry.emplace<universe::ShipType>(entity, ship.type);
registry.emplace<Team>(entity, team);
+ registry.emplace<Transform>(entity, Point{pos(dev), pos(dev)}, Point{0.0, 0.0});
}
team++;
}
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index 63a4b4a..a68df17 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -1,5 +1,6 @@
#include "Battle.h"
+#include <algorithm>
#include <memory>
#include <utility>
@@ -36,18 +37,14 @@ static const battles::Scenario DEFAULT {
Battle::Battle(std::shared_ptr<Session> _session) :
session {std::move(_session)},
- battle {DEFAULT},
- camera {{1.f, 1.f, 1.f}, {4.f, 1.f, 4.f}, {0.f, 1.f, 0.f}, 45.f, 0},
- skybox {"resources/skybox.png"}
+ battle {DEFAULT}
{
- SetCameraMode(camera, CAMERA_FIRST_PERSON);
}
void
Battle::update(const float)
{
- UpdateCamera(&camera);
if (IsKeyPressed(KEY_SPACE))
session->set(std::make_shared<Title>(session));
}
@@ -57,16 +54,17 @@ void
Battle::draw() const
{
ClearBackground(BLACK);
- BeginMode3D(camera);
- skybox.draw();
- DrawGrid(10, 1.f);
- EndMode3D();
- auto view = battle.registry.view<const universe::ShipType, const battles::Team>();
- int y = 10;
- for (auto [entity, ship_type, team] : view.each()) {
+ 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;
- DrawText(TextFormat("%d %s", team.id, ship_type.name.c_str()), 10, y, 20, WHITE);
- y += 25;
+ 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);
+ DrawText(ship_type.name.c_str(), x+10, y-10, 20.0f, GRAY);
}
}
diff --git a/kurator/src/Battle.h b/kurator/src/Battle.h
index ea41a1f..476381b 100644
--- a/kurator/src/Battle.h
+++ b/kurator/src/Battle.h
@@ -2,13 +2,10 @@
#include <memory>
-#include <raylib.h>
-
#include <kurator/battles/Battle.h>
#include "Scene.h"
#include "Session.h"
-#include "Skybox.h"
namespace kurator
@@ -24,8 +21,6 @@ public:
private:
std::shared_ptr<Session> session;
battles::Battle battle;
- Camera camera;
- Skybox skybox;
};