Implement captors and color-dependent laser effects

Add captor support and related door-toggling state plus color-specific laser interactions. Changes include: replace one level tile value (15 -> 20), add captorGroups/getCaptorGroup, add toggleDoorsFromCaptor, and new state (toggledDoors, poweredCaptors). traceLaser now initializes openedDoors from toggledDoors, tracks nextPoweredCaptors, handles captor tiles (red lasers power/toggle door groups, yellow passes, others stop), updates poweredCaptors, and applies color-based behavior for rotator buttons and demi-wall reflections (only reflect for blue). Reset toggledDoors and poweredCaptors on next level. These changes implement captor mechanics that toggle door groups and ensure correct color-dependent laser effects.
This commit is contained in:
Sysy's
2026-03-31 13:27:08 +02:00
committed by M1n-0
parent 1ad8282833
commit f9e94f5c18

View File

@@ -66,7 +66,7 @@ let levels = [
[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],
[0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 11, 0, 0, 0, 0], [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 11, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 10, 6, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 10, 6, 0, 0, 0, 0],
[0, 0, 0, 0, 3, 16, 16, 15, 0, 3, 6, 0, 0, 0, 0], [0, 0, 0, 0, 3, 16, 16, 20, 0, 3, 6, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 6, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 6, 0, 0, 0, 0],
[0, 0, 0, 0, 12, 6, 6, 6, 6, 6, 9, 0, 0, 0, 0], [0, 0, 0, 0, 12, 6, 6, 6, 6, 6, 9, 0, 0, 0, 0],
[0, 0, 0, 0, 6, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 6, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0],
@@ -107,6 +107,9 @@ const doorGroups = {
"4,8": 2, "4,8": 2,
}; };
const captorGroups = {
};
const rotatorButtons = { const rotatorButtons = {
}; };
@@ -119,6 +122,8 @@ let openedDoors = {};
let isLevelFinished = false; let isLevelFinished = false;
let activeRotatorButtons = {}; let activeRotatorButtons = {};
let rotatorIntervals = {}; let rotatorIntervals = {};
let toggledDoors = {};
let poweredCaptors = {};
function getCurrentLevel() { function getCurrentLevel() {
return levels[currentLevelIndex]; return levels[currentLevelIndex];
@@ -188,6 +193,10 @@ function getDoorGroup(x, y) {
return doorGroups[`${y},${x}`] || 1; return doorGroups[`${y},${x}`] || 1;
} }
function getCaptorGroup(x, y) {
return captorGroups[`${y},${x}`] || getDoorGroup(x, y);
}
function openDoorsFromButton(x, y) { function openDoorsFromButton(x, y) {
const buttonGroup = getButtonGroup(x, y); const buttonGroup = getButtonGroup(x, y);
const level = getCurrentLevel(); const level = getCurrentLevel();
@@ -201,6 +210,21 @@ function openDoorsFromButton(x, y) {
} }
} }
function toggleDoorsFromCaptor(x, y) {
const captorGroup = getCaptorGroup(x, y);
const level = getCurrentLevel();
for (let doorY = 0; doorY < level.length; doorY++) {
for (let doorX = 0; doorX < level[doorY].length; doorX++) {
const coordKey = `${doorY},${doorX}`;
if (level[doorY][doorX] === legend.door && getDoorGroup(doorX, doorY) === captorGroup) {
toggledDoors[coordKey] = !toggledDoors[coordKey];
}
}
}
}
function getRotatorButtonConfig(x, y) { function getRotatorButtonConfig(x, y) {
return rotatorButtons[`${y},${x}`]; return rotatorButtons[`${y},${x}`];
} }
@@ -536,9 +560,10 @@ function rotateMirror(x, y, isRightClick) {
function traceLaser() { function traceLaser() {
laserSegments = {}; laserSegments = {};
activatedButtons = {}; activatedButtons = {};
openedDoors = {}; openedDoors = { ...toggledDoors };
activeRotatorButtons = {}; activeRotatorButtons = {};
isLevelFinished = false; isLevelFinished = false;
const nextPoweredCaptors = {};
const level = getCurrentLevel(); const level = getCurrentLevel();
let startLaserX; let startLaserX;
@@ -634,7 +659,6 @@ function traceLaser() {
laserActive = false; laserActive = false;
} }
break; break;
case legend.button: case legend.button:
case legend.button2: case legend.button2:
if (currentLaserColor === laserColors.red) { if (currentLaserColor === laserColors.red) {
@@ -650,35 +674,66 @@ function traceLaser() {
} }
break; break;
case legend.captor:
case legend.captorTurn:
if (currentLaserColor === laserColors.red) {
const captorKey = `${currentY},${currentX}`;
activatedButtons[captorKey] = true;
nextPoweredCaptors[captorKey] = true;
if (!poweredCaptors[captorKey]) {
toggleDoorsFromCaptor(currentX, currentY);
openedDoors = { ...toggledDoors };
}
saveLaserSegment(currentX, currentY, laserDirection, currentLaserColor);
laserActive = false;
}else if(currentLaserColor === laserColors.yellow) {
saveLaserSegment(currentX, currentY, laserDirection, currentLaserColor);
} else {
laserActive = false;
}
break;
case legend.rotatorButton: case legend.rotatorButton:
if (currentLaserColor === laserColors.red) { if (currentLaserColor === laserColors.red) {
const rotatorKey = `${currentY},${currentX}`; const rotatorKey = `${currentY},${currentX}`;
activatedButtons[rotatorKey] = true; activatedButtons[rotatorKey] = true;
activeRotatorButtons[rotatorKey] = true; activeRotatorButtons[rotatorKey] = true;
saveLaserSegment(currentX, currentY, laserDirection, currentLaserColor); saveLaserSegment(currentX, currentY, laserDirection, currentLaserColor);
laserActive = false;
} else if (currentLaserColor === laserColors.yellow) { } else if (currentLaserColor === laserColors.yellow) {
saveLaserSegment(currentX, currentY, laserDirection, currentLaserColor); saveLaserSegment(currentX, currentY, laserDirection, currentLaserColor);
} else if (currentLaserColor === laserColors.blue) { } else if (currentLaserColor === laserColors.blue) {
laserDirection = reverseLaser(laserDirection); laserDirection = reverseLaser(laserDirection);
laserActive = false;
} else { } else {
laserActive = false; laserActive = false;
} }
break; break;
case legend.demiWallCornerUpLeft: case legend.demiWallCornerUpLeft:
if(currentLaserColor === laserColors.blue) {
laserDirection = reflectLaser(laserDirection, 135); laserDirection = reflectLaser(laserDirection, 135);
}
break; break;
case legend.demiWallCornerUpRight: case legend.demiWallCornerUpRight:
if(currentLaserColor === laserColors.blue) {
laserDirection = reflectLaser(laserDirection, 45); laserDirection = reflectLaser(laserDirection, 45);
}
break; break;
case legend.demiWallCornerDownLeft: case legend.demiWallCornerDownLeft:
if(currentLaserColor === laserColors.blue) {
laserDirection = reflectLaser(laserDirection, 225); laserDirection = reflectLaser(laserDirection, 225);
}
break; break;
case legend.demiWallCornerDownRight: case legend.demiWallCornerDownRight:
if(currentLaserColor === laserColors.blue) {
laserDirection = reflectLaser(laserDirection, 315); laserDirection = reflectLaser(laserDirection, 315);
}
break; break;
default: default:
@@ -687,6 +742,7 @@ function traceLaser() {
} }
} }
poweredCaptors = nextPoweredCaptors;
syncRotatorButtons(); syncRotatorButtons();
loadGrid(); loadGrid();
@@ -740,6 +796,8 @@ function nextLevel() {
glassPlacements = {}; glassPlacements = {};
activatedButtons = {}; activatedButtons = {};
openedDoors = {}; openedDoors = {};
toggledDoors = {};
poweredCaptors = {};
traceLaser(); traceLaser();
const winOverlay = document.querySelector(".win-overlay"); const winOverlay = document.querySelector(".win-overlay");