blob: 0155fc638081d36255750fd1512ff701230e3f8f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
}
|