summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-11-20 14:33:43 +0100
committerAki <please@ignore.pl>2022-11-20 14:33:43 +0100
commit6204aa1afe8d6906f31e79840f4593872bf412f4 (patch)
tree67473de658d697a4bbc674f8c2eded0bc0f9fb92
parentfe3bdfd21253c2a9295e70ba6005a53f4fec7b73 (diff)
downloadkurator-6204aa1afe8d6906f31e79840f4593872bf412f4.zip
kurator-6204aa1afe8d6906f31e79840f4593872bf412f4.tar.gz
kurator-6204aa1afe8d6906f31e79840f4593872bf412f4.tar.bz2
Extracted markers to a component
-rw-r--r--kurator/CMakeLists.txt2
-rw-r--r--kurator/src/Battle.cpp15
-rw-r--r--kurator/src/components.h10
3 files changed, 20 insertions, 7 deletions
diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt
index dffd368..c85cfdc 100644
--- a/kurator/CMakeLists.txt
+++ b/kurator/CMakeLists.txt
@@ -10,6 +10,6 @@ add_executable(
)
target_link_libraries(
${PROJECT_NAME}
- PRIVATE raylib
PRIVATE battles
+ PRIVATE raylib
)
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index bee8932..9a92180 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -28,6 +28,10 @@ Battle::Battle(std::shared_ptr<Session> _session) :
battle {battles::prepare(battles::scenarios::example())}
{
battle->dispatcher().sink<battles::Hit>().connect<&Battle::receive>(*this);
+ auto& registry = battle->registry();
+ auto ships = registry.view<battles::Team, universe::ShipType>();
+ for (const auto& [entity, team, type] : ships.each())
+ registry.emplace<Marker>(entity, 5.0, team.id ? GREEN : RED, type.name);
}
@@ -70,14 +74,13 @@ Battle::draw() const
const int height = GetScreenHeight();
const double scale = std::min(width/10.0, height/10.0);
auto& registry = battle->registry();
- auto view = registry.view<const universe::ShipType, const battles::Team, const battles::Transform>();
- for (auto [entity, ship_type, team, transform] : view.each()) {
- const auto color = team.id == 1 ? RED : GREEN;
+ auto view = registry.view<const Marker, const battles::Transform>();
+ for (auto [entity, marker, transform] : view.each()) {
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);
+ DrawCircle(x, y, marker.radius, marker.color);
+ DrawLine(x, y, x + marker.radius*std::cos(transform.angle), y + marker.radius*std::sin(transform.angle), WHITE);
+ DrawText(marker.name.c_str(), x+10, y-10, 20.0f, GRAY);
}
auto pops = registry.view<CenteredText, battles::Transform>();
for (const auto& [entity, text, transform] : pops.each()) {
diff --git a/kurator/src/components.h b/kurator/src/components.h
index 655db2f..7d54ea5 100644
--- a/kurator/src/components.h
+++ b/kurator/src/components.h
@@ -1,5 +1,7 @@
#pragma once
+#include <string>
+
#include <raylib.h>
#include <kurator/battles/Point.h>
@@ -31,4 +33,12 @@ struct PopMove
};
+struct Marker
+{
+ double radius;
+ Color color;
+ std::string name;
+};
+
+
} // namespace kurator