summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-12-04 01:00:12 +0100
committerAki <please@ignore.pl>2022-12-04 01:00:12 +0100
commit4cd1c6163a5101f21826248c2b0d4e0e804168ca (patch)
tree48aca6b16e34d54e79074211bcf7b9550afb5100
parent25776ec71cc240cc0a30dd1113ad6bf1e53ddf37 (diff)
downloadkurator-4cd1c6163a5101f21826248c2b0d4e0e804168ca.zip
kurator-4cd1c6163a5101f21826248c2b0d4e0e804168ca.tar.gz
kurator-4cd1c6163a5101f21826248c2b0d4e0e804168ca.tar.bz2
Implemented naive laser effect
-rw-r--r--kurator/src/Battle.cpp27
-rw-r--r--kurator/src/components.h8
-rw-r--r--sim/src/BaseBattle.cpp2
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<Line>();
+ 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<sim::HitPoints, sim::Team>();
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<sim::Transform>(hit.victim);
- registry.emplace<Timed>(entity, 1.2);
- registry.emplace<CenteredText>(entity, text, MeasureText(text.c_str(), 10), 10, RED);
- registry.emplace<sim::Transform>(entity, transform.position, 0.0);
- registry.emplace<UIOffset>(entity, 0, 0);
- registry.emplace<PopMove>(entity, sim::Point{0.0, -20}, 0.9998);
+ const auto& source = registry.get<sim::Transform>(hit.source);
+ const auto& victim = registry.get<sim::Transform>(hit.victim);
+ const auto popup = registry.create();
+ registry.emplace<Timed>(popup, 1.2);
+ registry.emplace<CenteredText>(popup, text, MeasureText(text.c_str(), 10), 10, RED);
+ registry.emplace<sim::Transform>(popup, victim.position, 0.0);
+ registry.emplace<UIOffset>(popup, 0, 0);
+ registry.emplace<PopMove>(popup, sim::Point{0.0, -20}, 0.9998);
+ const auto line = registry.create();
+ registry.emplace<Timed>(line, 0.2);
+ registry.emplace<Line>(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;
}