Compare commits
2 Commits
edea5e0972
...
a9d2a0c9a5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9d2a0c9a5 | ||
|
|
9c7c2ddc1d |
@@ -67,11 +67,11 @@ 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, 3, 0, 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],
|
||||||
[0, 0, 0, 0, 6, 0, 0, 0, 3, 0, 7, 0, 0, 0, 0],
|
[0, 0, 0, 0, 6, 0, 0, 3, 0, 0, 7, 0, 0, 0, 0],
|
||||||
[0, 0, 0, 0, 6, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
[0, 0, 0, 0, 6, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
[0, 0, 0, 0, 10, 6, 6, 6, 6, 6, 0, 0, 0, 0, 0],
|
[0, 0, 0, 0, 10, 6, 6, 6, 6, 6, 0, 0, 0, 0, 0],
|
||||||
],
|
],
|
||||||
@@ -93,23 +93,50 @@ let levels = [
|
|||||||
|
|
||||||
let currentLevelIndex = 0;
|
let currentLevelIndex = 0;
|
||||||
|
|
||||||
const initialMirrorAngles = {
|
const initialMirrorAngles = [
|
||||||
"6,4": 315,
|
{
|
||||||
"4,3": 315,
|
"6,4": 315,
|
||||||
};
|
},
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
"3,4": 315,
|
||||||
|
"7,8": 0,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const buttonGroups = {
|
const buttonGroups = [
|
||||||
"4,6": 1,
|
{
|
||||||
"4,7": 2,
|
"4,6": 1,
|
||||||
};
|
},
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
];
|
||||||
|
|
||||||
const doorGroups = {
|
const doorGroups = [
|
||||||
"4,7": 1,
|
{
|
||||||
"4,8": 2,
|
"4,7": 1,
|
||||||
};
|
},
|
||||||
|
{
|
||||||
|
"4,6": 1,
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
];
|
||||||
|
|
||||||
const rotatorButtons = {
|
const captorGroups = [
|
||||||
};
|
{},
|
||||||
|
{
|
||||||
|
"2,6": 1,
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
];
|
||||||
|
|
||||||
|
const rotatorButtons = [
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
"3,7": { mirrorX: 7, mirrorY: 7, step: -22.5, intervalMs: 1000 },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
let laserDirection = { dx: 0, dy: 0 };
|
let laserDirection = { dx: 0, dy: 0 };
|
||||||
let laserSegments = {};
|
let laserSegments = {};
|
||||||
@@ -120,11 +147,17 @@ 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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCurrentLevelConfig(configByLevel) {
|
||||||
|
return configByLevel[currentLevelIndex] || {};
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeLaserDirection(dx, dy) {
|
function normalizeLaserDirection(dx, dy) {
|
||||||
const epsilon = 0.0001;
|
const epsilon = 0.0001;
|
||||||
const normalizedDx = Math.abs(dx) < epsilon ? 0 : Math.sign(dx);
|
const normalizedDx = Math.abs(dx) < epsilon ? 0 : Math.sign(dx);
|
||||||
@@ -182,11 +215,15 @@ function getButtonGroup(x, y) {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return buttonGroups[`${y},${x}`] || 1;
|
return getCurrentLevelConfig(buttonGroups)[`${y},${x}`] || 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDoorGroup(x, y) {
|
function getDoorGroup(x, y) {
|
||||||
return doorGroups[`${y},${x}`] || 1;
|
return getCurrentLevelConfig(doorGroups)[`${y},${x}`] || 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCaptorGroup(x, y) {
|
||||||
|
return getCurrentLevelConfig(captorGroups)[`${y},${x}`] || getDoorGroup(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
function openDoorsFromButton(x, y) {
|
function openDoorsFromButton(x, y) {
|
||||||
@@ -202,12 +239,27 @@ 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 getCurrentLevelConfig(rotatorButtons)[`${y},${x}`];
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMirrorControlledByButton(x, y) {
|
function isMirrorControlledByButton(x, y) {
|
||||||
const rotatorEntries = Object.values(rotatorButtons);
|
const rotatorEntries = Object.values(getCurrentLevelConfig(rotatorButtons));
|
||||||
|
|
||||||
for (let i = 0; i < rotatorEntries.length; i++) {
|
for (let i = 0; i < rotatorEntries.length; i++) {
|
||||||
const rotatorConfig = rotatorEntries[i];
|
const rotatorConfig = rotatorEntries[i];
|
||||||
@@ -238,11 +290,12 @@ function rotateMirrorStep(x, y, angleStep) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function syncRotatorButtons() {
|
function syncRotatorButtons() {
|
||||||
const rotatorKeys = Object.keys(rotatorButtons);
|
const currentLevelRotatorButtons = getCurrentLevelConfig(rotatorButtons);
|
||||||
|
const rotatorKeys = Object.keys(currentLevelRotatorButtons);
|
||||||
|
|
||||||
for (let i = 0; i < rotatorKeys.length; i++) {
|
for (let i = 0; i < rotatorKeys.length; i++) {
|
||||||
const key = rotatorKeys[i];
|
const key = rotatorKeys[i];
|
||||||
const config = rotatorButtons[key];
|
const config = currentLevelRotatorButtons[key];
|
||||||
const isActive = activeRotatorButtons[key] === true;
|
const isActive = activeRotatorButtons[key] === true;
|
||||||
|
|
||||||
if (isActive && !rotatorIntervals[key]) {
|
if (isActive && !rotatorIntervals[key]) {
|
||||||
@@ -402,7 +455,7 @@ function initializeMirrorOrientations() {
|
|||||||
for (let y = 0; y < level.length; y++) {
|
for (let y = 0; y < level.length; y++) {
|
||||||
for (let x = 0; x < level[y].length; x++) {
|
for (let x = 0; x < level[y].length; x++) {
|
||||||
if (level[y][x] === legend.mirror) {
|
if (level[y][x] === legend.mirror) {
|
||||||
mirrorOrientations[`${y},${x}`] = initialMirrorAngles[`${y},${x}`] || 0;
|
mirrorOrientations[`${y},${x}`] = getCurrentLevelConfig(initialMirrorAngles)[`${y},${x}`] || 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -537,9 +590,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;
|
||||||
@@ -635,7 +689,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) {
|
||||||
@@ -651,35 +704,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:
|
||||||
laserDirection = reflectLaser(laserDirection, 135);
|
if(currentLaserColor === laserColors.blue) {
|
||||||
|
laserDirection = reflectLaser(laserDirection, 135);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case legend.demiWallCornerUpRight:
|
case legend.demiWallCornerUpRight:
|
||||||
laserDirection = reflectLaser(laserDirection, 45);
|
if(currentLaserColor === laserColors.blue) {
|
||||||
|
laserDirection = reflectLaser(laserDirection, 45);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case legend.demiWallCornerDownLeft:
|
case legend.demiWallCornerDownLeft:
|
||||||
laserDirection = reflectLaser(laserDirection, 225);
|
if(currentLaserColor === laserColors.blue) {
|
||||||
|
laserDirection = reflectLaser(laserDirection, 225);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case legend.demiWallCornerDownRight:
|
case legend.demiWallCornerDownRight:
|
||||||
laserDirection = reflectLaser(laserDirection, 315);
|
if(currentLaserColor === laserColors.blue) {
|
||||||
|
laserDirection = reflectLaser(laserDirection, 315);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -688,6 +772,7 @@ function traceLaser() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
poweredCaptors = nextPoweredCaptors;
|
||||||
syncRotatorButtons();
|
syncRotatorButtons();
|
||||||
loadGrid();
|
loadGrid();
|
||||||
|
|
||||||
@@ -720,6 +805,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");
|
||||||
|
|||||||
Reference in New Issue
Block a user