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/src/BaseBattle.cpp | 7 +++++++ battles/src/scenarios.cpp | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'battles/src') 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