diff options
Diffstat (limited to 'src/character.cpp')
-rw-r--r-- | src/character.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/character.cpp b/src/character.cpp index 110d2031..10ef4a34 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -96,26 +96,36 @@ void character::set_keys(bool L, bool R, bool U, bool D) b_D = D; } -bool character::update(size_t i, float dt) +Vector2 character::ordinal_offset(Vector2b offset) const +{ + return Vector2(offset); +} + +entity_update_status character::update(size_t i, float dt) { auto [lr, ud, new_r] = arrows_to_dir(b_L, b_R, b_U, b_D); if (!lr & !ud) { delta = 0; - return false; + return entity_update_status::not_updated; } int nframes = allocate_frame_time(dt); - rotate(i, new_r); - - if (!nframes) - return false; + if (nframes == 0) + { + if (r == new_r) [[unlikely]] + return entity_update_status::not_updated; + rotate(i, new_r); + return entity_update_status::updated; + } const auto vec = move_vec(lr, ud); c->ensure_passability(); + entity_update_status ret = entity_update_status::updated; + for (int k = 0; k < nframes; k++) { constexpr auto frac = Vector2(32767); @@ -123,12 +133,22 @@ bool character::update(size_t i, float dt) auto offset_ = vec + Vector2(offset_frac) * inv_frac; offset_frac = Vector2s(Vector2(std::fmod(offset_[0], 1.f), std::fmod(offset_[1], 1.f)) * frac); auto off_i = Vector2i(offset_); + const auto old_i = i; if (can_move_to(off_i)) + { i = move_to(i, off_i, new_r); + if (i != old_i) + { + //Debug{} << "move_to repositioned" << i; + ret = entity_update_status::updated_repositioned; + } + } + else + break; ++frame %= atlas->info().nframes; } //Debug{} << "pos" << Vector2i(pos.local()); - return true; + return ret; } entity_type character::type() const noexcept { return entity_type::character; } |