From 0e57ea98049658b4d82488c43d71b4ced534c2af Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 12 Nov 2022 13:43:54 +0100 Subject: Extracted basic implementation of concrete Battle --- battles/src/Battle.cpp | 66 +------------------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) (limited to 'battles/src/Battle.cpp') diff --git a/battles/src/Battle.cpp b/battles/src/Battle.cpp index 7040dd0..f44a88e 100644 --- a/battles/src/Battle.cpp +++ b/battles/src/Battle.cpp @@ -1,16 +1,10 @@ #include -#include #include -#include -#include - -#include #include -#include -#include "RandomSpawner.h" +#include "BaseBattle.h" namespace kurator @@ -19,52 +13,6 @@ namespace battles { -int total_teams_in(const Scenario& scenario); - - -class BaseBattle : public Battle -{ -public: - BaseBattle(const Scenario& scenario); - entt::registry& registry() override; - void update(float dt) override; -private: - entt::registry _registry; - RandomSpawner spawner; -}; - - -BaseBattle::BaseBattle(const Scenario& scenario) : - _registry {}, - spawner {total_teams_in(scenario), 2.5, 0.1} -{ - for (const auto& ship : scenario.ships) { - const auto entity = _registry.create(); - _registry.emplace(entity, ship.type); - _registry.emplace(entity, ship.team); - _registry.emplace(entity, spawner.get(ship.team)); - } -} - - -entt::registry& -BaseBattle::registry() -{ - return _registry; -} - - -void -BaseBattle::update(const float dt) -{ - auto view = _registry.view(); - for (auto&& [entity, transform] : view.each()) { - transform.position.x += 0.1 * dt * std::cos(transform.angle); - transform.position.y += 0.1 * dt * std::sin(transform.angle); - } -} - - std::unique_ptr prepare(const Scenario& scenario) { @@ -72,17 +20,5 @@ prepare(const Scenario& scenario) } -int -total_teams_in(const Scenario& scenario) -{ - int last_team = 0; - for (const auto& ship : scenario.ships) { - if (ship.team > last_team) - last_team = ship.team; - } - return last_team + 1; -} - - } // namespace battles } // namespace kurator -- cgit v1.1