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, 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, 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, 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, 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, 10, 6, 6, 6, 6, 6, 0, 0, 0, 0, 0],
|
||||
],
|
||||
@@ -93,23 +93,50 @@ let levels = [
|
||||
|
||||
let currentLevelIndex = 0;
|
||||
|
||||
const initialMirrorAngles = {
|
||||
"6,4": 315,
|
||||
"4,3": 315,
|
||||
};
|
||||
const initialMirrorAngles = [
|
||||
{
|
||||
"6,4": 315,
|
||||
},
|
||||
{},
|
||||
{
|
||||
"3,4": 315,
|
||||
"7,8": 0,
|
||||
},
|
||||
];
|
||||
|
||||
const buttonGroups = {
|
||||
"4,6": 1,
|
||||
"4,7": 2,
|
||||
};
|
||||
const buttonGroups = [
|
||||
{
|
||||
"4,6": 1,
|
||||
},
|
||||
{},
|
||||
{},
|
||||
];
|
||||
|
||||
const doorGroups = {
|
||||
"4,7": 1,
|
||||
"4,8": 2,
|
||||
};
|
||||
const doorGroups = [
|
||||
{
|
||||
"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 laserSegments = {};
|
||||
@@ -120,11 +147,17 @@ let openedDoors = {};
|
||||
let isLevelFinished = false;
|
||||
let activeRotatorButtons = {};
|
||||
let rotatorIntervals = {};
|
||||
let toggledDoors = {};
|
||||
let poweredCaptors = {};
|
||||
|
||||
function getCurrentLevel() {
|
||||
return levels[currentLevelIndex];
|
||||
}
|
||||
|
||||
function getCurrentLevelConfig(configByLevel) {
|
||||
return configByLevel[currentLevelIndex] || {};
|
||||
}
|
||||
|
||||
function normalizeLaserDirection(dx, dy) {
|
||||
const epsilon = 0.0001;
|
||||
const normalizedDx = Math.abs(dx) < epsilon ? 0 : Math.sign(dx);
|
||||
@@ -182,11 +215,15 @@ function getButtonGroup(x, y) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
return buttonGroups[`${y},${x}`] || 1;
|
||||
return getCurrentLevelConfig(buttonGroups)[`${y},${x}`] || 1;
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -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) {
|
||||
return rotatorButtons[`${y},${x}`];
|
||||
return getCurrentLevelConfig(rotatorButtons)[`${y},${x}`];
|
||||
}
|
||||
|
||||
function isMirrorControlledByButton(x, y) {
|
||||
const rotatorEntries = Object.values(rotatorButtons);
|
||||
const rotatorEntries = Object.values(getCurrentLevelConfig(rotatorButtons));
|
||||
|
||||
for (let i = 0; i < rotatorEntries.length; i++) {
|
||||
const rotatorConfig = rotatorEntries[i];
|
||||
@@ -238,11 +290,12 @@ function rotateMirrorStep(x, y, angleStep) {
|
||||
}
|
||||
|
||||
function syncRotatorButtons() {
|
||||
const rotatorKeys = Object.keys(rotatorButtons);
|
||||
const currentLevelRotatorButtons = getCurrentLevelConfig(rotatorButtons);
|
||||
const rotatorKeys = Object.keys(currentLevelRotatorButtons);
|
||||
|
||||
for (let i = 0; i < rotatorKeys.length; i++) {
|
||||
const key = rotatorKeys[i];
|
||||
const config = rotatorButtons[key];
|
||||
const config = currentLevelRotatorButtons[key];
|
||||
const isActive = activeRotatorButtons[key] === true;
|
||||
|
||||
if (isActive && !rotatorIntervals[key]) {
|
||||
@@ -402,7 +455,7 @@ function initializeMirrorOrientations() {
|
||||
for (let y = 0; y < level.length; y++) {
|
||||
for (let x = 0; x < level[y].length; x++) {
|
||||
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() {
|
||||
laserSegments = {};
|
||||
activatedButtons = {};
|
||||
openedDoors = {};
|
||||
openedDoors = { ...toggledDoors };
|
||||
activeRotatorButtons = {};
|
||||
isLevelFinished = false;
|
||||
const nextPoweredCaptors = {};
|
||||
|
||||
const level = getCurrentLevel();
|
||||
let startLaserX;
|
||||
@@ -635,7 +689,6 @@ function traceLaser() {
|
||||
laserActive = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case legend.button:
|
||||
case legend.button2:
|
||||
if (currentLaserColor === laserColors.red) {
|
||||
@@ -651,35 +704,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:
|
||||
@@ -688,6 +772,7 @@ function traceLaser() {
|
||||
}
|
||||
}
|
||||
|
||||
poweredCaptors = nextPoweredCaptors;
|
||||
syncRotatorButtons();
|
||||
loadGrid();
|
||||
|
||||
@@ -720,6 +805,8 @@ function nextLevel() {
|
||||
glassPlacements = {};
|
||||
activatedButtons = {};
|
||||
openedDoors = {};
|
||||
toggledDoors = {};
|
||||
poweredCaptors = {};
|
||||
traceLaser();
|
||||
|
||||
const winOverlay = document.querySelector(".win-overlay");
|
||||
|
||||
Reference in New Issue
Block a user