Remove player + right click change rotation mirror

This commit is contained in:
Sysy's
2026-03-31 09:40:25 +02:00
committed by M1n-0
parent 853a6ae9ee
commit d8f56cb548
2 changed files with 17 additions and 97 deletions

View File

@@ -97,20 +97,6 @@ main {
background: #00FF00; background: #00FF00;
} }
/* ================================
CURSOR PLAYER
================================ */
.player-cursor {
outline: 2px solid #00e5ff;
outline-offset: -2px;
z-index: 10;
}
.player-cursor.mirror {
outline-color: #FFD700;
}
/* ================================ /* ================================
LIGHT LASER LIGHT LASER
================================ */ ================================ */
@@ -169,4 +155,4 @@ main {
.map { .map {
padding: 4px; padding: 4px;
} }
} }

View File

@@ -28,10 +28,6 @@ let level1 = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [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 // Function to save initial orientation of mirrors
let laserDirection = { dx: 0, dy: 0 }; let laserDirection = { dx: 0, dy: 0 };
let laserSegments = {}; let laserSegments = {};
@@ -76,13 +72,18 @@ function loadGrid() {
break; break;
case legend.mirror: case legend.mirror:
const currentAngle = mirrorOrientations[`${y},${x}`] || 0; const currentAngle = mirrorOrientations[`${y},${x}`] || 0;
cell.onclick = () => {
rotateMirror(x, y);
}
const btnMirror = document.createElement("button"); const btnMirror = document.createElement("button");
btnMirror.classList.add("btn-mirror"); btnMirror.classList.add("btn-mirror");
btnMirror.type = "button";
btnMirror.style.transform = `rotate(${currentAngle}deg)`; btnMirror.style.transform = `rotate(${currentAngle}deg)`;
btnMirror.style.width = "100%"; 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.appendChild(btnMirror);
cell.classList.add("mirror"); cell.classList.add("mirror");
break; break;
@@ -112,10 +113,6 @@ function loadGrid() {
break; break;
} }
if (x === playerX && y === playerY) {
cell.classList.add("player-cursor");
}
lign.appendChild(cell); lign.appendChild(cell);
} }
@@ -127,18 +124,20 @@ loadGrid();
// Function to rotate mirror // Function to rotate mirror
function rotateMirror(x, y) { function rotateMirror(x, y, isRightClick) {
const coordKey = `${y},${x}`; const coordKey = `${y},${x}`;
// See if it's a mirror
if (level1[y][x] !== legend.mirror) { if (level1[y][x] !== legend.mirror) {
return return;
}; }
let currentAngle = mirrorOrientations[coordKey] || 0; let currentAngle = mirrorOrientations[coordKey] || 0;
// Rotation // Rotation and normalize negative angles to [0, 360)
currentAngle = (currentAngle + 45) % 360; currentAngle = (currentAngle + (isRightClick ? 45 : -45)) % 360;
if (currentAngle < 0) {
currentAngle += 360;
}
// Save // Save
mirrorOrientations[coordKey] = currentAngle; 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();
}