This commit is contained in:
2025-11-03 19:50:23 -06:00
parent f3d985ecbc
commit d4a2e059d7
16 changed files with 329 additions and 220 deletions

View File

@@ -46,8 +46,66 @@ void entityUpdate(entity_t *entity) {
assertTrue(entity->type < ENTITY_TYPE_COUNT, "Invalid entity type");
assertTrue(entity->type != ENTITY_TYPE_NULL, "Cannot have NULL entity type");
// What state is the entity in?
if(entity->animation != ENTITY_ANIM_IDLE) {
// Entity is mid animation, tick it (down).
entity->animFrame--;
if(entity->animFrame == 0) entity->animation = ENTITY_ANIM_IDLE;
return;
}
// Movement code.
if(entity->type == ENTITY_TYPE_PLAYER) {
playerMovement(entity);
}
}
void entityTurn(entity_t *entity, const entitydir_t direction) {
entity->direction = direction;
entity->animation = ENTITY_ANIM_TURN;
entity->animFrame = ENTITY_ANIM_TURN_DURATION;
}
void entityWalk(entity_t *entity, const entitydir_t direction) {
// TODO: Animation, delay, etc.
entity->direction = direction;
// Where are we moving?
uint8_t newX, newY;
newX = entity->position.x;
newY = entity->position.y;
{
int8_t relX, relY;
entityDirGetRelative(direction, &relX, &relY);
newX += relX;
newY += relY;
}
// TODO: Tile in way?
// TODO: Map bounds in way?
// Entity in way?
// entity_t *start = GAME.overworld.map.entities;
// entity_t *end = start + MAP_ENTITY_COUNT;
// while(start < end) {
// if(
// start == entity ||
// entity->type == ENTITY_TYPE_NULL ||
// start->position.x != newX ||
// start->position.y != newY
// ) {
// start++;
// continue;
// }
// return;// Blocked
// }
// Move.
entity->position.x = newX;
entity->position.y = newY;
entity->animation = ENTITY_ANIM_WALK;
entity->animFrame = ENTITY_ANIM_WALK_DURATION;// TODO: Running vs walking
}