summaryrefslogtreecommitdiff
path: root/src/World
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-10-23 01:16:10 +0200
committerMel <einebeere@gmail.com>2022-10-23 01:16:10 +0200
commit589bfb5cad0052856077ce867f3858ca3741d95d (patch)
tree424d9e11474e27e04222330eea7c64e9d67220bb /src/World
parent403ba87eaf2f6554bc0a83efed7ff78d66dd59a8 (diff)
downloadmeowcraft-589bfb5cad0052856077ce867f3858ca3741d95d.tar.zst
meowcraft-589bfb5cad0052856077ce867f3858ca3741d95d.zip
Noisy world generation with broken chunk borders
Diffstat (limited to 'src/World')
-rw-r--r--src/World/Chunk.hpp2
-rw-r--r--src/World/Generator.cpp28
2 files changed, 20 insertions, 10 deletions
diff --git a/src/World/Chunk.hpp b/src/World/Chunk.hpp
index 797a757..4c7810d 100644
--- a/src/World/Chunk.hpp
+++ b/src/World/Chunk.hpp
@@ -8,7 +8,7 @@
#include "../GFX/Binder.hpp"
#define CHUNK_WIDTH 16
-#define CHUNK_HEIGHT 32
+#define CHUNK_HEIGHT 64
namespace MC::World {
diff --git a/src/World/Generator.cpp b/src/World/Generator.cpp
index 757abf2..ee7ece9 100644
--- a/src/World/Generator.cpp
+++ b/src/World/Generator.cpp
@@ -1,20 +1,30 @@
#include "Generator.hpp"
+#include "../Math/Noise.hpp"
namespace MC::World {
Chunk Generator::generate(int64_t chunk_x, int64_t chunk_y) {
Chunk chunk(chunk_x, chunk_y);
- for (int y = 0; y < CHUNK_HEIGHT; y++) {
- BlockType type = BlockType::Air;
- if (y < CHUNK_HEIGHT / 2) {
- type = BlockType::Dirt;
- } else if (y == CHUNK_HEIGHT / 2) {
- type = BlockType::Grass;
- }
+ uint8_t extent = 60;
+ uint8_t base = 4;
+
+ for (int x = 0; x < CHUNK_WIDTH; x++) {
+ for (int z = 0; z < CHUNK_WIDTH; z++) {
+ float noise = Math::noise2d(
+ {(float)chunk_x * CHUNK_WIDTH + x, (float)chunk_y * CHUNK_WIDTH + z}
+ ) * extent + base;
+
+ uint height = std::round(noise);
+
+ for (int y = 0; y < CHUNK_HEIGHT; y++) {
+ BlockType type = BlockType::Air;
+ if (y < height) {
+ type = BlockType::Dirt;
+ } else if (y == height) {
+ type = BlockType::Grass;
+ }
- for (int x = 0; x < CHUNK_WIDTH; x++) {
- for (int z = 0; z < CHUNK_WIDTH; z++) {
chunk.set(x, y, z, type);
}
}