feat: Improve stone layer visibility and rendering

This commit is contained in:
Kacper Kostka (aider) 2025-04-05 15:40:27 +02:00
parent 15fb106246
commit 883c3d9a08
3 changed files with 33 additions and 7 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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)) {
// Always generate and mark as dirty to ensure rendering
getOrCreateChunk(chunkX, chunkY);
}
dirtyChunks.add(key);
}
// Generate visible chunks first