]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Add mountain generation
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 12 Jul 2021 18:57:54 +0000 (20:57 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 12 Jul 2021 18:57:54 +0000 (20:57 +0200)
src/clientplayer.c
src/mapgen.c

index 98dddb4f2cbbb9676d8aeb01b9d13f40adcc38e2..5be9e008727a0ef2df37faf9a51c1c591d1d7411 100644 (file)
@@ -19,7 +19,7 @@ static void update_pos(ClientPlayer *player)
 void clientplayer_init(Client *client)
 {
        client->player.client = client;
-       client->player.pos = (v3f) {0.0f, 25.0f, 0.0f};
+       client->player.pos = (v3f) {0.0f, 150.0f, 0.0f};
        client->player.velocity = (v3f) {0.0f, 0.0f, 0.0f};
        client->player.box = (aabb3f) {{-0.3f, 0.0f, -0.3f}, {0.3f, 1.75f, 0.3f}};
        client->player.yaw = client->player.pitch = 0.0f;
index 9491e4a9c25c697889c34b879fcab9bfbd8a7ffd..dc9e98e397d4b5e8f37cdbb762b24e7e6d955ffd 100644 (file)
@@ -1,3 +1,4 @@
+#include <math.h>
 #include "mapgen.h"
 #include "perlin.h"
 
@@ -7,19 +8,32 @@ void mapgen_generate_block(MapBlock *block)
                u32 ux = x + block->pos.x * 16 + ((u32) 1 << 31);
                for (u8 z = 0; z < 16; z++) {
                        u32 uz = z + block->pos.z * 16 + ((u32) 1 << 31);
-                       s32 height = smooth2d((double) ux / 32.0f, (double) uz / 32.0f, 0, 0) * 16.0f;
+                       s32 height = smooth2d(ux / 32.0, uz / 32.0, 0, 0) * 16.0 + 100.0;
+                       bool is_mountain = false;
+
+                       double mountain_factor = pow((smooth2d(ux / 1000.0, uz / 1000.0, 0, 1) - 0.3) * 5.0, 0.8);
+
+                       if (mountain_factor > 0.0) {
+                               height = pow(height * pow(((smooth2d(ux / 50.0, uz / 50.0, 0, 2) + 1.0) * 200.0 + 100.0), mountain_factor), 1.0 / (mountain_factor + 1.0));
+                               is_mountain = true;
+                       }
+
                        for (u8 y = 0; y < 16; y++) {
-                               s32 ay = y + block->pos.y * 16;
-                               Node type;
-                               if (ay > height)
-                                       type = NODE_AIR;
-                               else if (ay == height)
-                                       type = NODE_GRASS;
-                               else if (ay >= height - 4)
-                                       type = NODE_DIRT;
-                               else
-                                       type = NODE_STONE;
-                               block->data[x][y][z] = map_node_create(type);
+                               s32 ay = block->pos.y * 16 + y;
+                               s32 diff = ay - height;
+
+                               Node node = NODE_AIR;
+
+                               if (diff < -5)
+                                       node = NODE_STONE;
+                               else if (diff < -1)
+                                       node = is_mountain ? NODE_STONE : NODE_DIRT;
+                               else if (diff < 0)
+                                       node = is_mountain ? NODE_STONE : NODE_GRASS;
+                               else if (diff < 1)
+                                       node = (is_mountain && ay > 150) ? NODE_SNOW : NODE_AIR;
+
+                               block->data[x][y][z] = map_node_create(node);
                                block->metadata[x][y][z] = list_create(&list_compare_string);
                        }
                }