feat: Set default world position to 0,0 and extend floor to 2 chunks deep
This commit is contained in:
parent
5ef436498f
commit
9cdf7eba78
11
script.js
11
script.js
@ -46,7 +46,7 @@ let currentMouseX, currentMouseY;
|
||||
let lastFrameTime = 0;
|
||||
let fps = 0;
|
||||
let worldOffsetX = 0;
|
||||
let worldOffsetY = CHUNK_SIZE; // Start at Chunk: 0,-1
|
||||
let worldOffsetY = 0; // Start at Chunk: 0,0
|
||||
let worldOffsetXBeforeDrag = 0;
|
||||
let worldOffsetYBeforeDrag = 0;
|
||||
let chunks = new Map(); // Map to store chunks with key "x,y"
|
||||
@ -307,8 +307,8 @@ function getOrCreateChunk(chunkX, chunkY) {
|
||||
// Create a new chunk with empty pixels
|
||||
const chunkData = new Array(CHUNK_SIZE * CHUNK_SIZE).fill(EMPTY);
|
||||
|
||||
// Add floor at the bottom of the world (y = 0)
|
||||
if (chunkY === 0) {
|
||||
// Add floor at the bottom of the world (y = 0 and y = 1)
|
||||
if (chunkY === 0 || chunkY === 1) {
|
||||
// Fill the bottom row with walls
|
||||
for (let x = 0; x < CHUNK_SIZE; x++) {
|
||||
chunkData[(CHUNK_SIZE - 1) * CHUNK_SIZE + x] = WALL;
|
||||
@ -339,8 +339,9 @@ function setPixel(worldX, worldY, type) {
|
||||
}
|
||||
|
||||
function getPixel(worldX, worldY) {
|
||||
// Special case: floor at the bottom of the world
|
||||
if (worldY === CHUNK_SIZE - 1 && Math.floor(worldY / CHUNK_SIZE) === 0) {
|
||||
// Special case: floor at the bottom of the world (first two chunks)
|
||||
const chunkY = Math.floor(worldY / CHUNK_SIZE);
|
||||
if (worldY % CHUNK_SIZE === CHUNK_SIZE - 1 && (chunkY === 0 || chunkY === 1)) {
|
||||
return WALL;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user