#pragma once #include "coordinates.hpp" struct actor_t { enum direction { up, down, left, right, }; world_t world; enum direction facing; bool moving; uint8_t frame; constexpr inline offset_t offset() { switch (facing) { case left: return {-frame, 0}; case right: return {frame, 0}; case up: return {0, -frame}; case down: return {0, frame}; default: return {0, 0}; } } // call tick() before move() constexpr inline void tick() { if (!moving) return; if (++frame == 16) { moving = false; frame = 0; switch (facing) { case left: world.x--; break; case right: world.x++; break; case up: world.y--; break; case down: world.y++; break; } } } constexpr inline void move(enum direction dir) { /* m 1 . 2 . 3 . 4 . | - | - | - | - | */ if (moving) return; frame = 0; facing = dir; moving = true; } };