This commit is contained in:
2025-06-08 18:32:36 -05:00
parent 2309fea9f3
commit a2fd58fda7
6 changed files with 155 additions and 3 deletions

View File

@@ -39,9 +39,58 @@ void entityUpdate(entity_t *entity) {
"Entity type has no update"
);
// Handle subpixel movement
if(entity->subX < 0) {
entity->subX++;
} else if(entity->subY < 0) {
entity->subY++;
} else if(entity->subX > 0) {
entity->subX--;
} else if(entity->subY > 0) {
entity->subY--;
}
// Entity-Type handling
ENTITY_CALLBACKS[entity->type].update(entity);
}
void entityTurn(entity_t *entity, const entitydir_t dir) {
assertNotNull(entity, "Entity cannot be NULL");
assertFalse(entityIsWalking(entity), "Entity is currently walking");
entity->dir = dir;
}
void entityWalk(entity_t *entity) {
assertNotNull(entity, "Entity cannot be NULL");
assertFalse(entityIsWalking(entity), "Entity is already walking");
switch(entity->dir) {
case ENTITY_DIR_UP:
entity->y--;
entity->subY = ENTITY_MOVE_SUBPIXEL;
break;
case ENTITY_DIR_DOWN:
entity->y++;
entity->subY = -ENTITY_MOVE_SUBPIXEL;
break;
case ENTITY_DIR_LEFT:
entity->x--;
entity->subX = ENTITY_MOVE_SUBPIXEL;
break;
case ENTITY_DIR_RIGHT:
entity->x++;
entity->subX = -ENTITY_MOVE_SUBPIXEL;
break;
default:
assertUnreachable("Invalid entity direction");
}
}
bool_t entityIsWalking(const entity_t *entity) {
assertNotNull(entity, "Entity cannot be NULL");
return (entity->subX != 0 || entity->subY != 0);
}
entity_t * entityGetAt(const uint8_t x, const uint8_t y) {
entity_t *e = ENTITIES;
do {