Make stairs work

This commit is contained in:
2025-11-11 22:12:08 -06:00
parent 4f8f6a47cb
commit 9f23533069
10 changed files with 103 additions and 48 deletions

View File

@@ -76,20 +76,43 @@ void entityWalk(entity_t *entity, const entitydir_t direction) {
}
// Get tile under foot
tile_t tile = mapGetTile(newPos);
if(tile == TILE_NULL && newPos.z > 0) {
// Check one level down for walkable tile (stairs down)
tile_t tileCurrent = mapGetTile(entity->position);
tile_t tileNew = mapGetTile(newPos);
bool_t fall = false;
bool_t raise = false;
// Are we walking up stairs?
if(
tileIsStairs(tileCurrent) &&
(direction+TILE_STAIRS_SOUTH) == tileCurrent &&
newPos.z < (MAP_CHUNK_DEPTH - 1)
) {
tileNew = TILE_NULL;// Force check for stairs above.
worldpos_t abovePos = newPos;
abovePos.z += 1;
tile_t tileAbove = mapGetTile(abovePos);
if(tileAbove != TILE_NULL && tileIsWalkable(tileAbove)) {
// We can go up the stairs.
raise = true;
}
} else if(tileNew == TILE_NULL && newPos.z > 0) {
// Falling down?
worldpos_t belowPos = newPos;
belowPos.z -= 1;
tile_t belowTile = mapGetTile(belowPos);
if(belowTile == TILE_STAIRS_UP) {
tile = TILE_STAIRS_DOWN;// Mark current as stairs down
tile_t tileBelow = mapGetTile(belowPos);
if(
tileBelow != TILE_NULL &&
tileIsStairs(tileBelow) &&
(entityDirGetOpposite(direction)+TILE_STAIRS_SOUTH) == tileBelow
) {
// We will fall to this tile.
fall = true;
}
}
// Tile walkable?
if(!tileIsWalkable(tile)) return;
// Can we walk here?
if(!raise && !fall && !tileIsWalkable(tileNew)) return;// Blocked
// Entity in way?
entity_t *other = ENTITIES;
@@ -105,13 +128,10 @@ void entityWalk(entity_t *entity, const entitydir_t direction) {
entity->animation = ENTITY_ANIM_WALK;
entity->animTime = ENTITY_ANIM_WALK_DURATION;// TODO: Running vs walking
// We are comitting, we can run effects here.
if(tile == TILE_STAIRS_DOWN) {
// Moving down a level
entity->position.z -= 1;
} else if(tile == TILE_STAIRS_UP) {
// Moving up a level
if(raise) {
entity->position.z += 1;
} else if(fall) {
entity->position.z -= 1;
}
}