From 53d45e11743909b8816ef95f50ac1c2b6467a3b7 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 11 Nov 2022 17:20:11 +0100 Subject: Changed rotation to be represented by angle --- battles/src/Battle.cpp | 9 ++++++--- battles/src/RandomSpawner.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'battles/src') diff --git a/battles/src/Battle.cpp b/battles/src/Battle.cpp index a28cdc6..7040dd0 100644 --- a/battles/src/Battle.cpp +++ b/battles/src/Battle.cpp @@ -1,5 +1,6 @@ #include +#include #include #include @@ -56,9 +57,11 @@ BaseBattle::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); + 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); + } } diff --git a/battles/src/RandomSpawner.cpp b/battles/src/RandomSpawner.cpp index a81a18c..b85d140 100644 --- a/battles/src/RandomSpawner.cpp +++ b/battles/src/RandomSpawner.cpp @@ -25,12 +25,16 @@ Transform RandomSpawner::get(const int team) { const double distance = distribution_d(device); - const double angle = angle_step * team + distribution_a(device); + const double clean_angle = angle_step * team; + const double angle = clean_angle + distribution_a(device); + double facing = clean_angle + M_PI; + if (facing > 2 * M_PI) + facing -= 2 * M_PI; const Point position { distance * std::cos(angle), distance * std::sin(angle), }; - return {position, {}}; + return {position, facing}; } -- cgit v1.1