summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-20 15:27:31 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-20 15:27:31 +0100
commit5dbee173b961792b42596cb792a50624555cc41b (patch)
tree2e6d82e2c3fefd13584730aecd42a3d3fc14f105 /src
parent81156d180847bf9ba502a25e546723f234d0e2c9 (diff)
src, senery, serialize: implement z offset
Diffstat (limited to 'src')
-rw-r--r--src/anim.hpp1
-rw-r--r--src/entity.cpp6
-rw-r--r--src/entity.hpp4
3 files changed, 6 insertions, 5 deletions
diff --git a/src/anim.hpp b/src/anim.hpp
index fe455128..4b7b6bc8 100644
--- a/src/anim.hpp
+++ b/src/anim.hpp
@@ -26,6 +26,7 @@ struct anim_group final
std::vector<anim_frame> frames;
Vector2ui ground; // for use in anim-crop-tool only
Vector3b offset;
+ Vector2b z_offset;
};
enum class anim_scale_type : unsigned char { invalid, ratio, fixed, };
diff --git a/src/entity.cpp b/src/entity.cpp
index 971b532d..1b54117d 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -48,15 +48,15 @@ entity::~entity() noexcept
float entity::ordinal() const
{
- return ordinal(coord.local(), offset);
+ return ordinal(coord.local(), offset, atlas->group(r).z_offset);
}
-float entity::ordinal(local_coords xy, Vector2b offset) const
+float entity::ordinal(local_coords xy, Vector2b offset, Vector2b z_offset) const
{
constexpr auto inv_tile_size = 1.f/TILE_SIZE2;
constexpr float width = TILE_MAX_DIM+1;
auto offset_ = ordinal_offset(offset);
- auto vec = Vector2(xy) + offset_*inv_tile_size;
+ auto vec = Vector2(xy) + offset_*inv_tile_size + Vector2(z_offset)*inv_tile_size;
return vec[1]*width + vec[0];
}
diff --git a/src/entity.hpp b/src/entity.hpp
index 75e06ba8..f2f6c65b 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -54,7 +54,7 @@ struct entity
virtual Vector2 ordinal_offset(Vector2b offset) const = 0;
float ordinal() const;
- float ordinal(local_coords xy, Vector2b offset) const;
+ float ordinal(local_coords xy, Vector2b offset, Vector2b z_offset) const;
struct chunk& chunk() const;
size_t index() const;
@@ -75,7 +75,7 @@ struct entity
bool is_dynamic() const;
bool can_rotate(rotation new_r);
bool can_move_to(Vector2i delta);
- [[nodiscard]] size_t move_to(size_t i, Vector2i delta, rotation new_r);
+ size_t move_to(size_t i, Vector2i delta, rotation new_r);
protected:
entity(object_id id, struct chunk& c, const entity_proto& proto);