Remove player + right click change rotation mirror
This commit is contained in:
@@ -97,20 +97,6 @@ main {
|
||||
background: #00FF00;
|
||||
}
|
||||
|
||||
/* ================================
|
||||
CURSOR PLAYER
|
||||
================================ */
|
||||
|
||||
.player-cursor {
|
||||
outline: 2px solid #00e5ff;
|
||||
outline-offset: -2px;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.player-cursor.mirror {
|
||||
outline-color: #FFD700;
|
||||
}
|
||||
|
||||
/* ================================
|
||||
LIGHT LASER
|
||||
================================ */
|
||||
|
||||
@@ -28,10 +28,6 @@ let level1 = [
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
]
|
||||
|
||||
// Player position
|
||||
let playerX = 0;
|
||||
let playerY = 0;
|
||||
|
||||
// Function to save initial orientation of mirrors
|
||||
let laserDirection = { dx: 0, dy: 0 };
|
||||
let laserSegments = {};
|
||||
@@ -76,13 +72,18 @@ function loadGrid() {
|
||||
break;
|
||||
case legend.mirror:
|
||||
const currentAngle = mirrorOrientations[`${y},${x}`] || 0;
|
||||
cell.onclick = () => {
|
||||
rotateMirror(x, y);
|
||||
}
|
||||
const btnMirror = document.createElement("button");
|
||||
btnMirror.classList.add("btn-mirror");
|
||||
btnMirror.type = "button";
|
||||
btnMirror.style.transform = `rotate(${currentAngle}deg)`;
|
||||
btnMirror.style.width = "100%";
|
||||
btnMirror.onmousedown = (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
rotateMirror(x, y, e.button === 2);
|
||||
};
|
||||
btnMirror.oncontextmenu = (e) => e.preventDefault();
|
||||
|
||||
cell.appendChild(btnMirror);
|
||||
cell.classList.add("mirror");
|
||||
break;
|
||||
@@ -112,10 +113,6 @@ function loadGrid() {
|
||||
break;
|
||||
}
|
||||
|
||||
if (x === playerX && y === playerY) {
|
||||
cell.classList.add("player-cursor");
|
||||
}
|
||||
|
||||
lign.appendChild(cell);
|
||||
}
|
||||
|
||||
@@ -127,18 +124,20 @@ loadGrid();
|
||||
|
||||
// Function to rotate mirror
|
||||
|
||||
function rotateMirror(x, y) {
|
||||
function rotateMirror(x, y, isRightClick) {
|
||||
const coordKey = `${y},${x}`;
|
||||
|
||||
// See if it's a mirror
|
||||
if (level1[y][x] !== legend.mirror) {
|
||||
return
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
let currentAngle = mirrorOrientations[coordKey] || 0;
|
||||
|
||||
// Rotation
|
||||
currentAngle = (currentAngle + 45) % 360;
|
||||
// Rotation and normalize negative angles to [0, 360)
|
||||
currentAngle = (currentAngle + (isRightClick ? 45 : -45)) % 360;
|
||||
if (currentAngle < 0) {
|
||||
currentAngle += 360;
|
||||
}
|
||||
|
||||
// Save
|
||||
mirrorOrientations[coordKey] = currentAngle;
|
||||
@@ -288,68 +287,3 @@ function finish() {
|
||||
}
|
||||
|
||||
|
||||
// Get player inputs arrows, qwerty and azerty
|
||||
|
||||
document.addEventListener("keydown", (e) => {
|
||||
|
||||
// If level finish -> don't move
|
||||
if (isLevelFinished === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.key) {
|
||||
case "ArrowUp":
|
||||
movePlayer(0, -1);
|
||||
break;
|
||||
case "w":
|
||||
movePlayer(0, -1);
|
||||
break;
|
||||
case "z":
|
||||
movePlayer(0, -1);
|
||||
break;
|
||||
case "ArrowDown":
|
||||
movePlayer(0, 1);
|
||||
break;
|
||||
case "s":
|
||||
movePlayer(0, 1);
|
||||
break;
|
||||
case "ArrowLeft":
|
||||
movePlayer(-1, 0);
|
||||
break;
|
||||
case "a":
|
||||
movePlayer(-1, 0);
|
||||
break;
|
||||
case "q":
|
||||
movePlayer(-1, 0);
|
||||
break;
|
||||
case "ArrowRight":
|
||||
movePlayer(1, 0);
|
||||
break;
|
||||
case "d":
|
||||
movePlayer(1, 0);
|
||||
break;
|
||||
case "Enter":
|
||||
rotateMirror(playerX, playerY);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// Player move
|
||||
|
||||
function movePlayer(x, y) {
|
||||
const newX = playerX + x;
|
||||
const newY = playerY + y;
|
||||
|
||||
if (newX < 0 || newX >= level1[0].length) {
|
||||
return
|
||||
};
|
||||
|
||||
if (newY < 0 || newY >= level1.length) {
|
||||
return
|
||||
};
|
||||
|
||||
playerX = newX;
|
||||
playerY = newY;
|
||||
|
||||
loadGrid();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user