From 39ae4f2fd4c382f25ab98c6e98816e3e3a6f4e22 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 13 Nov 2022 16:32:57 +0100 Subject: Playing around with hit points --- battles/include/kurator/battles/components.h | 6 ++++++ battles/src/BaseBattle.cpp | 7 +++++++ battles/src/scenarios.cpp | 14 +++++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) (limited to 'battles') diff --git a/battles/include/kurator/battles/components.h b/battles/include/kurator/battles/components.h index 0c1e280..35a9251 100644 --- a/battles/include/kurator/battles/components.h +++ b/battles/include/kurator/battles/components.h @@ -38,5 +38,11 @@ struct FloatingMovement }; +struct HitPoints +{ + double health; +}; + + } // namespace battles } // namespace kurator diff --git a/battles/src/BaseBattle.cpp b/battles/src/BaseBattle.cpp index 92ab351..4d80671 100644 --- a/battles/src/BaseBattle.cpp +++ b/battles/src/BaseBattle.cpp @@ -30,6 +30,7 @@ BaseBattle::BaseBattle(const Scenario& scenario) : _registry.emplace(entity, spawner.get(ship.team)); _registry.emplace(entity, 0.4); _registry.emplace(entity, Point{0.0, 0.0}); + _registry.emplace(entity, ship.type.base_health_points); manager.add(ship.team, entity); // registry supports on construction events } } @@ -60,6 +61,12 @@ BaseBattle::update(const float dt) transform.position.y += eff.y; } } + auto view2 = _registry.view(); + for (auto&& [entity, points] : view2.each()) { + points.health -= dt; + if (points.health <= 0.0) + _registry.destroy(entity); + } manager.clear(_registry); // registry supports on destructions events } diff --git a/battles/src/scenarios.cpp b/battles/src/scenarios.cpp index ffb4f27..cf348ca 100644 --- a/battles/src/scenarios.cpp +++ b/battles/src/scenarios.cpp @@ -15,19 +15,27 @@ namespace scenarios Scenario example() { - const universe::ShipType halo {"halo", 4.0}; - const universe::ShipType cube {"cube", 10.0}; - const universe::ShipType bell {"bell", 10.0}; + const universe::ShipType halo {"halo", 6.0}; + const universe::ShipType cube {"cube", 12.0}; + const universe::ShipType bell {"bell", 20.0}; return { "example", { {0, halo, {}}, {0, halo, {}}, {0, cube, {}}, + {0, cube, {}}, + {0, cube, {}}, + {0, bell, {}}, {0, bell, {}}, + {0, bell, {}}, + {1, halo, {}}, + {1, halo, {}}, {1, bell, {}}, {1, cube, {}}, {1, cube, {}}, + {1, cube, {}}, + {1, bell, {}}, {1, bell, {}}, }, }; -- cgit v1.1