diff --git a/script.js b/script.js index 8331adc..0b4a091 100644 --- a/script.js +++ b/script.js @@ -466,16 +466,29 @@ function render() { } } - // Draw cursor position in debug mode - if (debugMode) { - const rect = canvas.getBoundingClientRect(); - const mouseX = lastMouseX || 0; - const mouseY = lastMouseY || 0; - const worldX = Math.floor(mouseX / PIXEL_SIZE) + worldOffsetX; - const worldY = Math.floor(mouseY / PIXEL_SIZE) + worldOffsetY; + // Draw cursor position and update debug info + if (currentMouseX !== undefined && currentMouseY !== undefined) { + const worldX = Math.floor(currentMouseX / PIXEL_SIZE) + worldOffsetX; + const worldY = Math.floor(currentMouseY / PIXEL_SIZE) + worldOffsetY; - document.getElementById('coords').textContent = - `Chunk: ${Math.floor(worldOffsetX / CHUNK_SIZE)},${Math.floor(worldOffsetY / CHUNK_SIZE)} | ` + - `Mouse: ${worldX},${worldY} | Offset: ${Math.floor(worldOffsetX)},${Math.floor(worldOffsetY)}`; + // Update coordinates display in debug mode + if (debugMode) { + document.getElementById('coords').textContent = + `Chunk: ${Math.floor(worldOffsetX / CHUNK_SIZE)},${Math.floor(worldOffsetY / CHUNK_SIZE)} | ` + + `Mouse: ${worldX},${worldY} | Offset: ${Math.floor(worldOffsetX)},${Math.floor(worldOffsetY)}`; + + // Draw cursor outline + const cursorScreenX = (worldX - worldOffsetX) * PIXEL_SIZE; + const cursorScreenY = (worldY - worldOffsetY) * PIXEL_SIZE; + + ctx.strokeStyle = '#00ff00'; + ctx.lineWidth = 2; + ctx.strokeRect( + cursorScreenX - PIXEL_SIZE, + cursorScreenY - PIXEL_SIZE, + PIXEL_SIZE * 3, + PIXEL_SIZE * 3 + ); + } } }