This commit is contained in:
2025-11-09 22:17:26 -06:00
parent 8977d50992
commit 3eb24da475
4 changed files with 38 additions and 27 deletions

View File

@@ -67,34 +67,36 @@ void entityWalk(entity_t *entity, const entitydir_t direction) {
entity->direction = direction;
// Where are we moving?
worldunit_t newX, newY;
newX = entity->position.x;
newY = entity->position.y;
worldpos_t newPos = entity->position;
{
worldunits_t relX, relY;
entityDirGetRelative(direction, &relX, &relY);
newX += relX;
newY += relY;
newPos.x += relX;
newPos.y += relY;
}
// TODO: Tile in way?
// TODO: Map bounds in way?
chunkpos_t chunkPos;
worldPosToChunkPos(&newPos, &chunkPos);
chunkindex_t chunkIndex = mapGetChunkIndexAt(chunkPos);
if(chunkIndex != -1) {
chunk_t *chunk = mapGetChunkByIndex((uint8_t)chunkIndex);
assertNotbNull(chunk, "Chunk pointer cannot be NULL");
chunkGetTile
} else {
return;// Out of bounds
}
// Entity in way?
entity_t *other = ENTITIES;
do {
if(other == entity) continue;
if(other->type == ENTITY_TYPE_NULL) continue;
if(other->position.x != newX) continue;
if(other->position.y != newY) continue;
if(other->position.z != entity->position.z) continue;
if(!worldPosIsEqual(other->position, newPos)) continue;
return;// Blocked
} while(++other, other < &ENTITIES[ENTITY_COUNT]);
// Move.
entity->position.x = newX;
entity->position.y = newY;
entity->position = newPos;
entity->animation = ENTITY_ANIM_WALK;
entity->animTime = ENTITY_ANIM_WALK_DURATION;// TODO: Running vs walking
}