summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-28 00:49:50 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-28 00:49:50 +0100
commit28da3cfd99370694806286df363aa5fa19c49de0 (patch)
tree199683c4b2ab06dac3bc7dedcfc471975e818f8a
parent722b07a415f82a7fe56f595497ddf2ec0816f27c (diff)
fix diagonal movement offset bug
-rw-r--r--src/critter.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/critter.cpp b/src/critter.cpp
index 781d086b..a4f69362 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -196,23 +196,27 @@ void critter::update(size_t i, float dt)
auto vec = move_vecs[j];
constexpr auto frac = 65535u;
constexpr auto inv_frac = 1.f / (float)frac;
- const auto sign_vec = Vector2(Math::sign(vec.x()), Math::sign(vec.y()));
+ const auto sign_vec = Math::sign(vec);
auto offset_ = vec + Vector2(offset_frac) * sign_vec * inv_frac;
- offset_frac = Vector2us(Vector2(std::fabs(std::fmod(offset_.x(), 1.f)),
- std::fabs(std::fmod(offset_.y(), 1.f))) * frac);
auto off_i = Vector2i(offset_);
if (!off_i.isZero())
{
+ offset_frac =
+ Vector2us(Vector2(Math::abs(std::fmod(offset_.x(), 1.f)),
+ Math::abs(std::fmod(offset_.y(), 1.f))) * frac);
if (can_move_to(off_i))
{
move_to(i, off_i, new_r);
++frame %= atlas->info().nframes;
- goto done;
+ break;
}
}
+ else
+ {
+ offset_frac = Vector2us(Math::abs(Math::min({1.f,1.f}, offset_)) * frac);
+ break;
+ }
}
-done:
- (void)0;
}
}