diff --git a/js/world.js b/js/world.js index 23c76c6..cbd1c64 100644 --- a/js/world.js +++ b/js/world.js @@ -447,3 +447,25 @@ function getVisibleChunks() { return visibleChunks; } + +function generateChunksAroundPlayer() { + const centerChunkX = Math.floor(worldOffsetX / CHUNK_SIZE); + const centerChunkY = Math.floor(worldOffsetY / CHUNK_SIZE); + const radius = 3; // Generate chunks within 3 chunks of the player + + // Always generate the stone layer at y = 1 instead of below the floor + for (let dx = -radius; dx <= radius; dx++) { + const chunkX = centerChunkX + dx; + const chunkY = 1; // The chunk at y = 1 (moved from y = -1) + getOrCreateChunk(chunkX, chunkY); + } + + // Generate chunks in a square around the player + for (let dy = -radius; dy <= radius; dy++) { + for (let dx = -radius; dx <= radius; dx++) { + const chunkX = centerChunkX + dx; + const chunkY = centerChunkY + dy; + getOrCreateChunk(chunkX, chunkY); + } + } +}