diff options
Diffstat (limited to 'battles')
-rw-r--r-- | battles/include/kurator/battles/components.h | 6 | ||||
-rw-r--r-- | battles/src/BaseBattle.cpp | 7 | ||||
-rw-r--r-- | battles/src/scenarios.cpp | 14 |
3 files changed, 24 insertions, 3 deletions
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<Transform>(entity, spawner.get(ship.team)); _registry.emplace<FloatingMovement>(entity, 0.4); _registry.emplace<AIState>(entity, Point{0.0, 0.0}); + _registry.emplace<HitPoints>(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<HitPoints>(); + 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, {}}, }, }; |