Tiles
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "map.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
map_t MAP;
|
||||
|
||||
@@ -126,16 +127,13 @@ void mapChunkLoad(chunk_t* chunk) {
|
||||
);
|
||||
memoryZero(chunk->tiles, sizeof(tile_t) * CHUNK_TILE_COUNT);
|
||||
|
||||
uint8_t x, y, z;
|
||||
x = 1;
|
||||
y = 2;
|
||||
z = 0;
|
||||
|
||||
chunk->tiles[
|
||||
(z * CHUNK_WIDTH * CHUNK_HEIGHT) +
|
||||
(y * CHUNK_WIDTH) +
|
||||
x
|
||||
] = (tile_t){ .id = 1 };
|
||||
// 3x3 test walkable area
|
||||
for(int y = 0; y <= 3; y++) {
|
||||
for(int x = 0; x <= 3; x++) {
|
||||
chunktileindex_t tileIndex = (y * CHUNK_WIDTH) + x;
|
||||
chunk->tiles[tileIndex] = TILE_WALKABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
chunkindex_t mapGetChunkIndexAt(const chunkpos_t position) {
|
||||
@@ -160,4 +158,16 @@ chunkindex_t mapGetChunkIndexAt(const chunkpos_t position) {
|
||||
chunk_t* mapGetChunk(const uint8_t index) {
|
||||
if(index >= MAP_CHUNK_COUNT) return NULL;
|
||||
return &MAP.chunks[index];
|
||||
}
|
||||
|
||||
tile_t mapGetTile(const worldpos_t position) {
|
||||
chunkpos_t chunkPos;
|
||||
worldPosToChunkPos(&position, &chunkPos);
|
||||
chunkindex_t chunkIndex = mapGetChunkIndexAt(chunkPos);
|
||||
if(chunkIndex == -1) return TILE_NULL;
|
||||
|
||||
chunk_t *chunk = mapGetChunk(chunkIndex);
|
||||
assertNotNull(chunk, "Chunk pointer cannot be NULL");
|
||||
chunktileindex_t tileIndex = woprldPosToChunkTileIndex(&position);
|
||||
return chunk->tiles[tileIndex];
|
||||
}
|
||||
Reference in New Issue
Block a user