#include #include #include #include #include #include #include namespace kurator { namespace battles { class BaseBattle : public Battle { public: BaseBattle(const Scenario& scenario); entt::registry& registry() override; void update(float dt) override; private: entt::registry _registry; }; BaseBattle::BaseBattle(const Scenario& scenario) { std::random_device dev; std::uniform_real_distribution<> pos{-2.5, 2.5}; for (const auto& ship : scenario.ships) { const auto entity = _registry.create(); _registry.emplace(entity, ship.type); _registry.emplace(entity, ship.team); _registry.emplace(entity, Point{pos(dev), pos(dev)}, Point{0.0, 0.0}); } } entt::registry& BaseBattle::registry() { return _registry; } void BaseBattle::update(const float dt) { auto view = _registry.view(); for (auto&& [entity, transform, team] : view.each()) transform.position.x += 0.1 * dt * (team.id * 2 - 1); } std::unique_ptr prepare(const Scenario& scenario) { return std::make_unique(scenario); } } // namespace battles } // namespace kurator