From 84e0e1e45f908f93d0a6a60632e0ff177addfb77 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 23 Dec 2022 22:01:34 +0100 Subject: Shots are now animated to see what direction they go --- kurator/src/Battle.cpp | 24 +++++++++++++++++++----- kurator/src/components.h | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 8ecd571..d5390ae 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -72,6 +72,9 @@ Battle::update(const float dt) pop.speed.x -= damp.x; pop.speed.y -= damp.y; } + auto lines = registry.view(); + for (auto&& [entity, line] : lines.each()) + line.position += 1.0 / line.duration * dt * time_factor; balance.update(registry); ImGui::SetNextWindowPos({GetScreenWidth()/2.0f, GetScreenHeight()-100.0f}, ImGuiCond_Once, {0.5f, 0.5f}); ImGui::SetNextWindowSize({240.0f, 0.0f}, ImGuiCond_Once); @@ -99,11 +102,16 @@ Battle::draw() const auto& registry = battle->registry(); auto lines = registry.view(); for (const auto& [entity, line] : lines.each()) { + const auto diff = line.end - line.start; + const auto fstart = line.position - line.hlength; + const auto fend = line.position + line.hlength; + const auto start = line.start + diff.scale(fstart > 0.0 ? fstart : 0.0); + const auto end = line.start + diff.scale(fend > 1.0 ? 1.0 : fend); DrawLine( - hwidth + line.start.x*scale, - hheight + line.start.y*scale, - hwidth + line.end.x*scale, - hheight + line.end.y*scale, + hwidth + start.x*scale, + hheight + start.y*scale, + hwidth + end.x*scale, + hheight + end.y*scale, line.color); } auto view = registry.view(); @@ -146,7 +154,13 @@ Battle::on_hit(const sim::Hit& hit) registry.emplace(popup, sim::Point{0.0, -20}, 0.9998); const auto line = registry.create(); registry.emplace(line, 0.2, true); - registry.emplace(line, RED, source.position, victim.position); + registry.emplace( + line, + RED, + source.position, + victim.position, + 1000.0 / (victim.position - source.position).magnitude(), + 0.2); } diff --git a/kurator/src/components.h b/kurator/src/components.h index 0da3d6b..7d0239f 100644 --- a/kurator/src/components.h +++ b/kurator/src/components.h @@ -52,6 +52,9 @@ struct Line Color color; sim::Point start; sim::Point end; + double hlength; + double duration; + double position = 0.0; }; -- cgit v1.1