From 6204aa1afe8d6906f31e79840f4593872bf412f4 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 20 Nov 2022 14:33:43 +0100 Subject: Extracted markers to a component --- kurator/CMakeLists.txt | 2 +- kurator/src/Battle.cpp | 15 +++++++++------ kurator/src/components.h | 10 ++++++++++ 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) : battle {battles::prepare(battles::scenarios::example())} { battle->dispatcher().sink().connect<&Battle::receive>(*this); + auto& registry = battle->registry(); + auto ships = registry.view(); + for (const auto& [entity, team, type] : ships.each()) + registry.emplace(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(); - for (auto [entity, ship_type, team, transform] : view.each()) { - const auto color = team.id == 1 ? RED : GREEN; + auto view = registry.view(); + 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(); 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 + #include #include @@ -31,4 +33,12 @@ struct PopMove }; +struct Marker +{ + double radius; + Color color; + std::string name; +}; + + } // namespace kurator -- cgit v1.1