User prompt
now they are all dark
User prompt
when a button is clicked on one question, it should not be darkended for the next
User prompt
Please fix the bug: 'Uncaught TypeError: LK.effects.confetti is not a function' in or related to this line: 'LK.effects.confetti({' Line Number: 697
User prompt
can we make the UI more fun? Ideally some animations when you guess correct - like confetti
User prompt
okay. we need at least 100
Code edit (1 edits merged)
Please save this source code
User prompt
Game Studio Guessr
Initial prompt
Hi - i want to create a quiz game. It can pretty much be any format but the questions will be about guessing what studio made waht gaem
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // OptionButton: A tappable answer button var OptionButton = Container.expand(function () { var self = Container.call(this); // Button background var bg = self.attachAsset('optionBg', { width: 1200, height: 180, color: 0x2d2d2d, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); // Option text var txt = new Text2('', { size: 70, fill: 0xFFFFFF }); txt.anchor.set(0.5, 0.5); self.addChild(txt); // Store callback self._onSelect = null; // Set option text self.setText = function (t) { txt.setText(t); }; // Set callback self.setCallback = function (cb) { self._onSelect = cb; }; // Enable/disable button self.setEnabled = function (enabled) { self.interactive = enabled; self.alpha = enabled ? 1 : 0.5; }; // Handle tap self.down = function (x, y, obj) { if (self._onSelect) self._onSelect(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x181c24 }); /**** * Game Code ****/ // --- Quiz Data --- var quizData = [{ game: "The Legend of Zelda: Breath of the Wild", studio: "Nintendo", options: ["Nintendo", "Ubisoft", "Rockstar Games", "Valve"] }, { game: "The Witcher 3: Wild Hunt", studio: "CD Projekt Red", options: ["CD Projekt Red", "Bethesda", "Square Enix", "Capcom"] }, { game: "Halo: Combat Evolved", studio: "Bungie", options: ["Bungie", "343 Industries", "EA", "Insomniac Games"] }, { game: "God of War (2018)", studio: "Santa Monica Studio", options: ["Santa Monica Studio", "Naughty Dog", "FromSoftware", "Remedy"] }, { game: "Grand Theft Auto V", studio: "Rockstar North", options: ["Rockstar North", "Ubisoft", "Valve", "Nintendo"] }, { game: "Overwatch", studio: "Blizzard Entertainment", options: ["Blizzard Entertainment", "Epic Games", "Valve", "Riot Games"] }, { game: "Portal 2", studio: "Valve", options: ["Valve", "Bethesda", "Ubisoft", "Nintendo"] }, { game: "Uncharted 4: A Thief's End", studio: "Naughty Dog", options: ["Naughty Dog", "Santa Monica Studio", "Rockstar Games", "CD Projekt Red"] }, { game: "Dark Souls", studio: "FromSoftware", options: ["FromSoftware", "Capcom", "Square Enix", "Remedy"] }, { game: "Red Dead Redemption 2", studio: "Rockstar Games", options: ["Rockstar Games", "Ubisoft", "Valve", "Nintendo"] }]; // Shuffle quizData for each game session function shuffleArray(arr) { for (var i = arr.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } // --- Game State --- var currentQuestion = 0; var score = 0; var timeLeft = 60; // seconds var timerInterval = null; var optionButtons = []; var isAnswered = false; // --- UI Elements --- // Title var titleTxt = new Text2("Game Studio Guessr", { size: 110, fill: 0xF7C873 }); titleTxt.anchor.set(0.5, 0); LK.gui.top.addChild(titleTxt); // Score var scoreTxt = new Text2("Score: 0", { size: 70, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Timer var timerTxt = new Text2("Time: 60", { size: 70, fill: 0xFFFFFF }); timerTxt.anchor.set(0.5, 0); LK.gui.top.addChild(timerTxt); // Question text var questionTxt = new Text2("", { size: 90, fill: 0xFFFFFF }); questionTxt.anchor.set(0.5, 0.5); game.addChild(questionTxt); // --- Layout positions --- function layoutUI() { // Title at top center, below safe area titleTxt.x = LK.gui.width / 2; titleTxt.y = 40; // Score at top left (but not in the 0,0 area) scoreTxt.x = LK.gui.width / 2 - 500; scoreTxt.y = 40; // Timer at top right timerTxt.x = LK.gui.width / 2 + 500; timerTxt.y = 40; // Question in center questionTxt.x = 2048 / 2; questionTxt.y = 600; // Option buttons: vertical stack, centered var startY = 1100; var spacing = 260; for (var i = 0; i < optionButtons.length; i++) { var btn = optionButtons[i]; btn.x = 2048 / 2; btn.y = startY + i * spacing; } } // --- Option Buttons --- function createOptionButtons() { // Remove old buttons for (var i = 0; i < optionButtons.length; i++) { optionButtons[i].destroy(); } optionButtons = []; // Create 4 buttons for (var i = 0; i < 4; i++) { var btn = new OptionButton(); btn.setText(""); btn.setEnabled(false); game.addChild(btn); optionButtons.push(btn); } layoutUI(); } // --- Show Question --- function showQuestion(idx) { isAnswered = false; if (idx >= quizData.length) { endGame(); return; } var q = quizData[idx]; questionTxt.setText("Who made:\n" + q.game + "?"); // Shuffle options for this question var options = q.options.slice(); shuffleArray(options); // Set button text and callbacks for (var i = 0; i < optionButtons.length; i++) { var btn = optionButtons[i]; btn.setText(options[i]); btn.setEnabled(true); (function (btn, answer) { btn.setCallback(function () { if (isAnswered) return; isAnswered = true; handleAnswer(answer, q.studio, btn); }); })(btn, options[i]); } layoutUI(); } // --- Handle Answer --- function handleAnswer(selected, correct, btn) { // Disable all buttons for (var i = 0; i < optionButtons.length; i++) { optionButtons[i].setEnabled(false); } // Visual feedback if (selected === correct) { // Correct: flash green tween(btn, { tint: 0x4caf50 }, { duration: 200, onFinish: function onFinish() { tween(btn, { tint: 0x2d2d2d }, { duration: 300 }); } }); score += 1; scoreTxt.setText("Score: " + score); } else { // Incorrect: flash red tween(btn, { tint: 0xff3b30 }, { duration: 200, onFinish: function onFinish() { tween(btn, { tint: 0x2d2d2d }, { duration: 300 }); } }); // Also flash correct button green for (var i = 0; i < optionButtons.length; i++) { if (optionButtons[i].text === correct) { tween(optionButtons[i], { tint: 0x4caf50 }, { duration: 200, onFinish: function onFinish() { tween(optionButtons[i], { tint: 0x2d2d2d }, { duration: 300 }); } }); } } } // Next question after short delay LK.setTimeout(function () { currentQuestion += 1; showQuestion(currentQuestion); }, 700); } // --- Timer --- function startTimer() { timeLeft = 60; timerTxt.setText("Time: " + timeLeft); if (timerInterval) LK.clearInterval(timerInterval); timerInterval = LK.setInterval(function () { timeLeft -= 1; timerTxt.setText("Time: " + timeLeft); if (timeLeft <= 0) { LK.clearInterval(timerInterval); endGame(); } }, 1000); } // --- End Game --- function endGame() { // Show game over popup LK.setScore(score); LK.showGameOver(); } // --- Game Start --- function startGame() { // Shuffle questions shuffleArray(quizData); currentQuestion = 0; score = 0; scoreTxt.setText("Score: 0"); startTimer(); createOptionButtons(); showQuestion(currentQuestion); } // --- Responsive Layout --- game.on('resize', function () { layoutUI(); }); // --- Start --- startGame();
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,311 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// OptionButton: A tappable answer button
+var OptionButton = Container.expand(function () {
+ var self = Container.call(this);
+ // Button background
+ var bg = self.attachAsset('optionBg', {
+ width: 1200,
+ height: 180,
+ color: 0x2d2d2d,
+ shape: 'box',
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Option text
+ var txt = new Text2('', {
+ size: 70,
+ fill: 0xFFFFFF
+ });
+ txt.anchor.set(0.5, 0.5);
+ self.addChild(txt);
+ // Store callback
+ self._onSelect = null;
+ // Set option text
+ self.setText = function (t) {
+ txt.setText(t);
+ };
+ // Set callback
+ self.setCallback = function (cb) {
+ self._onSelect = cb;
+ };
+ // Enable/disable button
+ self.setEnabled = function (enabled) {
+ self.interactive = enabled;
+ self.alpha = enabled ? 1 : 0.5;
+ };
+ // Handle tap
+ self.down = function (x, y, obj) {
+ if (self._onSelect) self._onSelect();
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x181c24
+});
+
+/****
+* Game Code
+****/
+// --- Quiz Data ---
+var quizData = [{
+ game: "The Legend of Zelda: Breath of the Wild",
+ studio: "Nintendo",
+ options: ["Nintendo", "Ubisoft", "Rockstar Games", "Valve"]
+}, {
+ game: "The Witcher 3: Wild Hunt",
+ studio: "CD Projekt Red",
+ options: ["CD Projekt Red", "Bethesda", "Square Enix", "Capcom"]
+}, {
+ game: "Halo: Combat Evolved",
+ studio: "Bungie",
+ options: ["Bungie", "343 Industries", "EA", "Insomniac Games"]
+}, {
+ game: "God of War (2018)",
+ studio: "Santa Monica Studio",
+ options: ["Santa Monica Studio", "Naughty Dog", "FromSoftware", "Remedy"]
+}, {
+ game: "Grand Theft Auto V",
+ studio: "Rockstar North",
+ options: ["Rockstar North", "Ubisoft", "Valve", "Nintendo"]
+}, {
+ game: "Overwatch",
+ studio: "Blizzard Entertainment",
+ options: ["Blizzard Entertainment", "Epic Games", "Valve", "Riot Games"]
+}, {
+ game: "Portal 2",
+ studio: "Valve",
+ options: ["Valve", "Bethesda", "Ubisoft", "Nintendo"]
+}, {
+ game: "Uncharted 4: A Thief's End",
+ studio: "Naughty Dog",
+ options: ["Naughty Dog", "Santa Monica Studio", "Rockstar Games", "CD Projekt Red"]
+}, {
+ game: "Dark Souls",
+ studio: "FromSoftware",
+ options: ["FromSoftware", "Capcom", "Square Enix", "Remedy"]
+}, {
+ game: "Red Dead Redemption 2",
+ studio: "Rockstar Games",
+ options: ["Rockstar Games", "Ubisoft", "Valve", "Nintendo"]
+}];
+// Shuffle quizData for each game session
+function shuffleArray(arr) {
+ for (var i = arr.length - 1; i > 0; i--) {
+ var j = Math.floor(Math.random() * (i + 1));
+ var temp = arr[i];
+ arr[i] = arr[j];
+ arr[j] = temp;
+ }
+}
+// --- Game State ---
+var currentQuestion = 0;
+var score = 0;
+var timeLeft = 60; // seconds
+var timerInterval = null;
+var optionButtons = [];
+var isAnswered = false;
+// --- UI Elements ---
+// Title
+var titleTxt = new Text2("Game Studio Guessr", {
+ size: 110,
+ fill: 0xF7C873
+});
+titleTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(titleTxt);
+// Score
+var scoreTxt = new Text2("Score: 0", {
+ size: 70,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Timer
+var timerTxt = new Text2("Time: 60", {
+ size: 70,
+ fill: 0xFFFFFF
+});
+timerTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(timerTxt);
+// Question text
+var questionTxt = new Text2("", {
+ size: 90,
+ fill: 0xFFFFFF
+});
+questionTxt.anchor.set(0.5, 0.5);
+game.addChild(questionTxt);
+// --- Layout positions ---
+function layoutUI() {
+ // Title at top center, below safe area
+ titleTxt.x = LK.gui.width / 2;
+ titleTxt.y = 40;
+ // Score at top left (but not in the 0,0 area)
+ scoreTxt.x = LK.gui.width / 2 - 500;
+ scoreTxt.y = 40;
+ // Timer at top right
+ timerTxt.x = LK.gui.width / 2 + 500;
+ timerTxt.y = 40;
+ // Question in center
+ questionTxt.x = 2048 / 2;
+ questionTxt.y = 600;
+ // Option buttons: vertical stack, centered
+ var startY = 1100;
+ var spacing = 260;
+ for (var i = 0; i < optionButtons.length; i++) {
+ var btn = optionButtons[i];
+ btn.x = 2048 / 2;
+ btn.y = startY + i * spacing;
+ }
+}
+// --- Option Buttons ---
+function createOptionButtons() {
+ // Remove old buttons
+ for (var i = 0; i < optionButtons.length; i++) {
+ optionButtons[i].destroy();
+ }
+ optionButtons = [];
+ // Create 4 buttons
+ for (var i = 0; i < 4; i++) {
+ var btn = new OptionButton();
+ btn.setText("");
+ btn.setEnabled(false);
+ game.addChild(btn);
+ optionButtons.push(btn);
+ }
+ layoutUI();
+}
+// --- Show Question ---
+function showQuestion(idx) {
+ isAnswered = false;
+ if (idx >= quizData.length) {
+ endGame();
+ return;
+ }
+ var q = quizData[idx];
+ questionTxt.setText("Who made:\n" + q.game + "?");
+ // Shuffle options for this question
+ var options = q.options.slice();
+ shuffleArray(options);
+ // Set button text and callbacks
+ for (var i = 0; i < optionButtons.length; i++) {
+ var btn = optionButtons[i];
+ btn.setText(options[i]);
+ btn.setEnabled(true);
+ (function (btn, answer) {
+ btn.setCallback(function () {
+ if (isAnswered) return;
+ isAnswered = true;
+ handleAnswer(answer, q.studio, btn);
+ });
+ })(btn, options[i]);
+ }
+ layoutUI();
+}
+// --- Handle Answer ---
+function handleAnswer(selected, correct, btn) {
+ // Disable all buttons
+ for (var i = 0; i < optionButtons.length; i++) {
+ optionButtons[i].setEnabled(false);
+ }
+ // Visual feedback
+ if (selected === correct) {
+ // Correct: flash green
+ tween(btn, {
+ tint: 0x4caf50
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ tween(btn, {
+ tint: 0x2d2d2d
+ }, {
+ duration: 300
+ });
+ }
+ });
+ score += 1;
+ scoreTxt.setText("Score: " + score);
+ } else {
+ // Incorrect: flash red
+ tween(btn, {
+ tint: 0xff3b30
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ tween(btn, {
+ tint: 0x2d2d2d
+ }, {
+ duration: 300
+ });
+ }
+ });
+ // Also flash correct button green
+ for (var i = 0; i < optionButtons.length; i++) {
+ if (optionButtons[i].text === correct) {
+ tween(optionButtons[i], {
+ tint: 0x4caf50
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ tween(optionButtons[i], {
+ tint: 0x2d2d2d
+ }, {
+ duration: 300
+ });
+ }
+ });
+ }
+ }
+ }
+ // Next question after short delay
+ LK.setTimeout(function () {
+ currentQuestion += 1;
+ showQuestion(currentQuestion);
+ }, 700);
+}
+// --- Timer ---
+function startTimer() {
+ timeLeft = 60;
+ timerTxt.setText("Time: " + timeLeft);
+ if (timerInterval) LK.clearInterval(timerInterval);
+ timerInterval = LK.setInterval(function () {
+ timeLeft -= 1;
+ timerTxt.setText("Time: " + timeLeft);
+ if (timeLeft <= 0) {
+ LK.clearInterval(timerInterval);
+ endGame();
+ }
+ }, 1000);
+}
+// --- End Game ---
+function endGame() {
+ // Show game over popup
+ LK.setScore(score);
+ LK.showGameOver();
+}
+// --- Game Start ---
+function startGame() {
+ // Shuffle questions
+ shuffleArray(quizData);
+ currentQuestion = 0;
+ score = 0;
+ scoreTxt.setText("Score: 0");
+ startTimer();
+ createOptionButtons();
+ showQuestion(currentQuestion);
+}
+// --- Responsive Layout ---
+game.on('resize', function () {
+ layoutUI();
+});
+// --- Start ---
+startGame();
\ No newline at end of file