From ccc93530fe9f1578e2bf98071631db3459ba6bb0 Mon Sep 17 00:00:00 2001 From: 0undefined Date: Thu, 27 Mar 2025 16:11:20 +0100 Subject: Add some worldgen --- state_mainstate/src/worldgen.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 state_mainstate/src/worldgen.c (limited to 'state_mainstate/src/worldgen.c') 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 + +#include + +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; +} -- cgit v1.3