feat: Implement player block breaking with 10-pixel range and inventory collection
This commit is contained in:
19
js/input.js
19
js/input.js
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user