summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kurator/src/Battle.cpp24
-rw-r--r--kurator/src/components.h3
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;
};