summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--battles/include/kurator/battles/components.h2
-rw-r--r--battles/src/Battle.cpp9
-rw-r--r--battles/src/RandomSpawner.cpp8
-rw-r--r--kurator/src/Battle.cpp2
4 files changed, 15 insertions, 6 deletions
diff --git a/battles/include/kurator/battles/components.h b/battles/include/kurator/battles/components.h
index 03b93a2..307acc3 100644
--- a/battles/include/kurator/battles/components.h
+++ b/battles/include/kurator/battles/components.h
@@ -14,7 +14,7 @@ namespace battles
struct Transform
{
Point position;
- Point rotation;
+ double angle;
entt::entity reference_frame = entt::null;
};
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 <kurator/battles/Battle.h>
+#include <cmath>
#include <memory>
#include <random>
@@ -56,9 +57,11 @@ BaseBattle::registry()
void
BaseBattle::update(const float dt)
{
- auto view = _registry.view<Transform, Team>();
- for (auto&& [entity, transform, team] : view.each())
- transform.position.x += 0.1 * dt * (team.id * 2 - 1);
+ auto view = _registry.view<Transform>();
+ 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};
}
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index 7320c19..f78675c 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -1,6 +1,7 @@
#include "Battle.h"
#include <algorithm>
+#include <cmath>
#include <memory>
#include <utility>
@@ -49,6 +50,7 @@ Battle::draw() const
const int x = width/2 + transform.position.x*scale;
const int y = height/2 + transform.position.y*scale;
DrawCircle(x, y, 5, color);
+ DrawLine(x, y, x + 6 * std::cos(transform.angle), y + 6 * std::sin(transform.angle), WHITE);
DrawText(ship_type.name.c_str(), x+10, y-10, 20.0f, GRAY);
}
}