From 6ebd267bcf026343c354fb107fb03ba800eb9aca Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 15 Jan 2023 17:20:10 +0100 Subject: Implemented naive on-death markers --- kurator/src/Battle.cpp | 42 ++++++++++++++++++++++++++++++++++++++++ kurator/src/Battle.h | 3 ++- kurator/src/components.h | 9 +++++++++ sim/include/kurator/sim/events.h | 6 ++++++ sim/src/BaseBattle.cpp | 1 + 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 3d0ac72..d7232ff 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -44,6 +44,7 @@ Battle::Battle(std::shared_ptr _session, campaign::Scenario scenario, B { battle->dispatcher().sink().connect<&Battle::on_end>(*this); battle->dispatcher().sink().connect<&Battle::on_hit>(*this); + battle->dispatcher().sink().connect<&Battle::on_destroyed>(*this); battle->dispatcher().sink().connect<&Battle::on_ship_left>(*this); auto& registry = battle->registry(); auto ships = registry.view(); @@ -58,6 +59,7 @@ Battle::~Battle() { battle->dispatcher().sink().disconnect(*this); battle->dispatcher().sink().disconnect(*this); + battle->dispatcher().sink().disconnect(*this); battle->dispatcher().sink().disconnect(*this); } @@ -84,6 +86,13 @@ Battle::update(const float dt) pop.speed.x -= damp.x; pop.speed.y -= damp.y; } + auto crosses = registry.view(); + for (auto&& [entity, cross] : crosses.each()) { + cross.timer += dt; + const auto dphase = cross.phase * 2; + if (cross.timer > dphase) + cross.timer -= dphase; + } auto lines = registry.view(); for (auto&& [entity, line] : lines.each()) line.position += (1.0 + line.hlength) / line.duration * dt * time_factor; @@ -115,6 +124,25 @@ Battle::draw() const const int hheight = GetScreenHeight() / 2; const double scale = std::min(hwidth/15000.0, hheight/15000.0); auto& registry = battle->registry(); + auto crosses = registry.view(); + for (const auto& [entity, transform, cross] : crosses.each()) { + if (cross.timer > cross.phase) + continue; + const int x = hwidth + transform.position.x*scale; + const int y = hheight + transform.position.y*scale; + DrawLine( + x - cross.hlength, + y - cross.hlength, + x + cross.hlength, + y + cross.hlength, + cross.color); + DrawLine( + x + cross.hlength, + y - cross.hlength, + x - cross.hlength, + y + cross.hlength, + cross.color); + } auto lines = registry.view(); for (const auto& [entity, line] : lines.each()) { const auto diff = line.end - line.start; @@ -189,6 +217,20 @@ Battle::on_hit(const sim::Hit& hit) void +Battle::on_destroyed(const sim::Destroyed& event) +{ + auto& registry = battle->registry(); + if (!registry.valid(event.victim)) + return; + const auto& victim = registry.get(event.victim); + const auto cross = registry.create(); + registry.emplace(cross, 1.6); + registry.emplace(cross, 0.2, 6.0); + registry.emplace(cross, victim.position, 0.0); +} + + +void Battle::on_ship_left(const stats::ShipLeft& event) { log.push_back(event); diff --git a/kurator/src/Battle.h b/kurator/src/Battle.h index 500318a..7a48e21 100644 --- a/kurator/src/Battle.h +++ b/kurator/src/Battle.h @@ -29,7 +29,8 @@ public: void draw() const override; void on_end(const sim::End& end); void on_hit(const sim::Hit& hit); - void on_ship_left(const stats::ShipLeft& event); + void on_destroyed(const sim::Destroyed& event); + void on_ship_left(const stats::ShipLeft& event); // duplicated? private: std::shared_ptr session; std::unique_ptr battle; diff --git a/kurator/src/components.h b/kurator/src/components.h index 7d0239f..bcd34e6 100644 --- a/kurator/src/components.h +++ b/kurator/src/components.h @@ -58,4 +58,13 @@ struct Line }; +struct Cross +{ + double phase; + double hlength; + Color color = GRAY; + double timer = 0.0; +}; + + } // namespace kurator diff --git a/sim/include/kurator/sim/events.h b/sim/include/kurator/sim/events.h index 71ce098..87cd430 100644 --- a/sim/include/kurator/sim/events.h +++ b/sim/include/kurator/sim/events.h @@ -22,5 +22,11 @@ struct End }; +struct Destroyed +{ + entt::entity victim; +}; + + } // namespace sim } // namespace kurator diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index 5173892..99a0199 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -105,6 +105,7 @@ BaseBattle::kill_off_dead() if (_registry.all_of(entity)) { const auto& [identifier, team] = _registry.get(entity); _dispatcher.trigger(stats::ShipLeft{time, identifier, team.id, true}); + _dispatcher.trigger(Destroyed{entity}); } _registry.destroy(entity); } -- cgit v1.1