diff --git a/web/assets/js/game.js b/web/assets/js/game.js index d03c94a..03321a2 100644 --- a/web/assets/js/game.js +++ b/web/assets/js/game.js @@ -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, 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], @@ -107,6 +107,9 @@ const doorGroups = { "4,8": 2, }; +const captorGroups = { +}; + const rotatorButtons = { }; @@ -119,6 +122,8 @@ let openedDoors = {}; let isLevelFinished = false; let activeRotatorButtons = {}; let rotatorIntervals = {}; +let toggledDoors = {}; +let poweredCaptors = {}; function getCurrentLevel() { return levels[currentLevelIndex]; @@ -188,6 +193,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(); @@ -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) { return rotatorButtons[`${y},${x}`]; } @@ -536,9 +560,10 @@ function rotateMirror(x, y, isRightClick) { function traceLaser() { laserSegments = {}; activatedButtons = {}; - openedDoors = {}; + openedDoors = { ...toggledDoors }; activeRotatorButtons = {}; isLevelFinished = false; + const nextPoweredCaptors = {}; const level = getCurrentLevel(); let startLaserX; @@ -634,7 +659,6 @@ function traceLaser() { laserActive = false; } break; - case legend.button: case legend.button2: if (currentLaserColor === laserColors.red) { @@ -650,35 +674,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: - laserDirection = reflectLaser(laserDirection, 135); + if(currentLaserColor === laserColors.blue) { + laserDirection = reflectLaser(laserDirection, 135); + } break; case legend.demiWallCornerUpRight: - laserDirection = reflectLaser(laserDirection, 45); + if(currentLaserColor === laserColors.blue) { + laserDirection = reflectLaser(laserDirection, 45); + } break; case legend.demiWallCornerDownLeft: - laserDirection = reflectLaser(laserDirection, 225); + if(currentLaserColor === laserColors.blue) { + laserDirection = reflectLaser(laserDirection, 225); + } break; case legend.demiWallCornerDownRight: - laserDirection = reflectLaser(laserDirection, 315); + if(currentLaserColor === laserColors.blue) { + laserDirection = reflectLaser(laserDirection, 315); + } break; default: @@ -687,6 +742,7 @@ function traceLaser() { } } + poweredCaptors = nextPoweredCaptors; syncRotatorButtons(); loadGrid(); @@ -740,6 +796,8 @@ function nextLevel() { glassPlacements = {}; activatedButtons = {}; openedDoors = {}; + toggledDoors = {}; + poweredCaptors = {}; traceLaser(); const winOverlay = document.querySelector(".win-overlay");