Update index.html
Browse files- index.html +68 -45
index.html
CHANGED
|
@@ -129,56 +129,57 @@
|
|
| 129 |
|
| 130 |
#coordinates {
|
| 131 |
position: fixed;
|
| 132 |
-
top:
|
| 133 |
-
|
|
|
|
| 134 |
background: linear-gradient(135deg, rgba(0, 0, 0, 0.85), rgba(20, 20, 40, 0.85));
|
| 135 |
color: #00ff88;
|
| 136 |
-
padding:
|
| 137 |
-
border-radius:
|
| 138 |
font-family: 'Courier New', monospace;
|
| 139 |
-
font-size:
|
| 140 |
z-index: 50;
|
| 141 |
-
max-width:
|
| 142 |
-
border:
|
| 143 |
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
|
| 144 |
}
|
| 145 |
|
| 146 |
#coordinates > div {
|
| 147 |
-
margin:
|
| 148 |
text-shadow: 0 0 5px rgba(0, 255, 136, 0.5);
|
| 149 |
}
|
| 150 |
|
| 151 |
.coord-label {
|
| 152 |
color: #00ffff;
|
| 153 |
font-weight: bold;
|
| 154 |
-
font-size:
|
| 155 |
}
|
| 156 |
|
| 157 |
.coord-input {
|
| 158 |
background: rgba(0, 30, 20, 0.9);
|
| 159 |
-
border:
|
| 160 |
color: #00ff88;
|
| 161 |
-
padding:
|
| 162 |
-
border-radius:
|
| 163 |
font-family: 'Courier New', monospace;
|
| 164 |
-
margin-top:
|
| 165 |
-
width: calc(100% -
|
| 166 |
-
font-size:
|
| 167 |
}
|
| 168 |
|
| 169 |
.spawn-btn {
|
| 170 |
background: linear-gradient(135deg, rgba(0, 180, 100, 0.8), rgba(0, 120, 80, 0.8));
|
| 171 |
-
border:
|
| 172 |
color: #fff;
|
| 173 |
-
padding:
|
| 174 |
-
border-radius:
|
| 175 |
-
margin-top:
|
| 176 |
cursor: pointer;
|
| 177 |
font-weight: bold;
|
| 178 |
width: 100%;
|
| 179 |
transition: all 0.1s ease;
|
| 180 |
user-select: none;
|
| 181 |
-
font-size:
|
| 182 |
}
|
| 183 |
|
| 184 |
.spawn-btn:active {
|
|
@@ -248,12 +249,18 @@
|
|
| 248 |
</div>
|
| 249 |
|
| 250 |
<div id="coordinates">
|
| 251 |
-
<div class="coord-label">
|
| 252 |
<div>X: <span id="coordX">0.00</span></div>
|
| 253 |
<div>Y: <span id="coordY">0.00</span></div>
|
| 254 |
<div>Z: <span id="coordZ">0.00</span></div>
|
| 255 |
-
<input type="text" class="coord-input" id="spawnInput" placeholder="
|
| 256 |
-
<button class="spawn-btn" onclick="loadSpawn()">Set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
</div>
|
| 258 |
|
| 259 |
<script type="importmap">
|
|
@@ -273,10 +280,11 @@
|
|
| 273 |
let playerPos = { x: 0, y: 1, z: 0 };
|
| 274 |
let moveForward = 0;
|
| 275 |
let turnDirection = 0;
|
| 276 |
-
let moveSpeed = 0.
|
| 277 |
-
let turnSpeed = 0.
|
| 278 |
let cameraRotation = { x: 0, y: 0 };
|
| 279 |
let spawnPoint = { x: -3.5719999999999996, y: 1, z: 0.20199999999999968 };
|
|
|
|
| 280 |
|
| 281 |
// Check orientation
|
| 282 |
function checkOrientation() {
|
|
@@ -361,15 +369,14 @@
|
|
| 361 |
function setupControls() {
|
| 362 |
const joystick = document.getElementById('joystick');
|
| 363 |
const joystickHandle = document.getElementById('joystickHandle');
|
| 364 |
-
let isJoystickActive = false;
|
| 365 |
|
| 366 |
joystick.addEventListener('touchstart', (e) => {
|
| 367 |
-
|
| 368 |
e.preventDefault();
|
| 369 |
});
|
| 370 |
|
| 371 |
joystick.addEventListener('touchmove', (e) => {
|
| 372 |
-
if (!
|
| 373 |
e.preventDefault();
|
| 374 |
const touch = e.touches[0];
|
| 375 |
const rect = joystick.getBoundingClientRect();
|
|
@@ -383,10 +390,15 @@
|
|
| 383 |
if (distance > 5) {
|
| 384 |
const angle = Math.atan2(dy, dx);
|
| 385 |
const limitedDistance = Math.min(distance, maxDistance);
|
| 386 |
-
|
| 387 |
-
|
|
|
|
|
|
|
|
|
|
| 388 |
|
|
|
|
| 389 |
moveForward = -(dy / maxDistance);
|
|
|
|
| 390 |
turnDirection = dx / maxDistance;
|
| 391 |
} else {
|
| 392 |
moveForward = 0;
|
|
@@ -395,7 +407,7 @@
|
|
| 395 |
});
|
| 396 |
|
| 397 |
joystick.addEventListener('touchend', () => {
|
| 398 |
-
|
| 399 |
joystickHandle.style.left = '50%';
|
| 400 |
joystickHandle.style.top = '50%';
|
| 401 |
moveForward = 0;
|
|
@@ -417,15 +429,22 @@
|
|
| 417 |
|
| 418 |
document.addEventListener('touchstart', (e) => {
|
| 419 |
const touch = e.touches[0];
|
| 420 |
-
|
| 421 |
-
|
|
|
|
| 422 |
const joystickRect = joystick.getBoundingClientRect();
|
| 423 |
const isTouchingJoystick = touch.clientX >= joystickRect.left &&
|
| 424 |
touch.clientX <= joystickRect.right &&
|
| 425 |
touch.clientY >= joystickRect.top &&
|
| 426 |
touch.clientY <= joystickRect.bottom;
|
| 427 |
|
| 428 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
isLooking = true;
|
| 430 |
lastLookPos = { x: touch.clientX, y: touch.clientY };
|
| 431 |
e.preventDefault();
|
|
@@ -440,8 +459,8 @@
|
|
| 440 |
const deltaX = touch.clientX - lastLookPos.x;
|
| 441 |
const deltaY = touch.clientY - lastLookPos.y;
|
| 442 |
|
| 443 |
-
cameraRotation.y -= deltaX * 0.
|
| 444 |
-
cameraRotation.x -= deltaY * 0.
|
| 445 |
cameraRotation.x = Math.max(-Math.PI / 2.5, Math.min(Math.PI / 2.5, cameraRotation.x));
|
| 446 |
|
| 447 |
lastLookPos = { x: touch.clientX, y: touch.clientY };
|
|
@@ -530,18 +549,22 @@
|
|
| 530 |
function animate() {
|
| 531 |
requestAnimationFrame(animate);
|
| 532 |
|
| 533 |
-
|
|
|
|
|
|
|
| 534 |
|
| 535 |
-
|
| 536 |
-
|
| 537 |
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
|
|
|
|
|
|
|
|
|
| 543 |
|
| 544 |
-
playerPos = checkCollisions(newPos);
|
| 545 |
playerCube.position.set(playerPos.x, playerPos.y, playerPos.z);
|
| 546 |
|
| 547 |
camera.position.set(playerPos.x, playerPos.y + 1.6, playerPos.z);
|
|
|
|
| 129 |
|
| 130 |
#coordinates {
|
| 131 |
position: fixed;
|
| 132 |
+
top: 10px;
|
| 133 |
+
right: 10px;
|
| 134 |
+
left: auto;
|
| 135 |
background: linear-gradient(135deg, rgba(0, 0, 0, 0.85), rgba(20, 20, 40, 0.85));
|
| 136 |
color: #00ff88;
|
| 137 |
+
padding: 5px 8px;
|
| 138 |
+
border-radius: 6px;
|
| 139 |
font-family: 'Courier New', monospace;
|
| 140 |
+
font-size: 9px;
|
| 141 |
z-index: 50;
|
| 142 |
+
max-width: 120px;
|
| 143 |
+
border: 1px solid rgba(0, 255, 136, 0.3);
|
| 144 |
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
|
| 145 |
}
|
| 146 |
|
| 147 |
#coordinates > div {
|
| 148 |
+
margin: 1px 0;
|
| 149 |
text-shadow: 0 0 5px rgba(0, 255, 136, 0.5);
|
| 150 |
}
|
| 151 |
|
| 152 |
.coord-label {
|
| 153 |
color: #00ffff;
|
| 154 |
font-weight: bold;
|
| 155 |
+
font-size: 10px;
|
| 156 |
}
|
| 157 |
|
| 158 |
.coord-input {
|
| 159 |
background: rgba(0, 30, 20, 0.9);
|
| 160 |
+
border: 1px solid #00ff88;
|
| 161 |
color: #00ff88;
|
| 162 |
+
padding: 4px;
|
| 163 |
+
border-radius: 3px;
|
| 164 |
font-family: 'Courier New', monospace;
|
| 165 |
+
margin-top: 4px;
|
| 166 |
+
width: calc(100% - 10px);
|
| 167 |
+
font-size: 8px;
|
| 168 |
}
|
| 169 |
|
| 170 |
.spawn-btn {
|
| 171 |
background: linear-gradient(135deg, rgba(0, 180, 100, 0.8), rgba(0, 120, 80, 0.8));
|
| 172 |
+
border: 1px solid #00ff88;
|
| 173 |
color: #fff;
|
| 174 |
+
padding: 4px;
|
| 175 |
+
border-radius: 3px;
|
| 176 |
+
margin-top: 4px;
|
| 177 |
cursor: pointer;
|
| 178 |
font-weight: bold;
|
| 179 |
width: 100%;
|
| 180 |
transition: all 0.1s ease;
|
| 181 |
user-select: none;
|
| 182 |
+
font-size: 9px;
|
| 183 |
}
|
| 184 |
|
| 185 |
.spawn-btn:active {
|
|
|
|
| 249 |
</div>
|
| 250 |
|
| 251 |
<div id="coordinates">
|
| 252 |
+
<div class="coord-label">POS</div>
|
| 253 |
<div>X: <span id="coordX">0.00</span></div>
|
| 254 |
<div>Y: <span id="coordY">0.00</span></div>
|
| 255 |
<div>Z: <span id="coordZ">0.00</span></div>
|
| 256 |
+
<input type="text" class="coord-input" id="spawnInput" placeholder="Spawn JSON">
|
| 257 |
+
<button class="spawn-btn" onclick="loadSpawn()">Set</button>
|
| 258 |
+
</div>
|
| 259 |
+
|
| 260 |
+
<div id="crosshair">
|
| 261 |
+
<div class="crosshair-line crosshair-h"></div>
|
| 262 |
+
<div class="crosshair-line crosshair-v"></div>
|
| 263 |
+
<div class="crosshair-dot"></div>
|
| 264 |
</div>
|
| 265 |
|
| 266 |
<script type="importmap">
|
|
|
|
| 280 |
let playerPos = { x: 0, y: 1, z: 0 };
|
| 281 |
let moveForward = 0;
|
| 282 |
let turnDirection = 0;
|
| 283 |
+
let moveSpeed = 0.15;
|
| 284 |
+
let turnSpeed = 0.04;
|
| 285 |
let cameraRotation = { x: 0, y: 0 };
|
| 286 |
let spawnPoint = { x: -3.5719999999999996, y: 1, z: 0.20199999999999968 };
|
| 287 |
+
let joystickActive = false;
|
| 288 |
|
| 289 |
// Check orientation
|
| 290 |
function checkOrientation() {
|
|
|
|
| 369 |
function setupControls() {
|
| 370 |
const joystick = document.getElementById('joystick');
|
| 371 |
const joystickHandle = document.getElementById('joystickHandle');
|
|
|
|
| 372 |
|
| 373 |
joystick.addEventListener('touchstart', (e) => {
|
| 374 |
+
joystickActive = true;
|
| 375 |
e.preventDefault();
|
| 376 |
});
|
| 377 |
|
| 378 |
joystick.addEventListener('touchmove', (e) => {
|
| 379 |
+
if (!joystickActive) return;
|
| 380 |
e.preventDefault();
|
| 381 |
const touch = e.touches[0];
|
| 382 |
const rect = joystick.getBoundingClientRect();
|
|
|
|
| 390 |
if (distance > 5) {
|
| 391 |
const angle = Math.atan2(dy, dx);
|
| 392 |
const limitedDistance = Math.min(distance, maxDistance);
|
| 393 |
+
const handleX = Math.cos(angle) * limitedDistance;
|
| 394 |
+
const handleY = Math.sin(angle) * limitedDistance;
|
| 395 |
+
|
| 396 |
+
joystickHandle.style.left = `calc(50% + ${handleX}px)`;
|
| 397 |
+
joystickHandle.style.top = `calc(50% + ${handleY}px)`;
|
| 398 |
|
| 399 |
+
// Up = forward (negative dy), Down = backward (positive dy)
|
| 400 |
moveForward = -(dy / maxDistance);
|
| 401 |
+
// Right = turn right (positive dx), Left = turn left (negative dx)
|
| 402 |
turnDirection = dx / maxDistance;
|
| 403 |
} else {
|
| 404 |
moveForward = 0;
|
|
|
|
| 407 |
});
|
| 408 |
|
| 409 |
joystick.addEventListener('touchend', () => {
|
| 410 |
+
joystickActive = false;
|
| 411 |
joystickHandle.style.left = '50%';
|
| 412 |
joystickHandle.style.top = '50%';
|
| 413 |
moveForward = 0;
|
|
|
|
| 429 |
|
| 430 |
document.addEventListener('touchstart', (e) => {
|
| 431 |
const touch = e.touches[0];
|
| 432 |
+
// Smaller area: 35-65% horizontal, 30-70% vertical
|
| 433 |
+
if (touch.clientX > window.innerWidth * 0.35 && touch.clientX < window.innerWidth * 0.65 &&
|
| 434 |
+
touch.clientY > window.innerHeight * 0.30 && touch.clientY < window.innerHeight * 0.70) {
|
| 435 |
const joystickRect = joystick.getBoundingClientRect();
|
| 436 |
const isTouchingJoystick = touch.clientX >= joystickRect.left &&
|
| 437 |
touch.clientX <= joystickRect.right &&
|
| 438 |
touch.clientY >= joystickRect.top &&
|
| 439 |
touch.clientY <= joystickRect.bottom;
|
| 440 |
|
| 441 |
+
const coordsRect = document.getElementById('coordinates').getBoundingClientRect();
|
| 442 |
+
const isTouchingCoords = touch.clientX >= coordsRect.left &&
|
| 443 |
+
touch.clientX <= coordsRect.right &&
|
| 444 |
+
touch.clientY >= coordsRect.top &&
|
| 445 |
+
touch.clientY <= coordsRect.bottom;
|
| 446 |
+
|
| 447 |
+
if (!isTouchingJoystick && !isTouchingCoords) {
|
| 448 |
isLooking = true;
|
| 449 |
lastLookPos = { x: touch.clientX, y: touch.clientY };
|
| 450 |
e.preventDefault();
|
|
|
|
| 459 |
const deltaX = touch.clientX - lastLookPos.x;
|
| 460 |
const deltaY = touch.clientY - lastLookPos.y;
|
| 461 |
|
| 462 |
+
cameraRotation.y -= deltaX * 0.003;
|
| 463 |
+
cameraRotation.x -= deltaY * 0.003;
|
| 464 |
cameraRotation.x = Math.max(-Math.PI / 2.5, Math.min(Math.PI / 2.5, cameraRotation.x));
|
| 465 |
|
| 466 |
lastLookPos = { x: touch.clientX, y: touch.clientY };
|
|
|
|
| 549 |
function animate() {
|
| 550 |
requestAnimationFrame(animate);
|
| 551 |
|
| 552 |
+
// Only turn and move when joystick is active
|
| 553 |
+
if (joystickActive) {
|
| 554 |
+
cameraRotation.y += turnDirection * turnSpeed;
|
| 555 |
|
| 556 |
+
const forwardX = -Math.sin(cameraRotation.y) * moveForward * moveSpeed;
|
| 557 |
+
const forwardZ = -Math.cos(cameraRotation.y) * moveForward * moveSpeed;
|
| 558 |
|
| 559 |
+
const newPos = {
|
| 560 |
+
x: playerPos.x + forwardX,
|
| 561 |
+
y: playerPos.y,
|
| 562 |
+
z: playerPos.z + forwardZ
|
| 563 |
+
};
|
| 564 |
+
|
| 565 |
+
playerPos = checkCollisions(newPos);
|
| 566 |
+
}
|
| 567 |
|
|
|
|
| 568 |
playerCube.position.set(playerPos.x, playerPos.y, playerPos.z);
|
| 569 |
|
| 570 |
camera.position.set(playerPos.x, playerPos.y + 1.6, playerPos.z);
|