/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var CombinationLock = Container.expand(function (x, y, correctSeq) {
var self = Container.call(this);
self.correctSequence = correctSeq;
self.currentSequence = [];
self.maxLength = 4;
var graphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
graphics.tint = 0x4444ff;
self.x = x;
self.y = y;
self.addToSequence = function (value) {
self.currentSequence.push(value);
if (self.currentSequence.length > self.maxLength) {
self.currentSequence.shift();
}
showMessage("Kombinasyon: " + self.currentSequence.join('-'));
};
self.checkSequence = function () {
if (self.currentSequence.length === self.correctSequence.length) {
for (var i = 0; i < self.currentSequence.length; i++) {
if (self.currentSequence[i] !== self.correctSequence[i]) {
return false;
}
}
return true;
}
return false;
};
self.reset = function () {
self.currentSequence = [];
};
self.down = function (x, y, obj) {
self.addToSequence(1);
};
return self;
});
var Door = Container.expand(function (x, y) {
var self = Container.call(this);
var graphics = self.attachAsset('door', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.isLocked = true;
self.tryOpen = function () {
if (self.isLocked) {
showMessage("Kapı kilitli. Bir anahtara ihtiyacınız var!");
return false;
} else {
showMessage("Kapı açılıyor! Kaçtınız!");
LK.getSound('success').play();
return true;
}
};
self.unlock = function () {
self.isLocked = false;
graphics.tint = 0x00ff00;
LK.effects.flashObject(self, 0xffffff, 1000);
showMessage("Kapı kilidi açıldı!");
};
self.down = function (x, y, obj) {
if (self.tryOpen()) {
victory();
}
};
return self;
});
var InteractiveObject = Container.expand(function (type, x, y, data) {
var self = Container.call(this);
self.objectType = type;
self.objectData = data || {};
self.isExamined = false;
self.isUsed = false;
self.requiredSequence = data ? data.requiredSequence : null;
var graphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.examine = function () {
self.isExamined = true;
LK.effects.flashObject(self, 0xffffff, 500);
LK.getSound('click').play();
if (self.objectType === 'note') {
showMessage("Notta yazıyor: '" + self.objectData.text + "'");
} else if (self.objectType === 'key') {
showMessage("Altın bir anahtar. Bir şeyleri açabilir...");
} else if (self.objectType === 'box') {
if (self.objectData.isLocked && currentLoop > 2) {
showMessage("Kutu kilitli. Doğru sırayla düğmelere basın!");
} else {
showMessage("Ahşap bir kutu. Ağır hissediliyor.");
}
} else if (self.objectType === 'button') {
showMessage("Renkli bir düğme. Sırası önemli olabilir...");
} else if (self.objectType === 'lever') {
showMessage("Metal bir kol. Çekilebilir.");
} else if (self.objectType === 'water') {
if (!self.objectData.hasSpawnedKeys) {
// Spawn 2 keys when water is clicked
var key1 = new InteractiveObject('key', self.x - 100, self.y - 100);
var key2 = new InteractiveObject('key', self.x + 100, self.y - 100);
gameObjects.push(key1);
gameObjects.push(key2);
game.addChild(key1);
game.addChild(key2);
self.objectData.hasSpawnedKeys = true;
showMessage("Sudan 2 anahtar çıktı!");
LK.effects.flashObject(self, 0xffffff, 1000);
} else {
showMessage("Su artık boş görünüyor...");
}
}
};
self.use = function () {
if (self.objectType === 'button') {
// Add penalty for wrong sequence
if (self.requiredSequence && combination.length === 0) {
combination.push(self.objectData.buttonId);
} else if (self.requiredSequence && combination.length < self.requiredSequence.length) {
combination.push(self.objectData.buttonId);
if (combination[combination.length - 1] !== self.requiredSequence[combination.length - 1]) {
penalties++;
startTime -= wrongActionPenalty;
showMessage("Yanlış sıra! " + wrongActionPenalty / 1000 + " saniye ceza!");
LK.effects.flashScreen(0xff0000, 500);
combination = [];
}
}
self.isUsed = !self.isUsed;
graphics.tint = self.isUsed ? 0x00ff00 : 0xff4444;
LK.getSound('click').play();
showMessage(self.isUsed ? "Düğme etkinleştirildi!" : "Düğme devre dışı!");
} else if (self.objectType === 'lever') {
self.isUsed = !self.isUsed;
graphics.rotation = self.isUsed ? Math.PI / 4 : 0;
LK.getSound('click').play();
showMessage(self.isUsed ? "Kol çekildi!" : "Kol sıfırlandı!");
}
};
self.down = function (x, y, obj) {
if (self.objectType === 'key') {
draggedObject = self;
} else {
self.examine();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
var currentLoop = storage.currentLoop || 0;
var baseTimeLimit = 60000; // 60 seconds
var timeLimit = Math.max(30000, baseTimeLimit - currentLoop * 5000); // Reduce by 5s each loop, minimum 30s
var startTime = 0;
var gameObjects = [];
var draggedObject = null;
var door = null;
var messageText = null;
var timerText = null;
var loopText = null;
var isGameActive = true;
var combination = [];
var correctCombination = [];
var wrongActionPenalty = 5000; // 5 second penalty
var penalties = 0;
var keysCollected = 0;
var requiredKeys = 3;
// UI Setup
var titleText = new Text2('Zamanda Sıkışmış Kaçış Odası', {
size: 80,
fill: '#ffffff'
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
timerText = new Text2('Süre: 60s', {
size: 60,
fill: '#ffff00'
});
timerText.anchor.set(1, 0);
LK.gui.topRight.addChild(timerText);
loopText = new Text2('Döngü: ' + (currentLoop + 1), {
size: 50,
fill: '#00ffff'
});
loopText.anchor.set(0, 0);
loopText.x = 120;
LK.gui.topLeft.addChild(loopText);
messageText = new Text2('', {
size: 50,
fill: '#ffffff'
});
messageText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(messageText);
function showMessage(text) {
messageText.setText(text);
messageText.alpha = 1;
tween(messageText, {
alpha: 0
}, {
duration: 3000
});
}
function initializeRoom() {
// Clear existing objects
for (var i = gameObjects.length - 1; i >= 0; i--) {
gameObjects[i].destroy();
}
gameObjects = [];
// Create door
door = new Door(2048 - 200, 2732 / 2);
game.addChild(door);
// Create objects based on loop number
var keyX = 300 + currentLoop * 50 % 400;
var keyY = 2000 + currentLoop * 30 % 200;
var key = new InteractiveObject('key', keyX, keyY);
gameObjects.push(key);
game.addChild(key);
// Box position changes each loop
var boxX = 500 + currentLoop * 100 % 600;
var boxY = 1500 + currentLoop * 80 % 400;
var box = new InteractiveObject('box', boxX, boxY, {
containsKey: currentLoop > 0
});
gameObjects.push(box);
game.addChild(box);
// Button appears after first loop
if (currentLoop > 0) {
var button = new InteractiveObject('button', 1500, 1800, {
buttonId: 1
});
gameObjects.push(button);
game.addChild(button);
}
// Lever appears after second loop
if (currentLoop > 1) {
var lever = new InteractiveObject('lever', 1200, 1600);
gameObjects.push(lever);
game.addChild(lever);
}
// Multiple buttons with combination system (loop 3+)
if (currentLoop > 2) {
correctCombination = [1, 3, 2, 4]; // Correct sequence
combination = []; // Reset combination
var buttonPositions = [{
x: 1400,
y: 1600
}, {
x: 1600,
y: 1600
}, {
x: 1400,
y: 1800
}, {
x: 1600,
y: 1800
}];
for (var b = 0; b < 4; b++) {
var colorButton = new InteractiveObject('button', buttonPositions[b].x, buttonPositions[b].y, {
buttonId: b + 1,
requiredSequence: correctCombination
});
var graphics = colorButton.children[0];
var colors = [0xff4444, 0x44ff44, 0x4444ff, 0xffff44];
graphics.tint = colors[b];
gameObjects.push(colorButton);
game.addChild(colorButton);
}
}
// Water object that spawns keys when clicked
var water = new InteractiveObject('water', 600, 800, {
hasSpawnedKeys: false
});
gameObjects.push(water);
game.addChild(water);
// Note with different text each loop
var noteTexts = ["Anahtar kapıyı açar...", "Kutu sırları gizliyor...", "Düğmeler ve kollar odayı kontrol ediyor...", "Sıra önemli: Kırmızı, Mavi, Yeşil, Sarı...", "Her hata zaman kaybettirir..."];
var note = new InteractiveObject('note', 800, 1200, {
text: noteTexts[Math.min(currentLoop, noteTexts.length - 1)]
});
gameObjects.push(note);
game.addChild(note);
startTime = Date.now();
isGameActive = true;
showMessage("Döngü " + (currentLoop + 1) + " - Kaçış yolu bulun!");
}
function resetLoop() {
currentLoop++;
storage.currentLoop = currentLoop;
timeLimit = Math.max(30000, baseTimeLimit - currentLoop * 5000); // Update time limit
combination = [];
penalties = 0;
keysCollected = 0;
LK.getSound('reset').play();
LK.effects.flashScreen(0xff0000, 1000);
loopText.setText('Döngü: ' + (currentLoop + 1));
// Reset after a short delay
LK.setTimeout(function () {
initializeRoom();
}, 1000);
}
function victory() {
isGameActive = false;
showMessage("Kapı açıldı! Hangi odaya girmek istiyorsunuz?");
showRoomSelection();
}
function showRoomSelection() {
// Create room selection buttons
var room1Button = new InteractiveObject('button', 1024 - 200, 1366, {
roomId: 1
});
var room2Button = new InteractiveObject('button', 1024 + 200, 1366, {
roomId: 2
});
// Style the buttons differently
room1Button.children[0].tint = 0x00ff00;
room2Button.children[0].tint = 0x0000ff;
gameObjects.push(room1Button);
gameObjects.push(room2Button);
game.addChild(room1Button);
game.addChild(room2Button);
// Add room labels
var room1Label = new Text2('Oda 1', {
size: 40,
fill: '#ffffff'
});
room1Label.anchor.set(0.5, 0.5);
room1Label.x = 1024 - 200;
room1Label.y = 1466;
game.addChild(room1Label);
var room2Label = new Text2('Oda 2', {
size: 40,
fill: '#ffffff'
});
room2Label.anchor.set(0.5, 0.5);
room2Label.x = 1024 + 200;
room2Label.y = 1466;
game.addChild(room2Label);
// Override down function to handle room selection
room1Button.down = function (x, y, obj) {
enterRoom(1);
};
room2Button.down = function (x, y, obj) {
enterRoom(2);
};
}
function enterRoom(roomNumber) {
showMessage("Oda " + roomNumber + " seçildi!");
// Reset progress
storage.currentLoop = 0;
currentLoop = 0;
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
function checkPuzzleCompletion() {
// Progressive difficulty system
if (currentLoop === 0) {
// First loop: just need key
return true;
} else if (currentLoop === 1) {
// Second loop: need button pressed
for (var i = 0; i < gameObjects.length; i++) {
if (gameObjects[i].objectType === 'button' && gameObjects[i].isUsed) {
return true;
}
}
return false;
} else if (currentLoop === 2) {
// Third loop: need button and lever
var buttonPressed = false;
var leverPulled = false;
for (var i = 0; i < gameObjects.length; i++) {
if (gameObjects[i].objectType === 'button' && gameObjects[i].isUsed) {
buttonPressed = true;
}
if (gameObjects[i].objectType === 'lever' && gameObjects[i].isUsed) {
leverPulled = true;
}
}
return buttonPressed && leverPulled;
} else {
// Later loops: need correct button combination
if (combination.length === correctCombination.length) {
for (var i = 0; i < combination.length; i++) {
if (combination[i] !== correctCombination[i]) {
return false;
}
}
return true;
}
return false;
}
}
game.move = function (x, y, obj) {
if (draggedObject) {
draggedObject.x = x;
draggedObject.y = y;
// Check if key is dropped on door
if (draggedObject.objectType === 'key' && door.intersects(draggedObject)) {
if (checkPuzzleCompletion()) {
keysCollected++;
draggedObject.destroy();
// Remove key from gameObjects array
for (var i = 0; i < gameObjects.length; i++) {
if (gameObjects[i] === draggedObject) {
gameObjects.splice(i, 1);
break;
}
}
draggedObject = null;
if (keysCollected >= requiredKeys) {
door.unlock();
showMessage("3 anahtar toplandı! Kapı açılıyor!");
} else {
showMessage(requiredKeys - keysCollected + " anahtar daha gerekiyor!");
}
} else {
showMessage("Önce başka bir şey yapılması gerekiyor...");
}
}
}
};
game.up = function (x, y, obj) {
draggedObject = null;
};
game.down = function (x, y, obj) {
// Handle clicking on objects
for (var i = 0; i < gameObjects.length; i++) {
if (gameObjects[i].objectType === 'button' || gameObjects[i].objectType === 'lever') {
var objPos = gameObjects[i].toGlobal({
x: 0,
y: 0
});
var gamePos = game.toLocal(objPos);
var distance = Math.sqrt(Math.pow(x - gamePos.x, 2) + Math.pow(y - gamePos.y, 2));
if (distance < 100) {
gameObjects[i].use();
break;
}
}
}
};
game.update = function () {
if (!isGameActive) return;
var currentTime = Date.now();
var elapsed = currentTime - startTime;
var remaining = Math.max(0, timeLimit - elapsed);
var timerDisplay = 'Süre: ' + Math.ceil(remaining / 1000) + 's';
if (penalties > 0) {
timerDisplay += ' (Ceza: ' + penalties + ')';
}
timerText.setText(timerDisplay);
if (remaining <= 0) {
isGameActive = false;
showMessage("Süre doldu! Oda sıfırlanıyor...");
LK.setTimeout(function () {
resetLoop();
}, 2000);
}
};
// Initialize first room
initializeRoom(); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var CombinationLock = Container.expand(function (x, y, correctSeq) {
var self = Container.call(this);
self.correctSequence = correctSeq;
self.currentSequence = [];
self.maxLength = 4;
var graphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
graphics.tint = 0x4444ff;
self.x = x;
self.y = y;
self.addToSequence = function (value) {
self.currentSequence.push(value);
if (self.currentSequence.length > self.maxLength) {
self.currentSequence.shift();
}
showMessage("Kombinasyon: " + self.currentSequence.join('-'));
};
self.checkSequence = function () {
if (self.currentSequence.length === self.correctSequence.length) {
for (var i = 0; i < self.currentSequence.length; i++) {
if (self.currentSequence[i] !== self.correctSequence[i]) {
return false;
}
}
return true;
}
return false;
};
self.reset = function () {
self.currentSequence = [];
};
self.down = function (x, y, obj) {
self.addToSequence(1);
};
return self;
});
var Door = Container.expand(function (x, y) {
var self = Container.call(this);
var graphics = self.attachAsset('door', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.isLocked = true;
self.tryOpen = function () {
if (self.isLocked) {
showMessage("Kapı kilitli. Bir anahtara ihtiyacınız var!");
return false;
} else {
showMessage("Kapı açılıyor! Kaçtınız!");
LK.getSound('success').play();
return true;
}
};
self.unlock = function () {
self.isLocked = false;
graphics.tint = 0x00ff00;
LK.effects.flashObject(self, 0xffffff, 1000);
showMessage("Kapı kilidi açıldı!");
};
self.down = function (x, y, obj) {
if (self.tryOpen()) {
victory();
}
};
return self;
});
var InteractiveObject = Container.expand(function (type, x, y, data) {
var self = Container.call(this);
self.objectType = type;
self.objectData = data || {};
self.isExamined = false;
self.isUsed = false;
self.requiredSequence = data ? data.requiredSequence : null;
var graphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.examine = function () {
self.isExamined = true;
LK.effects.flashObject(self, 0xffffff, 500);
LK.getSound('click').play();
if (self.objectType === 'note') {
showMessage("Notta yazıyor: '" + self.objectData.text + "'");
} else if (self.objectType === 'key') {
showMessage("Altın bir anahtar. Bir şeyleri açabilir...");
} else if (self.objectType === 'box') {
if (self.objectData.isLocked && currentLoop > 2) {
showMessage("Kutu kilitli. Doğru sırayla düğmelere basın!");
} else {
showMessage("Ahşap bir kutu. Ağır hissediliyor.");
}
} else if (self.objectType === 'button') {
showMessage("Renkli bir düğme. Sırası önemli olabilir...");
} else if (self.objectType === 'lever') {
showMessage("Metal bir kol. Çekilebilir.");
} else if (self.objectType === 'water') {
if (!self.objectData.hasSpawnedKeys) {
// Spawn 2 keys when water is clicked
var key1 = new InteractiveObject('key', self.x - 100, self.y - 100);
var key2 = new InteractiveObject('key', self.x + 100, self.y - 100);
gameObjects.push(key1);
gameObjects.push(key2);
game.addChild(key1);
game.addChild(key2);
self.objectData.hasSpawnedKeys = true;
showMessage("Sudan 2 anahtar çıktı!");
LK.effects.flashObject(self, 0xffffff, 1000);
} else {
showMessage("Su artık boş görünüyor...");
}
}
};
self.use = function () {
if (self.objectType === 'button') {
// Add penalty for wrong sequence
if (self.requiredSequence && combination.length === 0) {
combination.push(self.objectData.buttonId);
} else if (self.requiredSequence && combination.length < self.requiredSequence.length) {
combination.push(self.objectData.buttonId);
if (combination[combination.length - 1] !== self.requiredSequence[combination.length - 1]) {
penalties++;
startTime -= wrongActionPenalty;
showMessage("Yanlış sıra! " + wrongActionPenalty / 1000 + " saniye ceza!");
LK.effects.flashScreen(0xff0000, 500);
combination = [];
}
}
self.isUsed = !self.isUsed;
graphics.tint = self.isUsed ? 0x00ff00 : 0xff4444;
LK.getSound('click').play();
showMessage(self.isUsed ? "Düğme etkinleştirildi!" : "Düğme devre dışı!");
} else if (self.objectType === 'lever') {
self.isUsed = !self.isUsed;
graphics.rotation = self.isUsed ? Math.PI / 4 : 0;
LK.getSound('click').play();
showMessage(self.isUsed ? "Kol çekildi!" : "Kol sıfırlandı!");
}
};
self.down = function (x, y, obj) {
if (self.objectType === 'key') {
draggedObject = self;
} else {
self.examine();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
var currentLoop = storage.currentLoop || 0;
var baseTimeLimit = 60000; // 60 seconds
var timeLimit = Math.max(30000, baseTimeLimit - currentLoop * 5000); // Reduce by 5s each loop, minimum 30s
var startTime = 0;
var gameObjects = [];
var draggedObject = null;
var door = null;
var messageText = null;
var timerText = null;
var loopText = null;
var isGameActive = true;
var combination = [];
var correctCombination = [];
var wrongActionPenalty = 5000; // 5 second penalty
var penalties = 0;
var keysCollected = 0;
var requiredKeys = 3;
// UI Setup
var titleText = new Text2('Zamanda Sıkışmış Kaçış Odası', {
size: 80,
fill: '#ffffff'
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
timerText = new Text2('Süre: 60s', {
size: 60,
fill: '#ffff00'
});
timerText.anchor.set(1, 0);
LK.gui.topRight.addChild(timerText);
loopText = new Text2('Döngü: ' + (currentLoop + 1), {
size: 50,
fill: '#00ffff'
});
loopText.anchor.set(0, 0);
loopText.x = 120;
LK.gui.topLeft.addChild(loopText);
messageText = new Text2('', {
size: 50,
fill: '#ffffff'
});
messageText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(messageText);
function showMessage(text) {
messageText.setText(text);
messageText.alpha = 1;
tween(messageText, {
alpha: 0
}, {
duration: 3000
});
}
function initializeRoom() {
// Clear existing objects
for (var i = gameObjects.length - 1; i >= 0; i--) {
gameObjects[i].destroy();
}
gameObjects = [];
// Create door
door = new Door(2048 - 200, 2732 / 2);
game.addChild(door);
// Create objects based on loop number
var keyX = 300 + currentLoop * 50 % 400;
var keyY = 2000 + currentLoop * 30 % 200;
var key = new InteractiveObject('key', keyX, keyY);
gameObjects.push(key);
game.addChild(key);
// Box position changes each loop
var boxX = 500 + currentLoop * 100 % 600;
var boxY = 1500 + currentLoop * 80 % 400;
var box = new InteractiveObject('box', boxX, boxY, {
containsKey: currentLoop > 0
});
gameObjects.push(box);
game.addChild(box);
// Button appears after first loop
if (currentLoop > 0) {
var button = new InteractiveObject('button', 1500, 1800, {
buttonId: 1
});
gameObjects.push(button);
game.addChild(button);
}
// Lever appears after second loop
if (currentLoop > 1) {
var lever = new InteractiveObject('lever', 1200, 1600);
gameObjects.push(lever);
game.addChild(lever);
}
// Multiple buttons with combination system (loop 3+)
if (currentLoop > 2) {
correctCombination = [1, 3, 2, 4]; // Correct sequence
combination = []; // Reset combination
var buttonPositions = [{
x: 1400,
y: 1600
}, {
x: 1600,
y: 1600
}, {
x: 1400,
y: 1800
}, {
x: 1600,
y: 1800
}];
for (var b = 0; b < 4; b++) {
var colorButton = new InteractiveObject('button', buttonPositions[b].x, buttonPositions[b].y, {
buttonId: b + 1,
requiredSequence: correctCombination
});
var graphics = colorButton.children[0];
var colors = [0xff4444, 0x44ff44, 0x4444ff, 0xffff44];
graphics.tint = colors[b];
gameObjects.push(colorButton);
game.addChild(colorButton);
}
}
// Water object that spawns keys when clicked
var water = new InteractiveObject('water', 600, 800, {
hasSpawnedKeys: false
});
gameObjects.push(water);
game.addChild(water);
// Note with different text each loop
var noteTexts = ["Anahtar kapıyı açar...", "Kutu sırları gizliyor...", "Düğmeler ve kollar odayı kontrol ediyor...", "Sıra önemli: Kırmızı, Mavi, Yeşil, Sarı...", "Her hata zaman kaybettirir..."];
var note = new InteractiveObject('note', 800, 1200, {
text: noteTexts[Math.min(currentLoop, noteTexts.length - 1)]
});
gameObjects.push(note);
game.addChild(note);
startTime = Date.now();
isGameActive = true;
showMessage("Döngü " + (currentLoop + 1) + " - Kaçış yolu bulun!");
}
function resetLoop() {
currentLoop++;
storage.currentLoop = currentLoop;
timeLimit = Math.max(30000, baseTimeLimit - currentLoop * 5000); // Update time limit
combination = [];
penalties = 0;
keysCollected = 0;
LK.getSound('reset').play();
LK.effects.flashScreen(0xff0000, 1000);
loopText.setText('Döngü: ' + (currentLoop + 1));
// Reset after a short delay
LK.setTimeout(function () {
initializeRoom();
}, 1000);
}
function victory() {
isGameActive = false;
showMessage("Kapı açıldı! Hangi odaya girmek istiyorsunuz?");
showRoomSelection();
}
function showRoomSelection() {
// Create room selection buttons
var room1Button = new InteractiveObject('button', 1024 - 200, 1366, {
roomId: 1
});
var room2Button = new InteractiveObject('button', 1024 + 200, 1366, {
roomId: 2
});
// Style the buttons differently
room1Button.children[0].tint = 0x00ff00;
room2Button.children[0].tint = 0x0000ff;
gameObjects.push(room1Button);
gameObjects.push(room2Button);
game.addChild(room1Button);
game.addChild(room2Button);
// Add room labels
var room1Label = new Text2('Oda 1', {
size: 40,
fill: '#ffffff'
});
room1Label.anchor.set(0.5, 0.5);
room1Label.x = 1024 - 200;
room1Label.y = 1466;
game.addChild(room1Label);
var room2Label = new Text2('Oda 2', {
size: 40,
fill: '#ffffff'
});
room2Label.anchor.set(0.5, 0.5);
room2Label.x = 1024 + 200;
room2Label.y = 1466;
game.addChild(room2Label);
// Override down function to handle room selection
room1Button.down = function (x, y, obj) {
enterRoom(1);
};
room2Button.down = function (x, y, obj) {
enterRoom(2);
};
}
function enterRoom(roomNumber) {
showMessage("Oda " + roomNumber + " seçildi!");
// Reset progress
storage.currentLoop = 0;
currentLoop = 0;
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
function checkPuzzleCompletion() {
// Progressive difficulty system
if (currentLoop === 0) {
// First loop: just need key
return true;
} else if (currentLoop === 1) {
// Second loop: need button pressed
for (var i = 0; i < gameObjects.length; i++) {
if (gameObjects[i].objectType === 'button' && gameObjects[i].isUsed) {
return true;
}
}
return false;
} else if (currentLoop === 2) {
// Third loop: need button and lever
var buttonPressed = false;
var leverPulled = false;
for (var i = 0; i < gameObjects.length; i++) {
if (gameObjects[i].objectType === 'button' && gameObjects[i].isUsed) {
buttonPressed = true;
}
if (gameObjects[i].objectType === 'lever' && gameObjects[i].isUsed) {
leverPulled = true;
}
}
return buttonPressed && leverPulled;
} else {
// Later loops: need correct button combination
if (combination.length === correctCombination.length) {
for (var i = 0; i < combination.length; i++) {
if (combination[i] !== correctCombination[i]) {
return false;
}
}
return true;
}
return false;
}
}
game.move = function (x, y, obj) {
if (draggedObject) {
draggedObject.x = x;
draggedObject.y = y;
// Check if key is dropped on door
if (draggedObject.objectType === 'key' && door.intersects(draggedObject)) {
if (checkPuzzleCompletion()) {
keysCollected++;
draggedObject.destroy();
// Remove key from gameObjects array
for (var i = 0; i < gameObjects.length; i++) {
if (gameObjects[i] === draggedObject) {
gameObjects.splice(i, 1);
break;
}
}
draggedObject = null;
if (keysCollected >= requiredKeys) {
door.unlock();
showMessage("3 anahtar toplandı! Kapı açılıyor!");
} else {
showMessage(requiredKeys - keysCollected + " anahtar daha gerekiyor!");
}
} else {
showMessage("Önce başka bir şey yapılması gerekiyor...");
}
}
}
};
game.up = function (x, y, obj) {
draggedObject = null;
};
game.down = function (x, y, obj) {
// Handle clicking on objects
for (var i = 0; i < gameObjects.length; i++) {
if (gameObjects[i].objectType === 'button' || gameObjects[i].objectType === 'lever') {
var objPos = gameObjects[i].toGlobal({
x: 0,
y: 0
});
var gamePos = game.toLocal(objPos);
var distance = Math.sqrt(Math.pow(x - gamePos.x, 2) + Math.pow(y - gamePos.y, 2));
if (distance < 100) {
gameObjects[i].use();
break;
}
}
}
};
game.update = function () {
if (!isGameActive) return;
var currentTime = Date.now();
var elapsed = currentTime - startTime;
var remaining = Math.max(0, timeLimit - elapsed);
var timerDisplay = 'Süre: ' + Math.ceil(remaining / 1000) + 's';
if (penalties > 0) {
timerDisplay += ' (Ceza: ' + penalties + ')';
}
timerText.setText(timerDisplay);
if (remaining <= 0) {
isGameActive = false;
showMessage("Süre doldu! Oda sıfırlanıyor...");
LK.setTimeout(function () {
resetLoop();
}, 2000);
}
};
// Initialize first room
initializeRoom();