diff options
Diffstat (limited to 'battles/src')
-rw-r--r-- | battles/src/BaseBattle.cpp | 22 | ||||
-rw-r--r-- | battles/src/Builder.cpp | 2 |
2 files changed, 15 insertions, 9 deletions
diff --git a/battles/src/BaseBattle.cpp b/battles/src/BaseBattle.cpp index 98af764..e102d79 100644 --- a/battles/src/BaseBattle.cpp +++ b/battles/src/BaseBattle.cpp @@ -87,14 +87,20 @@ void BaseBattle::floating_movement(const float dt) { auto view = _registry.view<Transform, FloatingMovement, AIState>(); - for (auto&& [entity, self, movement, ai] : view.each()) { - const double speed = movement.speed * dt; - const Point offset = ai.destination - self.position; - if (offset.magnitude() > speed) { - const Point move = offset.normalized().scale(speed); - self.position.x += move.x; - self.position.y += move.y; - } + for (auto&& [entity, transform, movement, ai] : view.each()) { + const auto offset = ai.destination - transform.position; + const auto at_destination = offset.magnitude() > movement.destination_boundary; + const auto acceleration = + at_destination ? + offset.normalized().scale(movement.acceleration * dt) : + offset.normalized().scale(-1 * movement.deceleration * dt); + movement.speed.x += acceleration.x; + movement.speed.y += acceleration.y; + if (movement.speed.magnitude() > movement.max_speed) + movement.speed = movement.speed.normalized().scale(movement.max_speed); + const auto speed = movement.speed.scale(dt); + transform.position.x += speed.x; + transform.position.y += speed.y; } } diff --git a/battles/src/Builder.cpp b/battles/src/Builder.cpp index 228e893..4ead634 100644 --- a/battles/src/Builder.cpp +++ b/battles/src/Builder.cpp @@ -30,7 +30,7 @@ Builder::operator()(const universe::ShipType& ship_type, const int team) const registry.emplace<universe::ShipType>(entity, ship_type); registry.emplace<Team>(entity, team); registry.emplace<Transform>(entity, spawner.get(team)); - registry.emplace<FloatingMovement>(entity, 0.4); + registry.emplace<FloatingMovement>(entity, 0.5, 2.0, 3.0, 0.1); registry.emplace<AIState>(entity, Point{0.0, 0.0}); registry.emplace<HitPoints>(entity, ship_type.base_health_points); return entity; |