summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-10 17:23:30 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-10 17:23:30 +0100
commit169662a775221a5bb227e1ce5746f7418e1e692c (patch)
tree829e911a5d78aed20ab5f20c79f00052dd354c5d
parent7f08c950c56b69026c879c4985a3e0134aed1864 (diff)
editor: put character on the right tile
-rw-r--r--editor/character.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/editor/character.cpp b/editor/character.cpp
index 27692fbf..a971434d 100644
--- a/editor/character.cpp
+++ b/editor/character.cpp
@@ -101,12 +101,23 @@ void character_wip::tick(world& w, float dt, bool L, bool R, bool U, bool D)
auto pos_1 = Vector2i(offset_ * inv_tile_size);
pos_ += pos_1;
offset_ = Vector2(std::fmod(offset_[0], TILE_SIZE2[0]), std::fmod(offset_[1], TILE_SIZE2[1]));
+ constexpr auto half_tile = TILE_SIZE2/2;
+ if (auto off = offset_[0]; std::fabs(off) > half_tile[0])
+ {
+ pos_ += Vector2i(offset_[0] < 0 ? -1 : 1, 0);
+ offset_[0] = std::copysign(TILE_SIZE[0] - std::fabs(offset_[0]), -off);
+ }
+ if (auto off = offset_[1]; std::fabs(off) > half_tile[1])
+ {
+ pos_ += Vector2i(0, offset_[1] < 0 ? -1 : 1);
+ offset_[1] = std::copysign(TILE_SIZE[1] - std::fabs(offset_[1]), -off);
+ }
auto [c, t] = w[pos_];
const auto& r = c.rtree();
auto center = Vector2(pos_.local()) * TILE_SIZE2 + offset_;
- auto half = Vector2(bbox_size)*.5f;
- auto min = center - half;
- auto max = center + half;
+ auto half_bbox = Vector2(bbox_size)*.5f;
+ auto min = center - half_bbox;
+ auto max = center + half_bbox;
bool is_blocked = false;
r->Search(min.data(), max.data(), [&](const std::uint64_t data, const auto&) {
auto cdata = std::bit_cast<collision_data>(data);
@@ -119,6 +130,7 @@ void character_wip::tick(world& w, float dt, bool L, bool R, bool U, bool D)
offset = offset_;
++frame %= walk_anim->info().nframes;
}
+ //Debug{} << "pos" << Vector2i(pos.local());
}
} // namespace floormat