diff --git a/js/world.js b/js/world.js index e561fa0..fd1e886 100644 --- a/js/world.js +++ b/js/world.js @@ -33,11 +33,29 @@ function getOrCreateChunk(chunkX, chunkY) { // Create a new chunk with empty pixels const chunkData = new Array(CHUNK_SIZE * CHUNK_SIZE).fill(EMPTY); - // Fill chunk at y = 1 completely with stone instead of y = -1 + // Fill chunk at y = 1 with stone, but create a noisy transition at the top if (chunkY === 1) { + // Use the chunk position as part of the seed for consistent generation + const seed = chunkX * 10000; + const random = createSeededRandom(seed); + for (let y = 0; y < CHUNK_SIZE; y++) { for (let x = 0; x < CHUNK_SIZE; x++) { - chunkData[y * CHUNK_SIZE + x] = STONE; + // Create a noisy transition at the top of the stone layer + if (y < 10) { // Only apply noise to the top 10 rows + // More noise at the top, less as we go down + const noiseThreshold = y / 10; // 0 at the top, 1 at row 10 + + if (random() > noiseThreshold) { + chunkData[y * CHUNK_SIZE + x] = STONE; + } else { + // Randomly choose between sand and empty space + chunkData[y * CHUNK_SIZE + x] = random() < 0.7 ? SAND : EMPTY; + } + } else { + // Below the transition zone, it's all stone + chunkData[y * CHUNK_SIZE + x] = STONE; + } } } }