Prepping map stuff

This commit is contained in:
2025-11-11 12:25:46 -06:00
parent 26bfb912f1
commit 5adf8a0773
16 changed files with 249 additions and 175 deletions

View File

@@ -81,9 +81,11 @@ void entityWalk(entity_t *entity, const entitydir_t direction) {
// Check one level down for walkable tile (stairs down)
worldpos_t belowPos = newPos;
belowPos.z -= 1;
tile = mapGetTile(belowPos);
if(tile != TILE_NULL) newPos.z -= 1;
tile_t belowTile = mapGetTile(belowPos);
if(belowTile == TILE_STAIRS_UP) {
tile = TILE_STAIRS_DOWN;// Mark current as stairs down
}
}
// Tile walkable?
@@ -98,11 +100,19 @@ void entityWalk(entity_t *entity, const entitydir_t direction) {
return;// Blocked
} while(++other, other < &ENTITIES[ENTITY_COUNT]);
entity->lastPosition = entity->position;
entity->position = newPos;
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
entity->position.z += 1;
}
}
entity_t * entityGetAt(const worldpos_t position) {

View File

@@ -23,6 +23,7 @@ typedef struct entity_s {
// Movement
entitydir_t direction;
worldpos_t position;
worldpos_t lastPosition;
entityanim_t animation;
float_t animTime;

View File

@@ -128,12 +128,25 @@ void mapChunkLoad(chunk_t* chunk) {
memoryZero(chunk->tiles, sizeof(tile_t) * CHUNK_TILE_COUNT);
// 3x3 test walkable area
for(int y = 0; y <= 3; y++) {
for(int x = 0; x <= 3; x++) {
chunktileindex_t x, y, z;
z = 0;
for(y = 0; y <= 3; y++) {
for(x = 0; x <= 3; x++) {
chunktileindex_t tileIndex = (y * CHUNK_WIDTH) + x;
chunk->tiles[tileIndex] = TILE_WALKABLE;
}
}
x = 3, y = 3;
chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_STAIRS_UP;
// x = 3, y = 2, z = 1;
// chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_WALKABLE;
// x = 2, y = 2, z = 1;
// chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_WALKABLE;
// x = 4, y = 2, z = 1;
// chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_WALKABLE;
}
chunkindex_t mapGetChunkIndexAt(const chunkpos_t position) {

View File

@@ -8,5 +8,9 @@
#include "tile.h"
bool_t tileIsWalkable(const tile_t tile) {
return tile == TILE_WALKABLE;
return (
tile == TILE_WALKABLE ||
tile == TILE_STAIRS_UP ||
tile == TILE_STAIRS_DOWN
);
}

View File

@@ -13,6 +13,8 @@ typedef uint8_t tile_t;
#define TILE_NULL 0
#define TILE_WALKABLE 1
#define TILE_STAIRS_UP 2
#define TILE_STAIRS_DOWN 3
/**
* Returns whether or not the given tile is walkable.

View File

@@ -21,7 +21,7 @@
typedef int16_t worldunit_t;
typedef int16_t chunkunit_t;
typedef int16_t chunkindex_t;
typedef uint8_t chunktileindex_t;
typedef uint32_t chunktileindex_t;
typedef int32_t worldunits_t;
typedef int32_t chunkunits_t;