|
|
|
@ -69,7 +69,8 @@
|
|
|
|
const stopAction = document.querySelector("#stopAction");
|
|
|
|
const stopAction = document.querySelector("#stopAction");
|
|
|
|
const endAction = document.querySelector("#endAction");
|
|
|
|
const endAction = document.querySelector("#endAction");
|
|
|
|
const fireAction = document.querySelector("#fireAction");
|
|
|
|
const fireAction = document.querySelector("#fireAction");
|
|
|
|
const touchButtons = [...document.querySelectorAll("[data-control]")];
|
|
|
|
const moveStick = document.querySelector("#moveStick");
|
|
|
|
|
|
|
|
const moveKnob = document.querySelector("#moveKnob");
|
|
|
|
|
|
|
|
|
|
|
|
const WIDTH = canvas.width;
|
|
|
|
const WIDTH = canvas.width;
|
|
|
|
const HEIGHT = canvas.height;
|
|
|
|
const HEIGHT = canvas.height;
|
|
|
|
@ -619,21 +620,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
if (isPlayer) {
|
|
|
|
if (isPlayer) {
|
|
|
|
if (health > 66) {
|
|
|
|
if (health > 66) {
|
|
|
|
glowColor = "rgba(132, 238, 212, 0.75)";
|
|
|
|
glowColor = "rgba(132, 238, 212, 0.55)";
|
|
|
|
glowBlur = 12;
|
|
|
|
glowBlur = 7;
|
|
|
|
outerColor = "#e8fff7";
|
|
|
|
outerColor = "#e8fff7";
|
|
|
|
innerColor = "#102822";
|
|
|
|
innerColor = "#102822";
|
|
|
|
coreColor = entity.color;
|
|
|
|
coreColor = entity.color;
|
|
|
|
} else if (health > 33) {
|
|
|
|
} else if (health > 33) {
|
|
|
|
glowColor = "rgba(240, 182, 70, 0.45)";
|
|
|
|
glowColor = "rgba(240, 182, 70, 0.45)";
|
|
|
|
glowBlur = 8;
|
|
|
|
glowBlur = 6;
|
|
|
|
outerColor = "#c8c0a0";
|
|
|
|
outerColor = "#c8c0a0";
|
|
|
|
innerColor = "#1e2818";
|
|
|
|
innerColor = "#1e2818";
|
|
|
|
coreColor = "#9a9850";
|
|
|
|
coreColor = "#9a9850";
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const pulse = 0.5 + 0.5 * Math.sin(Date.now() / 180);
|
|
|
|
const pulse = 0.5 + 0.5 * Math.sin(Date.now() / 180);
|
|
|
|
glowColor = `rgba(212, 93, 69, ${0.5 + 0.4 * pulse})`;
|
|
|
|
glowColor = `rgba(212, 93, 69, ${0.42 + 0.32 * pulse})`;
|
|
|
|
glowBlur = 10 + 6 * pulse;
|
|
|
|
glowBlur = 7 + 4 * pulse;
|
|
|
|
outerColor = "#3a2020";
|
|
|
|
outerColor = "#3a2020";
|
|
|
|
innerColor = "#1a0c0c";
|
|
|
|
innerColor = "#1a0c0c";
|
|
|
|
coreColor = "#6b2828";
|
|
|
|
coreColor = "#6b2828";
|
|
|
|
@ -766,38 +767,63 @@
|
|
|
|
keys.delete(event.key.toLowerCase());
|
|
|
|
keys.delete(event.key.toLowerCase());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function bindHoldButton(button, key) {
|
|
|
|
const stickKeys = ["arrowup", "arrowdown", "arrowleft", "arrowright"];
|
|
|
|
const press = (event) => {
|
|
|
|
let activeStickKey = null;
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
button.setPointerCapture?.(event.pointerId);
|
|
|
|
function clearStickDirection() {
|
|
|
|
keys.add(key);
|
|
|
|
if (activeStickKey) keys.delete(activeStickKey);
|
|
|
|
canvas.focus({ preventScroll: true });
|
|
|
|
activeStickKey = null;
|
|
|
|
};
|
|
|
|
if (moveKnob) moveKnob.style.transform = "translate(-50%, -50%)";
|
|
|
|
const release = (event) => {
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
keys.delete(key);
|
|
|
|
function setStickDirection(key) {
|
|
|
|
try {
|
|
|
|
if (activeStickKey === key) return;
|
|
|
|
button.releasePointerCapture?.(event.pointerId);
|
|
|
|
if (activeStickKey) keys.delete(activeStickKey);
|
|
|
|
} catch {
|
|
|
|
activeStickKey = key;
|
|
|
|
// Some browsers release capture automatically on cancel/leave.
|
|
|
|
if (key) keys.add(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
button.addEventListener("pointerdown", press);
|
|
|
|
function updateStick(event) {
|
|
|
|
button.addEventListener("pointerup", release);
|
|
|
|
if (!moveStick) return;
|
|
|
|
button.addEventListener("pointercancel", release);
|
|
|
|
event.preventDefault();
|
|
|
|
button.addEventListener("pointerleave", release);
|
|
|
|
const rect = moveStick.getBoundingClientRect();
|
|
|
|
|
|
|
|
const centerX = rect.left + rect.width / 2;
|
|
|
|
|
|
|
|
const centerY = rect.top + rect.height / 2;
|
|
|
|
|
|
|
|
const dx = event.clientX - centerX;
|
|
|
|
|
|
|
|
const dy = event.clientY - centerY;
|
|
|
|
|
|
|
|
const distance = Math.hypot(dx, dy);
|
|
|
|
|
|
|
|
const deadZone = rect.width * 0.12;
|
|
|
|
|
|
|
|
if (distance < deadZone) {
|
|
|
|
|
|
|
|
clearStickDirection();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const key = Math.abs(dx) > Math.abs(dy) ? (dx > 0 ? "arrowright" : "arrowleft") : dy > 0 ? "arrowdown" : "arrowup";
|
|
|
|
|
|
|
|
setStickDirection(key);
|
|
|
|
|
|
|
|
if (moveKnob) {
|
|
|
|
|
|
|
|
const max = rect.width * 0.24;
|
|
|
|
|
|
|
|
const scale = Math.min(max, distance) / distance;
|
|
|
|
|
|
|
|
moveKnob.style.transform = `translate(calc(-50% + ${dx * scale}px), calc(-50% + ${dy * scale}px))`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas.focus({ preventScroll: true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const touchKeyMap = {
|
|
|
|
if (moveStick) {
|
|
|
|
up: "arrowup",
|
|
|
|
moveStick.addEventListener("pointerdown", (event) => {
|
|
|
|
down: "arrowdown",
|
|
|
|
moveStick.setPointerCapture?.(event.pointerId);
|
|
|
|
left: "arrowleft",
|
|
|
|
updateStick(event);
|
|
|
|
right: "arrowright",
|
|
|
|
});
|
|
|
|
};
|
|
|
|
moveStick.addEventListener("pointermove", updateStick);
|
|
|
|
|
|
|
|
for (const type of ["pointerup", "pointercancel", "pointerleave"]) {
|
|
|
|
for (const button of touchButtons) {
|
|
|
|
moveStick.addEventListener(type, (event) => {
|
|
|
|
const key = touchKeyMap[button.dataset.control];
|
|
|
|
event.preventDefault();
|
|
|
|
if (key) bindHoldButton(button, key);
|
|
|
|
clearStickDirection();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
moveStick.releasePointerCapture?.(event.pointerId);
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
// Some browsers release capture automatically.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
primaryAction.addEventListener("click", startOrResume);
|
|
|
|
primaryAction.addEventListener("click", startOrResume);
|
|
|
|
|