diff options
| author | 0undefined <oscar@nelin.dk> | 2025-03-27 15:11:20 +0000 |
|---|---|---|
| committer | 0undefined <oscar@nelin.dk> | 2025-04-09 09:42:38 +0000 |
| commit | ccc93530fe9f1578e2bf98071631db3459ba6bb0 (patch) | |
| tree | 8b9e7ed55dee221c40df971df6371da90bc58c85 /state_mainstate/src/worldgen.c | |
| parent | 0651aeb8f2c5d02a5dc23ac0254721c2a9609161 (diff) | |
Add some worldgen
Diffstat (limited to 'state_mainstate/src/worldgen.c')
| -rw-r--r-- | state_mainstate/src/worldgen.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/state_mainstate/src/worldgen.c b/state_mainstate/src/worldgen.c new file mode 100644 index 0000000..0155fc6 --- /dev/null +++ b/state_mainstate/src/worldgen.c @@ -0,0 +1,43 @@ +#include <stdlib.h> + +#include <worldgen.h> + +void gen_terrain(u8 *world, usize height, usize length, usize width) { + if (world == NULL) { + world = calloc(width * length * height, sizeof(u8)); + } + + // y: height + // z: depth/length + // x: width + + // This is pretty cache unfriendly + for (usize y = 0; y < height / 2; y++) { + for (usize z = 0; z < length; z++) { + for (usize x = 0; x < width; x++) { + world[y * width * length + + z * width + + x] = BLOCK_grass; + } + } + } + + for (usize y = 0; y < 4; y++) { + for (usize z = 0; z < 8; z++) { + for (usize x = 0; x < 8; x++) { + if (z > 0 && z < 7 && x > 0 && x < 7) continue; + world[((height / 2 + 1) + y) * width * length + + (z + (length / 2 - 4)) * width + + (x + (width / 2 - 4))] = BLOCK_rock; + } + } + } + + // Doorway + world[(height / 2 + 1) * width * length + + (length / 2) * width + + (width / 2 - 4)] = BLOCK_none; + world[((height / 2 + 1) + 1) * width * length + + (length / 2) * width + + (width / 2 - 4)] = BLOCK_none; +} |
