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