From 1584600d0ba60a430ee12b68d72e17e335888197 Mon Sep 17 00:00:00 2001 From: "Kacper Kostka (aider)" Date: Sat, 5 Apr 2025 15:00:12 +0200 Subject: [PATCH] feat: Enhance grass generation with more coverage and variety --- js/world.js | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/js/world.js b/js/world.js index a8c4aeb..e5f5472 100644 --- a/js/world.js +++ b/js/world.js @@ -111,22 +111,22 @@ function generateSpecialChunk(chunkData, chunkX, playerChunkX) { } // 3. Add grass with significantly more coverage and noise - // Increase grass probability for more coverage + // Increase grass probability for more coverage - now almost guaranteed const grassProbability = (height - baseHeight) / (hill1Height - baseHeight); - if (random() < grassProbability * 0.7 + 0.3) { // Minimum 30% chance, up to 100% + if (random() < grassProbability * 0.3 + 0.7) { // Minimum 70% chance, up to 100% // Add grass on top chunkData[(floorY - noiseHeight) * CHUNK_SIZE + x] = GRASS; - // More frequently add patches of grass on the sides - if (random() < 0.5) { // Increased from 0.3 + // Much more frequently add patches of grass on the sides + if (random() < 0.8) { // Increased from 0.5 // Add grass to the left if possible if (x > 0 && chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x-1)] === SAND) { chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x-1)] = GRASS; } } - if (random() < 0.5) { // Increased from 0.3 + if (random() < 0.8) { // Increased from 0.5 // Add grass to the right if possible if (x < CHUNK_SIZE-1 && chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x+1)] === SAND) { chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x+1)] = GRASS; @@ -134,8 +134,8 @@ function generateSpecialChunk(chunkData, chunkX, playerChunkX) { } // More frequently add grass patches below the top - if (random() < 0.3 && noiseHeight > 2) { // Increased from 0.15 - const patchDepth = Math.floor(random() * 4) + 1; // Increased max depth + if (random() < 0.6 && noiseHeight > 2) { // Increased from 0.3 + const patchDepth = Math.floor(random() * 5) + 2; // Increased max depth and minimum for (let d = 1; d <= patchDepth; d++) { if (floorY - noiseHeight + d < floorY) { chunkData[(floorY - noiseHeight + d) * CHUNK_SIZE + x] = GRASS; @@ -143,21 +143,36 @@ function generateSpecialChunk(chunkData, chunkX, playerChunkX) { } } - // Sometimes add grass clusters - if (random() < 0.2) { - // Add a small cluster of grass - for (let dy = -1; dy <= 1; dy++) { - for (let dx = -1; dx <= 1; dx++) { + // More frequently add grass clusters + if (random() < 0.5) { // Increased from 0.2 + // Add a larger cluster of grass + for (let dy = -2; dy <= 1; dy++) { // Increased vertical range + for (let dx = -2; dx <= 2; dx++) { // Increased horizontal range const nx = x + dx; const ny = floorY - noiseHeight + dy; if (nx >= 0 && nx < CHUNK_SIZE && ny >= 0 && ny < CHUNK_SIZE && - chunkData[ny * CHUNK_SIZE + nx] === SAND) { - chunkData[ny * CHUNK_SIZE + nx] = GRASS; + (chunkData[ny * CHUNK_SIZE + nx] === SAND || chunkData[ny * CHUNK_SIZE + nx] === EMPTY)) { + // Higher chance to place grass closer to center + if (Math.abs(dx) + Math.abs(dy) <= 2 || random() < 0.7) { + chunkData[ny * CHUNK_SIZE + nx] = GRASS; + } } } } } + + // Sometimes add grass "islands" on top of sand + if (random() < 0.15 && noiseHeight > 4) { + // Add a small patch of grass above the surface + const islandHeight = Math.floor(random() * 2) + 1; + for (let d = 1; d <= islandHeight; d++) { + const ny = floorY - noiseHeight - d; + if (ny >= 0) { + chunkData[ny * CHUNK_SIZE + x] = GRASS; + } + } + } } }