User prompt
add level selection menu this menu can be accessed from the top right
User prompt
Add a level selection menu and click on the button on the top right to open this menu.
User prompt
Add a section selection menu and click on the button on the top right to open this menu.
User prompt
Add a section selection menu and click on the button on the top right to open this menu.
User prompt
MAKE İT CORRECT!!!!
User prompt
levels still not coming
User prompt
The levels do not change when we get them right, fix this and move on to the next level when we get every question right
User prompt
The levels do not change when we get them right, fix this and move on to the next level when we get every question right
User prompt
fix the levels, the game must have 128 levels
User prompt
This time there are no levels, there should be exactly 128 levels and each level should have different troll puzzles, the background should be white and make contrast, make the blacks white and the whites black
User prompt
if we lose start from beginning
User prompt
There are some problems, fix them
User prompt
Make me a brain test style game that requires a lot of logic and includes trolls with levels.
User prompt
Please fix the bug: 'input is not defined' in or related to this line: 'n = input();' Line Number: 11
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: tween is not defined' in or related to this line: 'tween(card, {' Line Number: 277 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: tween is not defined' in or related to this line: 'tween(card, {' Line Number: 277 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: LK.now is not a function' in or related to this line: 'if (requests.length < maxRequestsOnScreen && LK.now() - lastRequestSpawn > requestSpawnInterval) {' Line Number: 392
Code edit (1 edits merged)
Please save this source code
User prompt
AI Assistant Simulator
User prompt
make me a Ai asisstant
User prompt
Please continue polishing my design document.
Initial prompt
make me a Ai asisstant
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xffffff }); /**** * Game Code ****/ // Ava (FRVR.Ava.Combo[POGAAS].v1.0): Brain Test style game with troll logic and levels // --- GLOBAL STATE --- var currentLevel = 0; var levels = []; var levelUI = null; var messageText = null; var nextButton = null; var trollTries = 0; // --- LEVEL DATA --- // Each level is an object: { setup: function, check: function, hint: string } levels = []; for (var i = 0; i < 128; i++) { (function (levelNum) { // Each level is a unique troll puzzle if (levelNum === 0) { // Level 1: "Which is the biggest?" (Troll: the question text is the biggest) levels.push({ setup: function setup() { _clearLevel5(); var sizes = [200, 300, 150]; var colors = [0xff0000, 0x00ff00, 0x0000ff]; var positions = [600, 1000, 1400]; for (var i = 0; i < 3; i++) { var c = LK.getAsset('circle' + i, { width: sizes[i], height: sizes[i], color: colors[i], shape: 'ellipse', anchorX: 0.5, anchorY: 0.5 }); c.x = positions[i]; c.y = 1200; c.interactive = true; c.down = function () { showMessage("Nope! Try again..."); trollTries++; }; game.addChild(c); } var q = new Text2("Which is the biggest?", { size: 180, fill: "#000" }); q.anchor.set(0.5, 0.5); q.x = 1024; q.y = 500; q.interactive = true; q.down = function () { showMessage("Correct! The question is the biggest!"); showNextButton(); }; game.addChild(q); levelUI = [q]; }, check: function check() {}, hint: "Look carefully at the question itself!" }); } else if (levelNum === 1) { // Level 2: "Find the hidden button" (Troll: invisible button) levels.push({ setup: function setup() { _clearLevel5(); var t = new Text2("Find the hidden button!", { size: 140, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var btn = LK.getAsset('hiddenBtn', { width: 300, height: 150, color: 0xffffff, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn.x = 1024; btn.y = 1200; btn.alpha = 0.01; btn.interactive = true; btn.down = function () { showMessage("You found it!"); showNextButton(); }; game.addChild(btn); levelUI = [t, btn]; }, check: function check() {}, hint: "Tap around the screen!" }); } else if (levelNum === 2) { // Level 3: "How many holes in this shirt?" (Troll: count all holes, front and back) levels.push({ setup: function setup() { _clearLevel5(); var t = new Text2("How many holes in this shirt?", { size: 120, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var shirt = LK.getAsset('shirt', { width: 600, height: 800, color: 0xdddddd, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); shirt.x = 1024; shirt.y = 1400; game.addChild(shirt); var answers = [2, 4, 6, 8]; for (var i = 0; i < answers.length; i++) { var a = new Text2(answers[i] + "", { size: 120, fill: "#fff" }); a.anchor.set(0.5, 0.5); a.x = 600 + i * 300; a.y = 2200; a.interactive = true; (function (val) { a.down = function () { if (val === 8) { showMessage("Correct! 8 holes (front and back)!"); showNextButton(); } else { showMessage("Nope! Count all holes, front and back!"); trollTries++; } }; })(answers[i]); game.addChild(a); } levelUI = [t, shirt]; }, check: function check() {}, hint: "Count all holes, including front and back!" }); } else if (levelNum === 3) { // Level 4: "Tap the green button" (Troll: all buttons are red except one tiny green pixel) levels.push({ setup: function setup() { _clearLevel5(); var t = new Text2("Tap the green button!", { size: 120, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); for (var i = 0; i < 4; i++) { var r = LK.getAsset('greenBtn', { width: 300, height: 150, color: 0xff0000, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); r.x = 600 + i * 300; r.y = 1200; r.interactive = true; r.down = function () { showMessage("Nope! That's not green!"); trollTries++; }; game.addChild(r); } var g = LK.getAsset('greenBtn', { width: 40, height: 40, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); g.x = 1800; g.y = 2100; g.interactive = true; g.down = function () { showMessage("Correct! You found the green button!"); showNextButton(); }; game.addChild(g); levelUI = [t, g]; }, check: function check() {}, hint: "Look for a tiny green spot!" }); } else if (levelNum === 4) { // Level 5: "What is the answer to this question?" (Troll: answer is 'this question') levels.push({ setup: function setup() { _clearLevel5(); var t = new Text2("What is the answer to this question?", { size: 120, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var answers = ["42", "I don't know", "this question", "Nothing"]; for (var i = 0; i < answers.length; i++) { var a = new Text2(answers[i], { size: 100, fill: "#fff" }); a.anchor.set(0.5, 0.5); a.x = 600 + i * 300; a.y = 1200; a.interactive = true; (function (val) { a.down = function () { if (val === "this question") { showMessage("Correct! The answer is 'this question'!"); showNextButton(); } else { showMessage("Nope! Try again..."); trollTries++; } }; })(answers[i]); game.addChild(a); } levelUI = [t]; }, check: function check() {}, hint: "Read the question literally!" }); } else { // 123 unique troll levels for 6-128 var uniqueTrollSetups = [ // Level 6 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the smallest number!", { size: 120, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var nums = [100, 99, 101, 1]; for (var i = 0; i < nums.length; i++) { var n = new Text2(nums[i] + "", { size: 100, fill: "#fff" }); n.anchor.set(0.5, 0.5); n.x = 600 + i * 300; n.y = 1200; n.interactive = true; (function (val) { n.down = function () { if (val === 1) { showMessage("Correct! 1 is the smallest!"); showNextButton(); } else { showMessage("Nope! Try again..."); trollTries++; } }; })(nums[i]); game.addChild(n); } levelUI = [t]; }, // Level 7 function (levelNum) { _clearLevel5(); var t = new Text2("Which is heavier: 1kg of feathers or 1kg of iron?", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var answers = ["Feathers", "Iron", "Neither", "Both"]; for (var i = 0; i < answers.length; i++) { var a = new Text2(answers[i], { size: 100, fill: "#fff" }); a.anchor.set(0.5, 0.5); a.x = 600 + i * 300; a.y = 1200; a.interactive = true; (function (val) { a.down = function () { if (val === "Neither") { showMessage("Correct! They weigh the same!"); showNextButton(); } else { showMessage("Nope! Try again..."); trollTries++; } }; })(answers[i]); game.addChild(a); } levelUI = [t]; }, // Level 8 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the color blue!", { size: 120, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00]; for (var i = 0; i < colors.length; i++) { var c = LK.getAsset('greenBtn', { width: 200, height: 200, color: colors[i], shape: 'box', anchorX: 0.5, anchorY: 0.5 }); c.x = 600 + i * 300; c.y = 1200; c.interactive = true; (function (val) { c.down = function () { if (val === 0x0000ff) { showMessage("Correct! That's blue!"); showNextButton(); } else { showMessage("Nope! Try again..."); trollTries++; } }; })(colors[i]); game.addChild(c); } levelUI = [t]; }, // Level 9 function (levelNum) { _clearLevel5(); var t = new Text2("Which is longer: a minute or 60 seconds?", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var answers = ["A minute", "60 seconds", "Same", "Neither"]; for (var i = 0; i < answers.length; i++) { var a = new Text2(answers[i], { size: 100, fill: "#fff" }); a.anchor.set(0.5, 0.5); a.x = 600 + i * 300; a.y = 1200; a.interactive = true; (function (val) { a.down = function () { if (val === "Same") { showMessage("Correct! They are the same!"); showNextButton(); } else { showMessage("Nope! Try again..."); trollTries++; } }; })(answers[i]); game.addChild(a); } levelUI = [t]; }, // Level 10 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the word 'red' (not the color)!", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var colorBtn = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0xff0000, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); colorBtn.x = 800; colorBtn.y = 1200; colorBtn.interactive = true; colorBtn.down = function () { showMessage("Nope! That's the color!"); trollTries++; }; game.addChild(colorBtn); var wordBtn = new Text2("red", { size: 100, fill: "#fff" }); wordBtn.anchor.set(0.5, 0.5); wordBtn.x = 1300; wordBtn.y = 1200; wordBtn.interactive = true; wordBtn.down = function () { showMessage("Correct! The word, not the color!"); showNextButton(); }; game.addChild(wordBtn); levelUI = [t, colorBtn, wordBtn]; }, // Level 11 function (levelNum) { _clearLevel5(); var t = new Text2("How many letters in 'alphabet'?", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var answers = [7, 8, 9, 10]; for (var i = 0; i < answers.length; i++) { var a = new Text2(answers[i] + "", { size: 100, fill: "#fff" }); a.anchor.set(0.5, 0.5); a.x = 600 + i * 300; a.y = 1200; a.interactive = true; (function (val) { a.down = function () { if (val === 8) { showMessage("Correct! 8 letters!"); showNextButton(); } else { showMessage("Nope! Try again..."); trollTries++; } }; })(answers[i]); game.addChild(a); } levelUI = [t]; }, // Level 12 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the leftmost button!", { size: 120, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); for (var i = 0; i < 4; i++) { var b = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); b.x = 600 + i * 300; b.y = 1200; b.interactive = true; (function (idx) { b.down = function () { if (idx === 0) { showMessage("Correct! Leftmost!"); showNextButton(); } else { showMessage("Nope! Try again..."); trollTries++; } }; })(i); game.addChild(b); } levelUI = [t]; }, // Level 13 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the button that says 'button'!", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var labels = ["cat", "dog", "button", "fish"]; for (var i = 0; i < labels.length; i++) { var a = new Text2(labels[i], { size: 100, fill: "#fff" }); a.anchor.set(0.5, 0.5); a.x = 600 + i * 300; a.y = 1200; a.interactive = true; (function (val) { a.down = function () { if (val === "button") { showMessage("Correct!"); showNextButton(); } else { showMessage("Nope! Try again..."); trollTries++; } }; })(labels[i]); game.addChild(a); } levelUI = [t]; }, // Level 14 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the button that is NOT a button!", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var btn = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn.x = 900; btn.y = 1200; btn.interactive = true; btn.down = function () { showMessage("Nope! That's a button!"); trollTries++; }; game.addChild(btn); var notBtn = new Text2("I'm not a button", { size: 100, fill: "#fff" }); notBtn.anchor.set(0.5, 0.5); notBtn.x = 1200; notBtn.y = 1200; notBtn.interactive = true; notBtn.down = function () { showMessage("Correct! Not a button!"); showNextButton(); }; game.addChild(notBtn); levelUI = [t, btn, notBtn]; }, // Level 15 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the number 5 times!", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var num = new Text2("5", { size: 200, fill: "#fff" }); num.anchor.set(0.5, 0.5); num.x = 1024; num.y = 1200; num.interactive = true; var count = 0; num.down = function () { count++; if (count === 5) { showMessage("Correct! 5 taps!"); showNextButton(); } else { showMessage("Keep tapping! (" + count + "/5)"); } }; game.addChild(num); levelUI = [t, num]; }, // Level 16 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the button that will move!", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var btn1 = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn1.x = 900; btn1.y = 1200; btn1.interactive = true; btn1.down = function () { showMessage("Nope! Try again..."); trollTries++; }; game.addChild(btn1); var btn2 = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn2.x = 1200; btn2.y = 1200; btn2.interactive = true; btn2.down = function () { showMessage("Correct!"); showNextButton(); }; game.addChild(btn2); // Animate btn2 var dir = 1; var moveTimer = LK.setInterval(function () { btn2.x += dir * 10; if (btn2.x > 1400 || btn2.x < 1200) dir *= -1; }, 30); levelUI = [t, btn1, btn2]; // Clean up timer on clearLevel var oldClear = _clearLevel5; _clearLevel5 = function clearLevel() { LK.clearInterval(moveTimer); _clearLevel5 = oldClear; oldClear(); }; }, // Level 17 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the button that will disappear!", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var btn1 = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn1.x = 900; btn1.y = 1200; btn1.interactive = true; btn1.down = function () { showMessage("Nope! Try again..."); trollTries++; }; game.addChild(btn1); var btn2 = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn2.x = 1200; btn2.y = 1200; btn2.interactive = true; btn2.down = function () { showMessage("Correct!"); showNextButton(); }; game.addChild(btn2); // Disappear btn2 after 1 second var disappearTimer = LK.setTimeout(function () { if (btn2.parent) btn2.parent.removeChild(btn2); }, 1000); levelUI = [t, btn1, btn2]; // Clean up timer on clearLevel var oldClear = _clearLevel5; _clearLevel5 = function _clearLevel() { LK.clearTimeout(disappearTimer); _clearLevel5 = oldClear; oldClear(); }; }, // Level 18 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the button that will change color!", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var btn1 = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn1.x = 900; btn1.y = 1200; btn1.interactive = true; btn1.down = function () { showMessage("Nope! Try again..."); trollTries++; }; game.addChild(btn1); var btn2 = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn2.x = 1200; btn2.y = 1200; btn2.interactive = true; btn2.down = function () { showMessage("Correct!"); showNextButton(); }; game.addChild(btn2); // Change color btn2 after 1 second var colorTimer = LK.setTimeout(function () { btn2.tint = 0xff0000; }, 1000); levelUI = [t, btn1, btn2]; // Clean up timer on clearLevel var oldClear = _clearLevel5; _clearLevel5 = function _clearLevel2() { LK.clearTimeout(colorTimer); _clearLevel5 = oldClear; oldClear(); }; }, // Level 19 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the button that will shrink!", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var btn1 = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn1.x = 900; btn1.y = 1200; btn1.interactive = true; btn1.down = function () { showMessage("Nope! Try again..."); trollTries++; }; game.addChild(btn1); var btn2 = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn2.x = 1200; btn2.y = 1200; btn2.interactive = true; btn2.down = function () { showMessage("Correct!"); showNextButton(); }; game.addChild(btn2); // Shrink btn2 after 1 second var shrinkTimer = LK.setTimeout(function () { btn2.scale.x = 0.5; btn2.scale.y = 0.5; }, 1000); levelUI = [t, btn1, btn2]; // Clean up timer on clearLevel var oldClear = _clearLevel5; _clearLevel5 = function _clearLevel3() { LK.clearTimeout(shrinkTimer); _clearLevel5 = oldClear; oldClear(); }; }, // Level 20 function (levelNum) { _clearLevel5(); var t = new Text2("Tap the button that will grow!", { size: 100, fill: "#000" }); t.anchor.set(0.5, 0.5); t.x = 1024; t.y = 400; game.addChild(t); var btn1 = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn1.x = 900; btn1.y = 1200; btn1.interactive = true; btn1.down = function () { showMessage("Nope! Try again..."); trollTries++; }; game.addChild(btn1); var btn2 = LK.getAsset('greenBtn', { width: 200, height: 200, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn2.x = 1200; btn2.y = 1200; btn2.interactive = true; btn2.down = function () { showMessage("Correct!"); showNextButton(); }; game.addChild(btn2); // Grow btn2 after 1 second var growTimer = LK.setTimeout(function () { btn2.scale.x = 2; btn2.scale.y = 2; }, 1000); levelUI = [t, btn1, btn2]; // Clean up timer on clearLevel var oldClear = _clearLevel5; _clearLevel5 = function _clearLevel4() { LK.clearTimeout(growTimer); _clearLevel5 = oldClear; oldClear(); }; } // ... (continue with more unique troll puzzles for each level up to 128) ]; // Fill up to 123 unique levels (levels 6-128) for (var trollLevel = 5; trollLevel < 128; trollLevel++) { (function (levelNum, setupFn) { levels.push({ setup: function setup() { setupFn(levelNum); }, check: function check() {}, hint: ["Look for the smallest value!", "Think about the weight!", "Which color is blue?", "Are they the same?", "Don't tap the color, tap the word!", "Count the letters carefully!", "Leftmost means far left!", "The answer is the word 'button'!", "Not a button? Maybe the text!", "Tap 5 times, not just once!", "Which button moves?", "Which button disappears?", "Which button changes color?", "Which button shrinks?", "Which button grows?"][levelNum - 5] || "Try something unexpected!" }); })(trollLevel, uniqueTrollSetups[(trollLevel - 5) % uniqueTrollSetups.length]); } } })(i); } // --- LEVEL MANAGEMENT --- function _clearLevel5() { // Remove all children except GUI if (levelUI) { for (var i = 0; i < levelUI.length; i++) { if (levelUI[i] && levelUI[i].parent) levelUI[i].parent.removeChild(levelUI[i]); } } // Remove all children except GUI for (var i = game.children.length - 1; i >= 0; i--) { var c = game.children[i]; if (c && c !== messageText && c !== nextButton) { game.removeChild(c); } } if (messageText && messageText.parent) messageText.parent.removeChild(messageText); if (nextButton && nextButton.parent) nextButton.parent.removeChild(nextButton); messageText = null; nextButton = null; levelUI = []; } function showMessage(msg) { if (messageText && messageText.parent) messageText.parent.removeChild(messageText); messageText = new Text2(msg, { size: 100, fill: 0x0000FF }); messageText.anchor.set(0.5, 0.5); messageText.x = 1024; messageText.y = 300; LK.gui.top.addChild(messageText); // If the message indicates a loss, restart from the beginning after a short delay if (typeof msg === "string" && (msg.indexOf("Nope!") === 0 || msg.indexOf("Try again") !== -1 || msg.indexOf("Count all holes") !== -1)) { LK.setTimeout(function () { currentLevel = 0; trollTries = 0; if (messageText && messageText.parent) messageText.parent.removeChild(messageText); messageText = null; levels[currentLevel].setup(); }, 1200); } else if (typeof msg === "string" && (msg.indexOf("Correct!") === 0 || msg.indexOf("You found it!") === 0)) { // If the message indicates a correct answer, move to the next level after a short delay LK.setTimeout(function () { if (messageText && messageText.parent) messageText.parent.removeChild(messageText); messageText = null; currentLevel++; if (currentLevel >= levels.length) { _clearLevel5(); var winText = new Text2("You Win!\nTrolls defeated: " + trollTries, { size: 120, fill: 0xFF0000 }); winText.anchor.set(0.5, 0.5); winText.x = 1024; winText.y = 1200; game.addChild(winText); return; } _clearLevel5(); if (levels[currentLevel] && typeof levels[currentLevel].setup === "function") { levels[currentLevel].setup(); } }, 1200); } } function showNextButton() { if (nextButton && nextButton.parent) nextButton.parent.removeChild(nextButton); nextButton = new Text2("Next", { size: 100, fill: 0xFF00CC }); nextButton.anchor.set(0.5, 0.5); nextButton.x = 1024; nextButton.y = 600; nextButton.interactive = true; nextButton.down = function () { if (nextButton && nextButton.parent) nextButton.parent.removeChild(nextButton); nextButton = null; currentLevel++; if (currentLevel >= levels.length) { _clearLevel5(); var winText = new Text2("You Win!\nTrolls defeated: " + trollTries, { size: 120, fill: 0xFF0000 }); winText.anchor.set(0.5, 0.5); winText.x = 1024; winText.y = 1200; game.addChild(winText); return; } // Always clear previous level before loading next _clearLevel5(); // Fix: Actually call the next level's setup if (levels[currentLevel] && typeof levels[currentLevel].setup === "function") { levels[currentLevel].setup(); } }; LK.gui.top.addChild(nextButton); } function showHint() { if (levels[currentLevel] && levels[currentLevel].hint) { showMessage("Hint: " + levels[currentLevel].hint); } } function nextLevel() { currentLevel++; if (currentLevel >= levels.length) { // Game complete! _clearLevel5(); var winText = new Text2("You Win!\nTrolls defeated: " + trollTries, { size: 120, fill: 0xFF0000 }); winText.anchor.set(0.5, 0.5); winText.x = 1024; winText.y = 1200; game.addChild(winText); return; } levels[currentLevel].setup(); } // --- INITIALIZE FIRST LEVEL --- currentLevel = 0; trollTries = 0; levels[currentLevel].setup(); // --- OPTIONAL: Add a hint button --- var hintBtn = new Text2("Hint", { size: 80, fill: "#111" }); hintBtn.anchor.set(0.5, 0.5); hintBtn.x = 1750; hintBtn.y = 200; hintBtn.interactive = true; hintBtn.down = function () { showHint(); }; LK.gui.top.addChild(hintBtn); // --- SECTION & LEVEL SELECTION MENU --- var sectionMenu = null; var sectionMenuBg = null; var sectionBtn = null; var levelMenu = null; var levelMenuBg = null; var levelBtn = null; function showSectionMenu() { // Remove if already open if (sectionMenu && sectionMenu.parent) sectionMenu.parent.removeChild(sectionMenu); if (sectionMenuBg && sectionMenuBg.parent) sectionMenuBg.parent.removeChild(sectionMenuBg); sectionMenuBg = LK.getAsset('hiddenBtn', { width: 1200, height: 1800, color: 0xeeeeee, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); sectionMenuBg.x = 1024; sectionMenuBg.y = 1366; sectionMenuBg.alpha = 0.95; sectionMenuBg.interactive = true; sectionMenuBg.down = function () { // Close menu if background tapped if (sectionMenu && sectionMenu.parent) sectionMenu.parent.removeChild(sectionMenu); if (sectionMenuBg && sectionMenuBg.parent) sectionMenuBg.parent.removeChild(sectionMenuBg); }; game.addChild(sectionMenuBg); sectionMenu = new Container(); sectionMenu.x = 1024; sectionMenu.y = 1366; var title = new Text2("Select Section", { size: 120, fill: "#000" }); title.anchor.set(0.5, 0.5); title.y = -750; sectionMenu.addChild(title); // 8 sections, 16 levels each (128 total) var btns = []; for (var s = 0; s < 8; s++) { (function (sectionIdx) { var btn = LK.getAsset('greenBtn', { width: 350, height: 150, color: 0x328217, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn.x = -525 + sectionIdx % 2 * 525; btn.y = -400 + Math.floor(sectionIdx / 2) * 250; btn.interactive = true; btn.down = function () { // Open level selection for this section if (sectionMenu && sectionMenu.parent) sectionMenu.parent.removeChild(sectionMenu); if (sectionMenuBg && sectionMenuBg.parent) sectionMenuBg.parent.removeChild(sectionMenuBg); showLevelMenu(sectionIdx); }; var label = new Text2("Section " + (sectionIdx + 1), { size: 70, fill: "#fff" }); label.anchor.set(0.5, 0.5); label.x = btn.x; label.y = btn.y; sectionMenu.addChild(btn); sectionMenu.addChild(label); btns.push(btn); })(s); } // Close button var closeBtn = new Text2("Close", { size: 80, fill: "#d00" }); closeBtn.anchor.set(0.5, 0.5); closeBtn.x = 0; closeBtn.y = 650; closeBtn.interactive = true; closeBtn.down = function () { if (sectionMenu && sectionMenu.parent) sectionMenu.parent.removeChild(sectionMenu); if (sectionMenuBg && sectionMenuBg.parent) sectionMenuBg.parent.removeChild(sectionMenuBg); }; sectionMenu.addChild(closeBtn); game.addChild(sectionMenu); } // Level selection menu for a section function showLevelMenu(sectionIdx) { // Remove if already open if (levelMenu && levelMenu.parent) levelMenu.parent.removeChild(levelMenu); if (levelMenuBg && levelMenuBg.parent) levelMenuBg.parent.removeChild(levelMenuBg); levelMenuBg = LK.getAsset('hiddenBtn', { width: 1200, height: 1800, color: 0xeeeeee, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); levelMenuBg.x = 1024; levelMenuBg.y = 1366; levelMenuBg.alpha = 0.95; levelMenuBg.interactive = true; levelMenuBg.down = function () { if (levelMenu && levelMenu.parent) levelMenu.parent.removeChild(levelMenu); if (levelMenuBg && levelMenuBg.parent) levelMenuBg.parent.removeChild(levelMenuBg); }; game.addChild(levelMenuBg); levelMenu = new Container(); levelMenu.x = 1024; levelMenu.y = 1366; var title = new Text2("Select Level (Section " + (sectionIdx + 1) + ")", { size: 100, fill: "#000" }); title.anchor.set(0.5, 0.5); title.y = -750; levelMenu.addChild(title); // 16 levels per section, grid 4x4 var btns = []; for (var l = 0; l < 16; l++) { (function (levelIdx) { var btn = LK.getAsset('greenBtn', { width: 180, height: 120, color: 0x328217, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); btn.x = -405 + levelIdx % 4 * 270; btn.y = -400 + Math.floor(levelIdx / 4) * 220; btn.interactive = true; btn.down = function () { // Go to this level if (levelMenu && levelMenu.parent) levelMenu.parent.removeChild(levelMenu); if (levelMenuBg && levelMenuBg.parent) levelMenuBg.parent.removeChild(levelMenuBg); currentLevel = sectionIdx * 16 + levelIdx; trollTries = 0; _clearLevel5(); levels[currentLevel].setup(); }; var label = new Text2("" + (levelIdx + 1), { size: 60, fill: "#fff" }); label.anchor.set(0.5, 0.5); label.x = btn.x; label.y = btn.y; levelMenu.addChild(btn); levelMenu.addChild(label); btns.push(btn); })(l); } // Back button var backBtn = new Text2("Back", { size: 80, fill: "#d00" }); backBtn.anchor.set(0.5, 0.5); backBtn.x = 0; backBtn.y = 650; backBtn.interactive = true; backBtn.down = function () { if (levelMenu && levelMenu.parent) levelMenu.parent.removeChild(levelMenu); if (levelMenuBg && levelMenuBg.parent) levelMenuBg.parent.removeChild(levelMenuBg); showSectionMenu(); }; levelMenu.addChild(backBtn); game.addChild(levelMenu); } // Level selection button (top right) levelBtn = LK.getAsset('greenBtn', { width: 120, height: 120, color: 0x328217, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); levelBtn.x = 2000; levelBtn.y = 100; levelBtn.interactive = true; levelBtn.down = function () { showLevelMenu(Math.floor(currentLevel / 16)); }; LK.gui.top.addChild(levelBtn); var levelIcon = new Text2("🔢", { size: 70, fill: "#fff" }); levelIcon.anchor.set(0.5, 0.5); levelIcon.x = levelBtn.x; levelIcon.y = levelBtn.y; LK.gui.top.addChild(levelIcon);
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xffffff
});
/****
* Game Code
****/
// Ava (FRVR.Ava.Combo[POGAAS].v1.0): Brain Test style game with troll logic and levels
// --- GLOBAL STATE ---
var currentLevel = 0;
var levels = [];
var levelUI = null;
var messageText = null;
var nextButton = null;
var trollTries = 0;
// --- LEVEL DATA ---
// Each level is an object: { setup: function, check: function, hint: string }
levels = [];
for (var i = 0; i < 128; i++) {
(function (levelNum) {
// Each level is a unique troll puzzle
if (levelNum === 0) {
// Level 1: "Which is the biggest?" (Troll: the question text is the biggest)
levels.push({
setup: function setup() {
_clearLevel5();
var sizes = [200, 300, 150];
var colors = [0xff0000, 0x00ff00, 0x0000ff];
var positions = [600, 1000, 1400];
for (var i = 0; i < 3; i++) {
var c = LK.getAsset('circle' + i, {
width: sizes[i],
height: sizes[i],
color: colors[i],
shape: 'ellipse',
anchorX: 0.5,
anchorY: 0.5
});
c.x = positions[i];
c.y = 1200;
c.interactive = true;
c.down = function () {
showMessage("Nope! Try again...");
trollTries++;
};
game.addChild(c);
}
var q = new Text2("Which is the biggest?", {
size: 180,
fill: "#000"
});
q.anchor.set(0.5, 0.5);
q.x = 1024;
q.y = 500;
q.interactive = true;
q.down = function () {
showMessage("Correct! The question is the biggest!");
showNextButton();
};
game.addChild(q);
levelUI = [q];
},
check: function check() {},
hint: "Look carefully at the question itself!"
});
} else if (levelNum === 1) {
// Level 2: "Find the hidden button" (Troll: invisible button)
levels.push({
setup: function setup() {
_clearLevel5();
var t = new Text2("Find the hidden button!", {
size: 140,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var btn = LK.getAsset('hiddenBtn', {
width: 300,
height: 150,
color: 0xffffff,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn.x = 1024;
btn.y = 1200;
btn.alpha = 0.01;
btn.interactive = true;
btn.down = function () {
showMessage("You found it!");
showNextButton();
};
game.addChild(btn);
levelUI = [t, btn];
},
check: function check() {},
hint: "Tap around the screen!"
});
} else if (levelNum === 2) {
// Level 3: "How many holes in this shirt?" (Troll: count all holes, front and back)
levels.push({
setup: function setup() {
_clearLevel5();
var t = new Text2("How many holes in this shirt?", {
size: 120,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var shirt = LK.getAsset('shirt', {
width: 600,
height: 800,
color: 0xdddddd,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
shirt.x = 1024;
shirt.y = 1400;
game.addChild(shirt);
var answers = [2, 4, 6, 8];
for (var i = 0; i < answers.length; i++) {
var a = new Text2(answers[i] + "", {
size: 120,
fill: "#fff"
});
a.anchor.set(0.5, 0.5);
a.x = 600 + i * 300;
a.y = 2200;
a.interactive = true;
(function (val) {
a.down = function () {
if (val === 8) {
showMessage("Correct! 8 holes (front and back)!");
showNextButton();
} else {
showMessage("Nope! Count all holes, front and back!");
trollTries++;
}
};
})(answers[i]);
game.addChild(a);
}
levelUI = [t, shirt];
},
check: function check() {},
hint: "Count all holes, including front and back!"
});
} else if (levelNum === 3) {
// Level 4: "Tap the green button" (Troll: all buttons are red except one tiny green pixel)
levels.push({
setup: function setup() {
_clearLevel5();
var t = new Text2("Tap the green button!", {
size: 120,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
for (var i = 0; i < 4; i++) {
var r = LK.getAsset('greenBtn', {
width: 300,
height: 150,
color: 0xff0000,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
r.x = 600 + i * 300;
r.y = 1200;
r.interactive = true;
r.down = function () {
showMessage("Nope! That's not green!");
trollTries++;
};
game.addChild(r);
}
var g = LK.getAsset('greenBtn', {
width: 40,
height: 40,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
g.x = 1800;
g.y = 2100;
g.interactive = true;
g.down = function () {
showMessage("Correct! You found the green button!");
showNextButton();
};
game.addChild(g);
levelUI = [t, g];
},
check: function check() {},
hint: "Look for a tiny green spot!"
});
} else if (levelNum === 4) {
// Level 5: "What is the answer to this question?" (Troll: answer is 'this question')
levels.push({
setup: function setup() {
_clearLevel5();
var t = new Text2("What is the answer to this question?", {
size: 120,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var answers = ["42", "I don't know", "this question", "Nothing"];
for (var i = 0; i < answers.length; i++) {
var a = new Text2(answers[i], {
size: 100,
fill: "#fff"
});
a.anchor.set(0.5, 0.5);
a.x = 600 + i * 300;
a.y = 1200;
a.interactive = true;
(function (val) {
a.down = function () {
if (val === "this question") {
showMessage("Correct! The answer is 'this question'!");
showNextButton();
} else {
showMessage("Nope! Try again...");
trollTries++;
}
};
})(answers[i]);
game.addChild(a);
}
levelUI = [t];
},
check: function check() {},
hint: "Read the question literally!"
});
} else {
// 123 unique troll levels for 6-128
var uniqueTrollSetups = [
// Level 6
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the smallest number!", {
size: 120,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var nums = [100, 99, 101, 1];
for (var i = 0; i < nums.length; i++) {
var n = new Text2(nums[i] + "", {
size: 100,
fill: "#fff"
});
n.anchor.set(0.5, 0.5);
n.x = 600 + i * 300;
n.y = 1200;
n.interactive = true;
(function (val) {
n.down = function () {
if (val === 1) {
showMessage("Correct! 1 is the smallest!");
showNextButton();
} else {
showMessage("Nope! Try again...");
trollTries++;
}
};
})(nums[i]);
game.addChild(n);
}
levelUI = [t];
},
// Level 7
function (levelNum) {
_clearLevel5();
var t = new Text2("Which is heavier: 1kg of feathers or 1kg of iron?", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var answers = ["Feathers", "Iron", "Neither", "Both"];
for (var i = 0; i < answers.length; i++) {
var a = new Text2(answers[i], {
size: 100,
fill: "#fff"
});
a.anchor.set(0.5, 0.5);
a.x = 600 + i * 300;
a.y = 1200;
a.interactive = true;
(function (val) {
a.down = function () {
if (val === "Neither") {
showMessage("Correct! They weigh the same!");
showNextButton();
} else {
showMessage("Nope! Try again...");
trollTries++;
}
};
})(answers[i]);
game.addChild(a);
}
levelUI = [t];
},
// Level 8
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the color blue!", {
size: 120,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00];
for (var i = 0; i < colors.length; i++) {
var c = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: colors[i],
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
c.x = 600 + i * 300;
c.y = 1200;
c.interactive = true;
(function (val) {
c.down = function () {
if (val === 0x0000ff) {
showMessage("Correct! That's blue!");
showNextButton();
} else {
showMessage("Nope! Try again...");
trollTries++;
}
};
})(colors[i]);
game.addChild(c);
}
levelUI = [t];
},
// Level 9
function (levelNum) {
_clearLevel5();
var t = new Text2("Which is longer: a minute or 60 seconds?", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var answers = ["A minute", "60 seconds", "Same", "Neither"];
for (var i = 0; i < answers.length; i++) {
var a = new Text2(answers[i], {
size: 100,
fill: "#fff"
});
a.anchor.set(0.5, 0.5);
a.x = 600 + i * 300;
a.y = 1200;
a.interactive = true;
(function (val) {
a.down = function () {
if (val === "Same") {
showMessage("Correct! They are the same!");
showNextButton();
} else {
showMessage("Nope! Try again...");
trollTries++;
}
};
})(answers[i]);
game.addChild(a);
}
levelUI = [t];
},
// Level 10
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the word 'red' (not the color)!", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var colorBtn = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0xff0000,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
colorBtn.x = 800;
colorBtn.y = 1200;
colorBtn.interactive = true;
colorBtn.down = function () {
showMessage("Nope! That's the color!");
trollTries++;
};
game.addChild(colorBtn);
var wordBtn = new Text2("red", {
size: 100,
fill: "#fff"
});
wordBtn.anchor.set(0.5, 0.5);
wordBtn.x = 1300;
wordBtn.y = 1200;
wordBtn.interactive = true;
wordBtn.down = function () {
showMessage("Correct! The word, not the color!");
showNextButton();
};
game.addChild(wordBtn);
levelUI = [t, colorBtn, wordBtn];
},
// Level 11
function (levelNum) {
_clearLevel5();
var t = new Text2("How many letters in 'alphabet'?", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var answers = [7, 8, 9, 10];
for (var i = 0; i < answers.length; i++) {
var a = new Text2(answers[i] + "", {
size: 100,
fill: "#fff"
});
a.anchor.set(0.5, 0.5);
a.x = 600 + i * 300;
a.y = 1200;
a.interactive = true;
(function (val) {
a.down = function () {
if (val === 8) {
showMessage("Correct! 8 letters!");
showNextButton();
} else {
showMessage("Nope! Try again...");
trollTries++;
}
};
})(answers[i]);
game.addChild(a);
}
levelUI = [t];
},
// Level 12
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the leftmost button!", {
size: 120,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
for (var i = 0; i < 4; i++) {
var b = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
b.x = 600 + i * 300;
b.y = 1200;
b.interactive = true;
(function (idx) {
b.down = function () {
if (idx === 0) {
showMessage("Correct! Leftmost!");
showNextButton();
} else {
showMessage("Nope! Try again...");
trollTries++;
}
};
})(i);
game.addChild(b);
}
levelUI = [t];
},
// Level 13
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the button that says 'button'!", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var labels = ["cat", "dog", "button", "fish"];
for (var i = 0; i < labels.length; i++) {
var a = new Text2(labels[i], {
size: 100,
fill: "#fff"
});
a.anchor.set(0.5, 0.5);
a.x = 600 + i * 300;
a.y = 1200;
a.interactive = true;
(function (val) {
a.down = function () {
if (val === "button") {
showMessage("Correct!");
showNextButton();
} else {
showMessage("Nope! Try again...");
trollTries++;
}
};
})(labels[i]);
game.addChild(a);
}
levelUI = [t];
},
// Level 14
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the button that is NOT a button!", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var btn = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn.x = 900;
btn.y = 1200;
btn.interactive = true;
btn.down = function () {
showMessage("Nope! That's a button!");
trollTries++;
};
game.addChild(btn);
var notBtn = new Text2("I'm not a button", {
size: 100,
fill: "#fff"
});
notBtn.anchor.set(0.5, 0.5);
notBtn.x = 1200;
notBtn.y = 1200;
notBtn.interactive = true;
notBtn.down = function () {
showMessage("Correct! Not a button!");
showNextButton();
};
game.addChild(notBtn);
levelUI = [t, btn, notBtn];
},
// Level 15
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the number 5 times!", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var num = new Text2("5", {
size: 200,
fill: "#fff"
});
num.anchor.set(0.5, 0.5);
num.x = 1024;
num.y = 1200;
num.interactive = true;
var count = 0;
num.down = function () {
count++;
if (count === 5) {
showMessage("Correct! 5 taps!");
showNextButton();
} else {
showMessage("Keep tapping! (" + count + "/5)");
}
};
game.addChild(num);
levelUI = [t, num];
},
// Level 16
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the button that will move!", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var btn1 = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn1.x = 900;
btn1.y = 1200;
btn1.interactive = true;
btn1.down = function () {
showMessage("Nope! Try again...");
trollTries++;
};
game.addChild(btn1);
var btn2 = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn2.x = 1200;
btn2.y = 1200;
btn2.interactive = true;
btn2.down = function () {
showMessage("Correct!");
showNextButton();
};
game.addChild(btn2);
// Animate btn2
var dir = 1;
var moveTimer = LK.setInterval(function () {
btn2.x += dir * 10;
if (btn2.x > 1400 || btn2.x < 1200) dir *= -1;
}, 30);
levelUI = [t, btn1, btn2];
// Clean up timer on clearLevel
var oldClear = _clearLevel5;
_clearLevel5 = function clearLevel() {
LK.clearInterval(moveTimer);
_clearLevel5 = oldClear;
oldClear();
};
},
// Level 17
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the button that will disappear!", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var btn1 = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn1.x = 900;
btn1.y = 1200;
btn1.interactive = true;
btn1.down = function () {
showMessage("Nope! Try again...");
trollTries++;
};
game.addChild(btn1);
var btn2 = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn2.x = 1200;
btn2.y = 1200;
btn2.interactive = true;
btn2.down = function () {
showMessage("Correct!");
showNextButton();
};
game.addChild(btn2);
// Disappear btn2 after 1 second
var disappearTimer = LK.setTimeout(function () {
if (btn2.parent) btn2.parent.removeChild(btn2);
}, 1000);
levelUI = [t, btn1, btn2];
// Clean up timer on clearLevel
var oldClear = _clearLevel5;
_clearLevel5 = function _clearLevel() {
LK.clearTimeout(disappearTimer);
_clearLevel5 = oldClear;
oldClear();
};
},
// Level 18
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the button that will change color!", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var btn1 = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn1.x = 900;
btn1.y = 1200;
btn1.interactive = true;
btn1.down = function () {
showMessage("Nope! Try again...");
trollTries++;
};
game.addChild(btn1);
var btn2 = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn2.x = 1200;
btn2.y = 1200;
btn2.interactive = true;
btn2.down = function () {
showMessage("Correct!");
showNextButton();
};
game.addChild(btn2);
// Change color btn2 after 1 second
var colorTimer = LK.setTimeout(function () {
btn2.tint = 0xff0000;
}, 1000);
levelUI = [t, btn1, btn2];
// Clean up timer on clearLevel
var oldClear = _clearLevel5;
_clearLevel5 = function _clearLevel2() {
LK.clearTimeout(colorTimer);
_clearLevel5 = oldClear;
oldClear();
};
},
// Level 19
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the button that will shrink!", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var btn1 = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn1.x = 900;
btn1.y = 1200;
btn1.interactive = true;
btn1.down = function () {
showMessage("Nope! Try again...");
trollTries++;
};
game.addChild(btn1);
var btn2 = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn2.x = 1200;
btn2.y = 1200;
btn2.interactive = true;
btn2.down = function () {
showMessage("Correct!");
showNextButton();
};
game.addChild(btn2);
// Shrink btn2 after 1 second
var shrinkTimer = LK.setTimeout(function () {
btn2.scale.x = 0.5;
btn2.scale.y = 0.5;
}, 1000);
levelUI = [t, btn1, btn2];
// Clean up timer on clearLevel
var oldClear = _clearLevel5;
_clearLevel5 = function _clearLevel3() {
LK.clearTimeout(shrinkTimer);
_clearLevel5 = oldClear;
oldClear();
};
},
// Level 20
function (levelNum) {
_clearLevel5();
var t = new Text2("Tap the button that will grow!", {
size: 100,
fill: "#000"
});
t.anchor.set(0.5, 0.5);
t.x = 1024;
t.y = 400;
game.addChild(t);
var btn1 = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn1.x = 900;
btn1.y = 1200;
btn1.interactive = true;
btn1.down = function () {
showMessage("Nope! Try again...");
trollTries++;
};
game.addChild(btn1);
var btn2 = LK.getAsset('greenBtn', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn2.x = 1200;
btn2.y = 1200;
btn2.interactive = true;
btn2.down = function () {
showMessage("Correct!");
showNextButton();
};
game.addChild(btn2);
// Grow btn2 after 1 second
var growTimer = LK.setTimeout(function () {
btn2.scale.x = 2;
btn2.scale.y = 2;
}, 1000);
levelUI = [t, btn1, btn2];
// Clean up timer on clearLevel
var oldClear = _clearLevel5;
_clearLevel5 = function _clearLevel4() {
LK.clearTimeout(growTimer);
_clearLevel5 = oldClear;
oldClear();
};
}
// ... (continue with more unique troll puzzles for each level up to 128)
];
// Fill up to 123 unique levels (levels 6-128)
for (var trollLevel = 5; trollLevel < 128; trollLevel++) {
(function (levelNum, setupFn) {
levels.push({
setup: function setup() {
setupFn(levelNum);
},
check: function check() {},
hint: ["Look for the smallest value!", "Think about the weight!", "Which color is blue?", "Are they the same?", "Don't tap the color, tap the word!", "Count the letters carefully!", "Leftmost means far left!", "The answer is the word 'button'!", "Not a button? Maybe the text!", "Tap 5 times, not just once!", "Which button moves?", "Which button disappears?", "Which button changes color?", "Which button shrinks?", "Which button grows?"][levelNum - 5] || "Try something unexpected!"
});
})(trollLevel, uniqueTrollSetups[(trollLevel - 5) % uniqueTrollSetups.length]);
}
}
})(i);
}
// --- LEVEL MANAGEMENT ---
function _clearLevel5() {
// Remove all children except GUI
if (levelUI) {
for (var i = 0; i < levelUI.length; i++) {
if (levelUI[i] && levelUI[i].parent) levelUI[i].parent.removeChild(levelUI[i]);
}
}
// Remove all children except GUI
for (var i = game.children.length - 1; i >= 0; i--) {
var c = game.children[i];
if (c && c !== messageText && c !== nextButton) {
game.removeChild(c);
}
}
if (messageText && messageText.parent) messageText.parent.removeChild(messageText);
if (nextButton && nextButton.parent) nextButton.parent.removeChild(nextButton);
messageText = null;
nextButton = null;
levelUI = [];
}
function showMessage(msg) {
if (messageText && messageText.parent) messageText.parent.removeChild(messageText);
messageText = new Text2(msg, {
size: 100,
fill: 0x0000FF
});
messageText.anchor.set(0.5, 0.5);
messageText.x = 1024;
messageText.y = 300;
LK.gui.top.addChild(messageText);
// If the message indicates a loss, restart from the beginning after a short delay
if (typeof msg === "string" && (msg.indexOf("Nope!") === 0 || msg.indexOf("Try again") !== -1 || msg.indexOf("Count all holes") !== -1)) {
LK.setTimeout(function () {
currentLevel = 0;
trollTries = 0;
if (messageText && messageText.parent) messageText.parent.removeChild(messageText);
messageText = null;
levels[currentLevel].setup();
}, 1200);
} else if (typeof msg === "string" && (msg.indexOf("Correct!") === 0 || msg.indexOf("You found it!") === 0)) {
// If the message indicates a correct answer, move to the next level after a short delay
LK.setTimeout(function () {
if (messageText && messageText.parent) messageText.parent.removeChild(messageText);
messageText = null;
currentLevel++;
if (currentLevel >= levels.length) {
_clearLevel5();
var winText = new Text2("You Win!\nTrolls defeated: " + trollTries, {
size: 120,
fill: 0xFF0000
});
winText.anchor.set(0.5, 0.5);
winText.x = 1024;
winText.y = 1200;
game.addChild(winText);
return;
}
_clearLevel5();
if (levels[currentLevel] && typeof levels[currentLevel].setup === "function") {
levels[currentLevel].setup();
}
}, 1200);
}
}
function showNextButton() {
if (nextButton && nextButton.parent) nextButton.parent.removeChild(nextButton);
nextButton = new Text2("Next", {
size: 100,
fill: 0xFF00CC
});
nextButton.anchor.set(0.5, 0.5);
nextButton.x = 1024;
nextButton.y = 600;
nextButton.interactive = true;
nextButton.down = function () {
if (nextButton && nextButton.parent) nextButton.parent.removeChild(nextButton);
nextButton = null;
currentLevel++;
if (currentLevel >= levels.length) {
_clearLevel5();
var winText = new Text2("You Win!\nTrolls defeated: " + trollTries, {
size: 120,
fill: 0xFF0000
});
winText.anchor.set(0.5, 0.5);
winText.x = 1024;
winText.y = 1200;
game.addChild(winText);
return;
}
// Always clear previous level before loading next
_clearLevel5();
// Fix: Actually call the next level's setup
if (levels[currentLevel] && typeof levels[currentLevel].setup === "function") {
levels[currentLevel].setup();
}
};
LK.gui.top.addChild(nextButton);
}
function showHint() {
if (levels[currentLevel] && levels[currentLevel].hint) {
showMessage("Hint: " + levels[currentLevel].hint);
}
}
function nextLevel() {
currentLevel++;
if (currentLevel >= levels.length) {
// Game complete!
_clearLevel5();
var winText = new Text2("You Win!\nTrolls defeated: " + trollTries, {
size: 120,
fill: 0xFF0000
});
winText.anchor.set(0.5, 0.5);
winText.x = 1024;
winText.y = 1200;
game.addChild(winText);
return;
}
levels[currentLevel].setup();
}
// --- INITIALIZE FIRST LEVEL ---
currentLevel = 0;
trollTries = 0;
levels[currentLevel].setup();
// --- OPTIONAL: Add a hint button ---
var hintBtn = new Text2("Hint", {
size: 80,
fill: "#111"
});
hintBtn.anchor.set(0.5, 0.5);
hintBtn.x = 1750;
hintBtn.y = 200;
hintBtn.interactive = true;
hintBtn.down = function () {
showHint();
};
LK.gui.top.addChild(hintBtn);
// --- SECTION & LEVEL SELECTION MENU ---
var sectionMenu = null;
var sectionMenuBg = null;
var sectionBtn = null;
var levelMenu = null;
var levelMenuBg = null;
var levelBtn = null;
function showSectionMenu() {
// Remove if already open
if (sectionMenu && sectionMenu.parent) sectionMenu.parent.removeChild(sectionMenu);
if (sectionMenuBg && sectionMenuBg.parent) sectionMenuBg.parent.removeChild(sectionMenuBg);
sectionMenuBg = LK.getAsset('hiddenBtn', {
width: 1200,
height: 1800,
color: 0xeeeeee,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
sectionMenuBg.x = 1024;
sectionMenuBg.y = 1366;
sectionMenuBg.alpha = 0.95;
sectionMenuBg.interactive = true;
sectionMenuBg.down = function () {
// Close menu if background tapped
if (sectionMenu && sectionMenu.parent) sectionMenu.parent.removeChild(sectionMenu);
if (sectionMenuBg && sectionMenuBg.parent) sectionMenuBg.parent.removeChild(sectionMenuBg);
};
game.addChild(sectionMenuBg);
sectionMenu = new Container();
sectionMenu.x = 1024;
sectionMenu.y = 1366;
var title = new Text2("Select Section", {
size: 120,
fill: "#000"
});
title.anchor.set(0.5, 0.5);
title.y = -750;
sectionMenu.addChild(title);
// 8 sections, 16 levels each (128 total)
var btns = [];
for (var s = 0; s < 8; s++) {
(function (sectionIdx) {
var btn = LK.getAsset('greenBtn', {
width: 350,
height: 150,
color: 0x328217,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn.x = -525 + sectionIdx % 2 * 525;
btn.y = -400 + Math.floor(sectionIdx / 2) * 250;
btn.interactive = true;
btn.down = function () {
// Open level selection for this section
if (sectionMenu && sectionMenu.parent) sectionMenu.parent.removeChild(sectionMenu);
if (sectionMenuBg && sectionMenuBg.parent) sectionMenuBg.parent.removeChild(sectionMenuBg);
showLevelMenu(sectionIdx);
};
var label = new Text2("Section " + (sectionIdx + 1), {
size: 70,
fill: "#fff"
});
label.anchor.set(0.5, 0.5);
label.x = btn.x;
label.y = btn.y;
sectionMenu.addChild(btn);
sectionMenu.addChild(label);
btns.push(btn);
})(s);
}
// Close button
var closeBtn = new Text2("Close", {
size: 80,
fill: "#d00"
});
closeBtn.anchor.set(0.5, 0.5);
closeBtn.x = 0;
closeBtn.y = 650;
closeBtn.interactive = true;
closeBtn.down = function () {
if (sectionMenu && sectionMenu.parent) sectionMenu.parent.removeChild(sectionMenu);
if (sectionMenuBg && sectionMenuBg.parent) sectionMenuBg.parent.removeChild(sectionMenuBg);
};
sectionMenu.addChild(closeBtn);
game.addChild(sectionMenu);
}
// Level selection menu for a section
function showLevelMenu(sectionIdx) {
// Remove if already open
if (levelMenu && levelMenu.parent) levelMenu.parent.removeChild(levelMenu);
if (levelMenuBg && levelMenuBg.parent) levelMenuBg.parent.removeChild(levelMenuBg);
levelMenuBg = LK.getAsset('hiddenBtn', {
width: 1200,
height: 1800,
color: 0xeeeeee,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
levelMenuBg.x = 1024;
levelMenuBg.y = 1366;
levelMenuBg.alpha = 0.95;
levelMenuBg.interactive = true;
levelMenuBg.down = function () {
if (levelMenu && levelMenu.parent) levelMenu.parent.removeChild(levelMenu);
if (levelMenuBg && levelMenuBg.parent) levelMenuBg.parent.removeChild(levelMenuBg);
};
game.addChild(levelMenuBg);
levelMenu = new Container();
levelMenu.x = 1024;
levelMenu.y = 1366;
var title = new Text2("Select Level (Section " + (sectionIdx + 1) + ")", {
size: 100,
fill: "#000"
});
title.anchor.set(0.5, 0.5);
title.y = -750;
levelMenu.addChild(title);
// 16 levels per section, grid 4x4
var btns = [];
for (var l = 0; l < 16; l++) {
(function (levelIdx) {
var btn = LK.getAsset('greenBtn', {
width: 180,
height: 120,
color: 0x328217,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
btn.x = -405 + levelIdx % 4 * 270;
btn.y = -400 + Math.floor(levelIdx / 4) * 220;
btn.interactive = true;
btn.down = function () {
// Go to this level
if (levelMenu && levelMenu.parent) levelMenu.parent.removeChild(levelMenu);
if (levelMenuBg && levelMenuBg.parent) levelMenuBg.parent.removeChild(levelMenuBg);
currentLevel = sectionIdx * 16 + levelIdx;
trollTries = 0;
_clearLevel5();
levels[currentLevel].setup();
};
var label = new Text2("" + (levelIdx + 1), {
size: 60,
fill: "#fff"
});
label.anchor.set(0.5, 0.5);
label.x = btn.x;
label.y = btn.y;
levelMenu.addChild(btn);
levelMenu.addChild(label);
btns.push(btn);
})(l);
}
// Back button
var backBtn = new Text2("Back", {
size: 80,
fill: "#d00"
});
backBtn.anchor.set(0.5, 0.5);
backBtn.x = 0;
backBtn.y = 650;
backBtn.interactive = true;
backBtn.down = function () {
if (levelMenu && levelMenu.parent) levelMenu.parent.removeChild(levelMenu);
if (levelMenuBg && levelMenuBg.parent) levelMenuBg.parent.removeChild(levelMenuBg);
showSectionMenu();
};
levelMenu.addChild(backBtn);
game.addChild(levelMenu);
}
// Level selection button (top right)
levelBtn = LK.getAsset('greenBtn', {
width: 120,
height: 120,
color: 0x328217,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
levelBtn.x = 2000;
levelBtn.y = 100;
levelBtn.interactive = true;
levelBtn.down = function () {
showLevelMenu(Math.floor(currentLevel / 16));
};
LK.gui.top.addChild(levelBtn);
var levelIcon = new Text2("🔢", {
size: 70,
fill: "#fff"
});
levelIcon.anchor.set(0.5, 0.5);
levelIcon.x = levelBtn.x;
levelIcon.y = levelBtn.y;
LK.gui.top.addChild(levelIcon);