diff --git a/game/diggingFunctions.js b/game/diggingFunctions.js index ec07770..4be021c 100644 --- a/game/diggingFunctions.js +++ b/game/diggingFunctions.js @@ -81,6 +81,62 @@ function playerDig(x,y, amount){ } } +function clearDirtAroundPlayer() { + if (Date.now() - lastDirtClearTime < DIRT_CLEAR_COOLDOWN) return; + lastDirtClearTime = Date.now(); + const px = Math.floor(player.pos.x); + const py = Math.floor(player.pos.y) - 1; // Check below player + + // Calculate chunk coordinates + const cx = Math.floor(px / CHUNKSIZE); + const cy = Math.floor(py / CHUNKSIZE); + const chunkKey = `${cx},${cy}`; + + // Only proceed if chunk exists + if (!testMap.chunks[chunkKey]) return; + + // Calculate local position within chunk + const lx = px % CHUNKSIZE; + const ly = py % CHUNKSIZE; + + // Clear 3x3 area (adjust radius as needed) + for (let dx = -1; dx <= 1; dx++) { + for (let dy = -1; dy <= 1; dy++) { + const checkX = lx + dx; + const checkY = ly + dy; + + // Skip if out of bounds + if (checkX < 0 || checkX >= CHUNKSIZE || checkY < 0 || checkY >= CHUNKSIZE) continue; + + const index = checkX + (checkY * CHUNKSIZE); + + // After setting block to air: + if (typeof spawnParticle === 'function') { + spawnParticle({ + x: px + dx, + y: py + dy, + texture: 'dirt_particle.png', + lifetime: 1.0 + }); + } + + // Check if block is dirt (assuming 1 = dirt) + if (testMap.chunks[chunkKey].data[index] === 1) { + // Update locally + testMap.chunks[chunkKey].data[index] = 0; + + // Sync with server + socket.emit("update_node", { + chunkPos: chunkKey, + index: index, + val: 0, + amt: 1 // Full removal + }); + } + } + } +} + function dig(x, y, amt, playerDiging, rayStart) { x = floor(x / TILESIZE); y = floor(y / TILESIZE); diff --git a/game/input.js b/game/input.js index 2b2daa1..431048f 100644 --- a/game/input.js +++ b/game/input.js @@ -428,6 +428,22 @@ function blurActiveElement() { } } +function handleMovement(dx, dy) { + // Existing movement logic + player.pos.x += dx * moveSpeed; + player.pos.y += dy * moveSpeed; + + // Clear dirt after moving + clearDirtAroundPlayer(); + + // Sync position with server + socket.emit('update_pos', { + id: curPlayer.id, + pos: player.pos, + holding: curPlayer.holding + }); +} + function mouseReleased(){ if(gameState == "chating"){ diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..c277c8c --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "Holes_Client", + "lockfileVersion": 3, + "requires": true, + "packages": {} +}