From 4cd1c6163a5101f21826248c2b0d4e0e804168ca Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 4 Dec 2022 01:00:12 +0100 Subject: Implemented naive laser effect --- kurator/src/Battle.cpp | 27 ++++++++++++++++++++------- kurator/src/components.h | 8 ++++++++ sim/src/BaseBattle.cpp | 2 +- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 9d6d6c5..8c35969 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -89,6 +89,15 @@ Battle::draw() const const int y = height/2 + transform.position.y*scale - text.font_size/2 + offset.y; DrawText(text.text.c_str(), x, y, text.font_size, text.color); } + auto lines = registry.view(); + for (const auto& [entity, line] : lines.each()) { + DrawLine( + width/2 + line.start.x*scale, + height/2 + line.start.y*scale, + width/2 + line.end.x*scale, + height/2 + line.end.y*scale, + line.color); + } auto points = registry.view(); double totals[2] {0.0, 0.0}; // FIXME and extract for (const auto& [entity, points, team] : points.each()) { @@ -110,14 +119,18 @@ Battle::receive(const sim::Hit& hit) auto& registry = battle->registry(); if (!registry.valid(hit.victim)) return; - const auto entity = registry.create(); const std::string text = TextFormat("%.1f", hit.damage); - const auto& transform = registry.get(hit.victim); - registry.emplace(entity, 1.2); - registry.emplace(entity, text, MeasureText(text.c_str(), 10), 10, RED); - registry.emplace(entity, transform.position, 0.0); - registry.emplace(entity, 0, 0); - registry.emplace(entity, sim::Point{0.0, -20}, 0.9998); + const auto& source = registry.get(hit.source); + const auto& victim = registry.get(hit.victim); + const auto popup = registry.create(); + registry.emplace(popup, 1.2); + registry.emplace(popup, text, MeasureText(text.c_str(), 10), 10, RED); + registry.emplace(popup, victim.position, 0.0); + registry.emplace(popup, 0, 0); + registry.emplace(popup, sim::Point{0.0, -20}, 0.9998); + const auto line = registry.create(); + registry.emplace(line, 0.2); + registry.emplace(line, RED, source.position, victim.position); } diff --git a/kurator/src/components.h b/kurator/src/components.h index 0b39ac0..5c4a32d 100644 --- a/kurator/src/components.h +++ b/kurator/src/components.h @@ -46,4 +46,12 @@ struct Marker }; +struct Line +{ + Color color; + sim::Point start; + sim::Point end; +}; + + } // namespace kurator diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index fc12b9c..9587ca7 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -139,7 +139,7 @@ BaseBattle::turrets(const float dt) const auto damage = effective_damage(def, distance.magnitude()); if (damage > 0.0) { target_points.health -= damage; - _dispatcher.trigger(Hit{damage, entity, state.target}); + _dispatcher.trigger(Hit{damage, control.owner, state.target}); } control.reload = def.rate_of_fire; } -- cgit v1.1