feat: Add generateChunksAroundPlayer function to world.js
This commit is contained in:
parent
b85ae017b8
commit
7aa0c1785b
22
js/world.js
22
js/world.js
@ -447,3 +447,25 @@ function getVisibleChunks() {
|
|||||||
|
|
||||||
return visibleChunks;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user