feat: Implement player block breaking with 10-pixel range and inventory collection

This commit is contained in:
Kacper Kostka (aider)
2025-04-05 19:12:11 +02:00
parent d765defa9d
commit 80c243ebf8
3 changed files with 80 additions and 35 deletions

View File

@@ -18,7 +18,7 @@ window.addEventListener('keydown', (e) => {
e.preventDefault();
}
// Start breaking blocks with E key
// Start breaking blocks with E key or left mouse button
if (e.code === 'KeyE' && player) {
player.startBreaking();
}
@@ -106,9 +106,15 @@ function handleMouseDown(e) {
worldOffsetXBeforeDrag = worldOffsetX;
worldOffsetYBeforeDrag = worldOffsetY;
} else {
// Left mouse button for drawing
isDrawing = true;
draw(x, y);
// Left mouse button for drawing or breaking blocks
if (player) {
// If player exists, start breaking blocks
player.startBreaking();
} else {
// Otherwise use normal drawing
isDrawing = true;
draw(x, y);
}
}
}
@@ -149,6 +155,11 @@ function handleMouseUp(e) {
}
}
isDragging = false;
// Stop breaking blocks if player exists
if (player) {
player.stopBreaking();
}
}
function draw(x, y) {