summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-01-15 17:20:10 +0100
committerAki <please@ignore.pl>2023-01-15 17:20:10 +0100
commit6ebd267bcf026343c354fb107fb03ba800eb9aca (patch)
tree26f2f1064f14871f17ba3d2de93e5180ffaf45fa
parenta36ebd9b053f80e0dae1a5b50e0914d6518a01d2 (diff)
downloadkurator-6ebd267bcf026343c354fb107fb03ba800eb9aca.zip
kurator-6ebd267bcf026343c354fb107fb03ba800eb9aca.tar.gz
kurator-6ebd267bcf026343c354fb107fb03ba800eb9aca.tar.bz2
Implemented naive on-death markers
-rw-r--r--kurator/src/Battle.cpp42
-rw-r--r--kurator/src/Battle.h3
-rw-r--r--kurator/src/components.h9
-rw-r--r--sim/include/kurator/sim/events.h6
-rw-r--r--sim/src/BaseBattle.cpp1
5 files changed, 60 insertions, 1 deletions
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index 3d0ac72..d7232ff 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -44,6 +44,7 @@ Battle::Battle(std::shared_ptr<Session> _session, campaign::Scenario scenario, B
{
battle->dispatcher().sink<sim::End>().connect<&Battle::on_end>(*this);
battle->dispatcher().sink<sim::Hit>().connect<&Battle::on_hit>(*this);
+ battle->dispatcher().sink<sim::Destroyed>().connect<&Battle::on_destroyed>(*this);
battle->dispatcher().sink<stats::ShipLeft>().connect<&Battle::on_ship_left>(*this);
auto& registry = battle->registry();
auto ships = registry.view<sim::Team, universe::ShipType, universe::UniqueIdentifier>();
@@ -58,6 +59,7 @@ Battle::~Battle()
{
battle->dispatcher().sink<sim::End>().disconnect(*this);
battle->dispatcher().sink<sim::Hit>().disconnect(*this);
+ battle->dispatcher().sink<sim::Destroyed>().disconnect(*this);
battle->dispatcher().sink<stats::ShipLeft>().disconnect(*this);
}
@@ -84,6 +86,13 @@ Battle::update(const float dt)
pop.speed.x -= damp.x;
pop.speed.y -= damp.y;
}
+ auto crosses = registry.view<Cross>();
+ for (auto&& [entity, cross] : crosses.each()) {
+ cross.timer += dt;
+ const auto dphase = cross.phase * 2;
+ if (cross.timer > dphase)
+ cross.timer -= dphase;
+ }
auto lines = registry.view<Line>();
for (auto&& [entity, line] : lines.each())
line.position += (1.0 + line.hlength) / line.duration * dt * time_factor;
@@ -115,6 +124,25 @@ Battle::draw() const
const int hheight = GetScreenHeight() / 2;
const double scale = std::min(hwidth/15000.0, hheight/15000.0);
auto& registry = battle->registry();
+ auto crosses = registry.view<sim::Transform, Cross>();
+ for (const auto& [entity, transform, cross] : crosses.each()) {
+ if (cross.timer > cross.phase)
+ continue;
+ const int x = hwidth + transform.position.x*scale;
+ const int y = hheight + transform.position.y*scale;
+ DrawLine(
+ x - cross.hlength,
+ y - cross.hlength,
+ x + cross.hlength,
+ y + cross.hlength,
+ cross.color);
+ DrawLine(
+ x + cross.hlength,
+ y - cross.hlength,
+ x - cross.hlength,
+ y + cross.hlength,
+ cross.color);
+ }
auto lines = registry.view<Line>();
for (const auto& [entity, line] : lines.each()) {
const auto diff = line.end - line.start;
@@ -189,6 +217,20 @@ Battle::on_hit(const sim::Hit& hit)
void
+Battle::on_destroyed(const sim::Destroyed& event)
+{
+ auto& registry = battle->registry();
+ if (!registry.valid(event.victim))
+ return;
+ const auto& victim = registry.get<sim::Transform>(event.victim);
+ const auto cross = registry.create();
+ registry.emplace<Timed>(cross, 1.6);
+ registry.emplace<Cross>(cross, 0.2, 6.0);
+ registry.emplace<sim::Transform>(cross, victim.position, 0.0);
+}
+
+
+void
Battle::on_ship_left(const stats::ShipLeft& event)
{
log.push_back(event);
diff --git a/kurator/src/Battle.h b/kurator/src/Battle.h
index 500318a..7a48e21 100644
--- a/kurator/src/Battle.h
+++ b/kurator/src/Battle.h
@@ -29,7 +29,8 @@ public:
void draw() const override;
void on_end(const sim::End& end);
void on_hit(const sim::Hit& hit);
- void on_ship_left(const stats::ShipLeft& event);
+ void on_destroyed(const sim::Destroyed& event);
+ void on_ship_left(const stats::ShipLeft& event); // duplicated?
private:
std::shared_ptr<Session> session;
std::unique_ptr<sim::Battle> battle;
diff --git a/kurator/src/components.h b/kurator/src/components.h
index 7d0239f..bcd34e6 100644
--- a/kurator/src/components.h
+++ b/kurator/src/components.h
@@ -58,4 +58,13 @@ struct Line
};
+struct Cross
+{
+ double phase;
+ double hlength;
+ Color color = GRAY;
+ double timer = 0.0;
+};
+
+
} // namespace kurator
diff --git a/sim/include/kurator/sim/events.h b/sim/include/kurator/sim/events.h
index 71ce098..87cd430 100644
--- a/sim/include/kurator/sim/events.h
+++ b/sim/include/kurator/sim/events.h
@@ -22,5 +22,11 @@ struct End
};
+struct Destroyed
+{
+ entt::entity victim;
+};
+
+
} // namespace sim
} // namespace kurator
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp
index 5173892..99a0199 100644
--- a/sim/src/BaseBattle.cpp
+++ b/sim/src/BaseBattle.cpp
@@ -105,6 +105,7 @@ BaseBattle::kill_off_dead()
if (_registry.all_of<universe::UniqueIdentifier, Team>(entity)) {
const auto& [identifier, team] = _registry.get<universe::UniqueIdentifier, Team>(entity);
_dispatcher.trigger(stats::ShipLeft{time, identifier, team.id, true});
+ _dispatcher.trigger(Destroyed{entity});
}
_registry.destroy(entity);
}