summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-11-09 17:17:22 +0100
committerAki <please@ignore.pl>2022-11-09 17:17:22 +0100
commit9de52991aaec19076cc79b54e097444532b5300f (patch)
tree76cb87452c9604760d8218aa534c982c4ab847d1
parentcaa48ce5946d093daaf950751dfa1432ea5373a9 (diff)
downloadkurator-9de52991aaec19076cc79b54e097444532b5300f.zip
kurator-9de52991aaec19076cc79b54e097444532b5300f.tar.gz
kurator-9de52991aaec19076cc79b54e097444532b5300f.tar.bz2
Created naive battle setup and view into it
-rw-r--r--battles/include/kurator/battles/Point.h18
-rw-r--r--battles/include/kurator/battles/components.h29
-rw-r--r--battles/src/Battle.cpp13
-rw-r--r--kurator/CMakeLists.txt1
-rw-r--r--kurator/src/Battle.cpp29
-rw-r--r--kurator/src/Battle.h3
6 files changed, 92 insertions, 1 deletions
diff --git a/battles/include/kurator/battles/Point.h b/battles/include/kurator/battles/Point.h
new file mode 100644
index 0000000..71a6993
--- /dev/null
+++ b/battles/include/kurator/battles/Point.h
@@ -0,0 +1,18 @@
+#pragma once
+
+
+namespace kurator
+{
+namespace battles
+{
+
+
+struct Point
+{
+ double x;
+ double y;
+};
+
+
+} // namespace battles
+} // namespace kurator
diff --git a/battles/include/kurator/battles/components.h b/battles/include/kurator/battles/components.h
new file mode 100644
index 0000000..03b93a2
--- /dev/null
+++ b/battles/include/kurator/battles/components.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <entt/entity/entity.hpp>
+
+#include "Point.h"
+
+
+namespace kurator
+{
+namespace battles
+{
+
+
+struct Transform
+{
+ Point position;
+ Point rotation;
+ entt::entity reference_frame = entt::null;
+};
+
+
+struct Team
+{
+ int id;
+};
+
+
+} // namespace battles
+} // namespace kurator
diff --git a/battles/src/Battle.cpp b/battles/src/Battle.cpp
index e185a68..699b9c4 100644
--- a/battles/src/Battle.cpp
+++ b/battles/src/Battle.cpp
@@ -1,6 +1,8 @@
#include <kurator/battles/Battle.h>
+#include <kurator/battles/components.h>
#include <kurator/battles/Scenario.h>
+#include <kurator/universe/ShipType.h>
namespace kurator
@@ -9,8 +11,17 @@ namespace battles
{
-Battle::Battle(Scenario)
+Battle::Battle(Scenario scenario)
{
+ 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);
+ }
+ team++;
+ }
}
diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt
index f506621..dffd368 100644
--- a/kurator/CMakeLists.txt
+++ b/kurator/CMakeLists.txt
@@ -11,4 +11,5 @@ add_executable(
target_link_libraries(
${PROJECT_NAME}
PRIVATE raylib
+ PRIVATE battles
)
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index 109478d..63a4b4a 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -5,6 +5,11 @@
#include <raylib.h>
+#include <kurator/battles/components.h>
+#include <kurator/battles/Battle.h>
+#include <kurator/battles/Scenario.h>
+#include <kurator/universe/ShipType.h>
+
#include "Session.h"
#include "Title.h"
@@ -13,8 +18,25 @@ namespace kurator
{
+static const battles::Scenario DEFAULT {
+ {
+ {
+ {{"cube", 10.0}, {}},
+ {{"cube", 10.0}, {}},
+ {{"else", 14.0}, {}},
+ },
+ {
+ {{"cube", 10.0}, {}},
+ {{"cube", 10.0}, {}},
+ {{"otto", 15.0}, {}},
+ },
+ },
+};
+
+
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"}
{
@@ -39,6 +61,13 @@ Battle::draw() const
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()) {
+ (void) entity;
+ DrawText(TextFormat("%d %s", team.id, ship_type.name.c_str()), 10, y, 20, WHITE);
+ y += 25;
+ }
}
diff --git a/kurator/src/Battle.h b/kurator/src/Battle.h
index 333f2f3..ea41a1f 100644
--- a/kurator/src/Battle.h
+++ b/kurator/src/Battle.h
@@ -4,6 +4,8 @@
#include <raylib.h>
+#include <kurator/battles/Battle.h>
+
#include "Scene.h"
#include "Session.h"
#include "Skybox.h"
@@ -21,6 +23,7 @@ public:
void draw() const override;
private:
std::shared_ptr<Session> session;
+ battles::Battle battle;
Camera camera;
Skybox skybox;
};