diff options
author | Aki <please@ignore.pl> | 2022-12-23 22:01:34 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-12-23 22:01:34 +0100 |
commit | 84e0e1e45f908f93d0a6a60632e0ff177addfb77 (patch) | |
tree | e7d04976a0a09306569ea5ecc302eb9108c376ec | |
parent | 07e92522ef27901eeedb00bfe797c792f903e1ab (diff) | |
download | kurator-84e0e1e45f908f93d0a6a60632e0ff177addfb77.zip kurator-84e0e1e45f908f93d0a6a60632e0ff177addfb77.tar.gz kurator-84e0e1e45f908f93d0a6a60632e0ff177addfb77.tar.bz2 |
Shots are now animated to see what direction they go
-rw-r--r-- | kurator/src/Battle.cpp | 24 | ||||
-rw-r--r-- | 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<Line>(); + 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<Line>(); 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<const Marker, const sim::Transform>(); @@ -146,7 +154,13 @@ Battle::on_hit(const sim::Hit& hit) registry.emplace<PopMove>(popup, sim::Point{0.0, -20}, 0.9998); const auto line = registry.create(); registry.emplace<Timed>(line, 0.2, true); - registry.emplace<Line>(line, RED, source.position, victim.position); + registry.emplace<Line>( + 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; }; |