voxelThing/source/chunkGenerator.c

26 lines
946 B
C

// chunkGenerator.c
// These functions fill a chunk with blocks and are placeholders for fancier ones.
#include "raylib.h"
#include "chunkGenerator.h"
#include "blockTypes.h"
// Fill a chunk with normalish Minecraft style flatworld terrain. A few layers of stone on the bottom, a few layers of dirt, and a layer of grass on top.
void GenerateFlatChunk(Chunk *chunk) {
for (int x = 0; x < CHUNK_SIZE_X; x++) {
for (int z = 0; z < CHUNK_SIZE_Z; z++) {
for (int y = 0; y < CHUNK_SIZE_Y; y++) {
if (y < 59) {
chunk->blocks[x][y][z].type = BLOCK_STONE;
} else if (y < 64) {
chunk->blocks[x][y][z].type = BLOCK_DIRT;
} else if (y == 64) {
chunk->blocks[x][y][z].type = BLOCK_GRASS;
} else {
chunk->blocks[x][y][z].type = BLOCK_AIR;
}
}
}
}
}