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:
@@ -67,7 +67,7 @@ let levels = [
|
||||
[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, 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, 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],
|
||||
@@ -108,6 +108,9 @@ const doorGroups = {
|
||||
"4,8": 2,
|
||||
};
|
||||
|
||||
const captorGroups = {
|
||||
};
|
||||
|
||||
const rotatorButtons = {
|
||||
};
|
||||
|
||||
@@ -120,6 +123,8 @@ let openedDoors = {};
|
||||
let isLevelFinished = false;
|
||||
let activeRotatorButtons = {};
|
||||
let rotatorIntervals = {};
|
||||
let toggledDoors = {};
|
||||
let poweredCaptors = {};
|
||||
|
||||
function getCurrentLevel() {
|
||||
return levels[currentLevelIndex];
|
||||
@@ -189,6 +194,10 @@ function getDoorGroup(x, y) {
|
||||
return doorGroups[`${y},${x}`] || 1;
|
||||
}
|
||||
|
||||
function getCaptorGroup(x, y) {
|
||||
return captorGroups[`${y},${x}`] || getDoorGroup(x, y);
|
||||
}
|
||||
|
||||
function openDoorsFromButton(x, y) {
|
||||
const buttonGroup = getButtonGroup(x, y);
|
||||
const level = getCurrentLevel();
|
||||
@@ -202,6 +211,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) {
|
||||
return rotatorButtons[`${y},${x}`];
|
||||
}
|
||||
@@ -537,9 +561,10 @@ function rotateMirror(x, y, isRightClick) {
|
||||
function traceLaser() {
|
||||
laserSegments = {};
|
||||
activatedButtons = {};
|
||||
openedDoors = {};
|
||||
openedDoors = { ...toggledDoors };
|
||||
activeRotatorButtons = {};
|
||||
isLevelFinished = false;
|
||||
const nextPoweredCaptors = {};
|
||||
|
||||
const level = getCurrentLevel();
|
||||
let startLaserX;
|
||||
@@ -635,7 +660,6 @@ function traceLaser() {
|
||||
laserActive = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case legend.button:
|
||||
case legend.button2:
|
||||
if (currentLaserColor === laserColors.red) {
|
||||
@@ -651,35 +675,66 @@ function traceLaser() {
|
||||
}
|
||||
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:
|
||||
if (currentLaserColor === laserColors.red) {
|
||||
const rotatorKey = `${currentY},${currentX}`;
|
||||
activatedButtons[rotatorKey] = true;
|
||||
activeRotatorButtons[rotatorKey] = true;
|
||||
saveLaserSegment(currentX, currentY, laserDirection, currentLaserColor);
|
||||
laserActive = false;
|
||||
} else if (currentLaserColor === laserColors.yellow) {
|
||||
saveLaserSegment(currentX, currentY, laserDirection, currentLaserColor);
|
||||
} else if (currentLaserColor === laserColors.blue) {
|
||||
laserDirection = reverseLaser(laserDirection);
|
||||
laserActive = false;
|
||||
} else {
|
||||
laserActive = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case legend.demiWallCornerUpLeft:
|
||||
if(currentLaserColor === laserColors.blue) {
|
||||
laserDirection = reflectLaser(laserDirection, 135);
|
||||
}
|
||||
break;
|
||||
|
||||
case legend.demiWallCornerUpRight:
|
||||
if(currentLaserColor === laserColors.blue) {
|
||||
laserDirection = reflectLaser(laserDirection, 45);
|
||||
}
|
||||
break;
|
||||
|
||||
case legend.demiWallCornerDownLeft:
|
||||
if(currentLaserColor === laserColors.blue) {
|
||||
laserDirection = reflectLaser(laserDirection, 225);
|
||||
}
|
||||
break;
|
||||
|
||||
case legend.demiWallCornerDownRight:
|
||||
if(currentLaserColor === laserColors.blue) {
|
||||
laserDirection = reflectLaser(laserDirection, 315);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -688,6 +743,7 @@ function traceLaser() {
|
||||
}
|
||||
}
|
||||
|
||||
poweredCaptors = nextPoweredCaptors;
|
||||
syncRotatorButtons();
|
||||
loadGrid();
|
||||
|
||||
@@ -720,6 +776,8 @@ function nextLevel() {
|
||||
glassPlacements = {};
|
||||
activatedButtons = {};
|
||||
openedDoors = {};
|
||||
toggledDoors = {};
|
||||
poweredCaptors = {};
|
||||
traceLaser();
|
||||
|
||||
const winOverlay = document.querySelector(".win-overlay");
|
||||
|
||||
Reference in New Issue
Block a user