idk2
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user