diff options
author | Aki <please@ignore.pl> | 2022-11-19 13:26:42 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-11-19 13:26:42 +0100 |
commit | 98982513f97f449fd200132d0f19130ab31e2c36 (patch) | |
tree | b562871c32a3c26fab6a23bb3f915a769f5f9258 /battles/src | |
parent | 45eee2571917b6ff48f237d9796696148cd6086c (diff) | |
download | kurator-98982513f97f449fd200132d0f19130ab31e2c36.zip kurator-98982513f97f449fd200132d0f19130ab31e2c36.tar.gz kurator-98982513f97f449fd200132d0f19130ab31e2c36.tar.bz2 |
Implemented funky floating movement
It's far from complete but it's hilarious and deserves to be a commit
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; |