From 883c3d9a087e3fb5675234f91064c488993070e9 Mon Sep 17 00:00:00 2001 From: "Kacper Kostka (aider)" Date: Sat, 5 Apr 2025 15:40:27 +0200 Subject: [PATCH] feat: Improve stone layer visibility and rendering --- js/main.js | 10 ++++++++++ js/render.js | 16 +++++++++++++++- js/world.js | 14 ++++++++------ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/js/main.js b/js/main.js index 4addd91..dad3999 100644 --- a/js/main.js +++ b/js/main.js @@ -47,6 +47,16 @@ window.onload = function() { // Initialize the first chunk and generate terrain around it getOrCreateChunk(0, 0); + + // Explicitly create and mark the stone layer as dirty + for (let dx = -5; dx <= 5; dx++) { + const chunkX = dx; + const chunkY = 1; // Stone layer + const key = getChunkKey(chunkX, chunkY); + getOrCreateChunk(chunkX, chunkY); + dirtyChunks.add(key); + } + generateChunksAroundPlayer(); // Start the simulation loop diff --git a/js/render.js b/js/render.js index 2644ab4..1b5fcc3 100644 --- a/js/render.js +++ b/js/render.js @@ -49,7 +49,21 @@ function render() { const index = y * CHUNK_SIZE + x; const type = chunk[index]; - if (type === EMPTY) continue; + // Always render stone layer even if it's not directly visible + if (type === EMPTY && chunkY !== 1) continue; + + // For the stone layer (chunkY = 1), render a faint background even for empty spaces + if (type === EMPTY && chunkY === 1) { + // Use a very faint gray for empty spaces in the stone layer + ctx.fillStyle = 'rgba(100, 100, 100, 0.2)'; + ctx.fillRect( + screenX + x * PIXEL_SIZE, + screenY + y * PIXEL_SIZE, + PIXEL_SIZE, + PIXEL_SIZE + ); + continue; + } // Set color based on type if (type === SAND) { diff --git a/js/world.js b/js/world.js index eb896a7..92a1b76 100644 --- a/js/world.js +++ b/js/world.js @@ -56,8 +56,8 @@ function getOrCreateChunk(chunkX, chunkY) { if (random() > noiseThreshold) { chunkData[y * CHUNK_SIZE + x] = SAND; } else { - // Randomly choose between stone and empty space - chunkData[y * CHUNK_SIZE + x] = random() < 0.7 ? STONE : EMPTY; + // Increase stone density to make it more visible + chunkData[y * CHUNK_SIZE + x] = random() < 0.9 ? STONE : EMPTY; } } else { // Below the transition zone, it's all stone @@ -65,6 +65,9 @@ function getOrCreateChunk(chunkX, chunkY) { } } } + + // Mark this chunk as dirty to ensure it gets rendered + dirtyChunks.add(key); } // Floor has been removed as it's no longer needed @@ -524,10 +527,9 @@ function generateChunksAroundPlayer() { const chunkY = 1; // The chunk at y = 1 (moved from y = -1) const key = getChunkKey(chunkX, chunkY); - // Prioritize visible chunks - if (visibleChunkKeys.has(key)) { - getOrCreateChunk(chunkX, chunkY); - } + // Always generate and mark as dirty to ensure rendering + getOrCreateChunk(chunkX, chunkY); + dirtyChunks.add(key); } // Generate visible chunks first