gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
html css js minecraft freeway generator pos debug drag
- User
html css js minecraft freeway generator pos debug drag
- Assistant
html css js minecraft freeway generator pos debug drag
Got it! You want a web-based Minecraft freeway generator with position debugging and drag functionality using HTML, CSS, and JavaScript.
Here’s a simple interactive example that lets you generate a Minecraft-style freeway layout, drag it around, and show debug info about the positions of the blocks.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Minecraft Freeway Generator</title>
<style>
body {
margin: 0;
background: #87ceeb; /* sky */
font-family: monospace, monospace;
user-select: none;
overflow: hidden;
}
#container {
position: relative;
width: 100vw;
height: 100vh;
cursor: grab;
overflow: visible;
}
#freeway {
position: absolute;
top: 50%;
left: 50%;
display: flex;
transform: translate(-50%, -50%);
}
.block {
width: 40px;
height: 20px;
background: linear-gradient(45deg, #555 25%, #333 75%);
border: 2px solid #666;
margin-right: 4px;
position: relative;
box-sizing: border-box;
cursor: default;
}
.block:hover .pos {
display: block;
}
.pos {
position: absolute;
top: -24px;
left: 50%;
transform: translateX(-50%);
background: rgba(0,0,0,0.7);
color: white;
font-size: 10px;
padding: 2px 4px;
border-radius: 3px;
display: none;
pointer-events: none;
white-space: nowrap;
}
#debugPanel {
position: absolute;
bottom: 10px;
left: 10px;
max-height: 150px;
overflow-y: auto;
background: rgba(0,0,0,0.6);
color: #ddd;
font-size: 12px;
padding: 10px;
border-radius: 6px;
width: 300px;
box-sizing: border-box;
}
button {
margin: 10px;
font-size: 14px;
padding: 6px 12px;
}
</style>
</head>
<body>
<div id="container">
<div id="freeway"></div>
</div>
<div>
<button id="generateBtn">Generate Freeway</button>
<label for="lengthInput">Length:</label>
<input type="number" id="lengthInput" value="12" min="1" max="50" />
</div>
<div id="debugPanel">
<strong>Block Positions (relative to container):</strong>
<pre id="debugInfo"></pre>
</div>
<script>
const container = document.getElementById('container');
const freeway = document.getElementById('freeway');
const debugInfo = document.getElementById('debugInfo');
const generateBtn = document.getElementById('generateBtn');
const lengthInput = document.getElementById('lengthInput');
let isDragging = false,
dragStartX, dragStartY,
initialLeft = 0, initialTop = 0;
// Initialize freeway position
let posX = window.innerWidth / 2;
let posY = window.innerHeight / 2;
setFreewayPosition(posX, posY);
function setFreewayPosition(x, y) {
posX = x;
posY = y;
freeway.style.left = x + 'px';
freeway.style.top = y + 'px';
}
function generateFreeway(length) {
freeway.innerHTML = '';
for(let i = 0; i < length; i++) {
const block = document.createElement('div');
block.className = 'block';
// Position info span
const posSpan = document.createElement('div');
posSpan.className = 'pos';
// Position relative to freeway container (block index and pixel)
posSpan.textContent = `Block ${i}\nX:${i * (40 + 4)} Y:0`;
block.appendChild(posSpan);
freeway.appendChild(block);
}
updateDebug();
}
function updateDebug() {
// Get blocks and log their positions relative to container
const blocks = freeway.querySelectorAll('.block');
const containerRect = container.getBoundingClientRect();
let info = '';
blocks.forEach((block,i) => {
const rect = block.getBoundingClientRect();
const x = Math.floor(rect.left - containerRect.left);
const y = Math.floor(rect.top - containerRect.top);
info += `Block ${i}: x=${x}, y=${y}\n`;
// Also update the posSpan text in case of movement
const posSpan = block.querySelector('.pos');
posSpan.textContent = `Block ${i}\nX:${x} Y:${y}`;
});
debugInfo.textContent = info;
}
// Drag handlers
container.addEventListener('mousedown', e => {
if(e.target === generateBtn || e.target === lengthInput) return;
isDragging = true;
dragStartX = e.clientX;
dragStartY = e.clientY;
// get current freeway position (numbers)
const rect = freeway.getBoundingClientRect();
initialLeft = rect.left;
initialTop = rect.top;
container.style.cursor = 'grabbing';
});
window.addEventListener('mouseup', e => {
if(isDragging) {
isDragging = false;
container.style.cursor = 'grab';
updateDebug();
}
});
window.addEventListener('mousemove', e => {
if(!isDragging) return;
let dx = e.clientX - dragStartX;
let dy = e.clientY - dragStartY;
setFreewayPosition(initialLeft + dx, initialTop + dy);
updateDebug();
});
// Generate on button click
generateBtn.addEventListener('click', () => {
let length = parseInt(lengthInput.value);
if(isNaN(length) || length < 1) length = 1;
if(length > 50) length = 50;
generateFreeway(length);
});
// Initial generate
generateFreeway(parseInt(lengthInput.value));
</script>
</body>
</html>
Let me know if you want to add vertical freeways, intersections, or textures!
Not yet included in a published release.