/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Question = Container.expand(function (questionData) { var self = Container.call(this); self.data = questionData; self.isAnswered = false; self.selectedAnswer = -1; // Question background var questionBg = self.attachAsset('questionBox', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0 }); // Question text self.questionText = new Text2(questionData.question, { size: 60, fill: 0xFFFFFF, wordWrap: true, wordWrapWidth: 1700 }); self.questionText.anchor.set(0.5, 0.5); self.questionText.x = 0; self.questionText.y = 0; self.addChild(self.questionText); // Answer boxes self.answerBoxes = []; self.answerTexts = []; for (var i = 0; i < 4; i++) { var answerBox = LK.getAsset('answerBox', { anchorX: 0.5, anchorY: 0.5 }); var row = Math.floor(i / 2); var col = i % 2; answerBox.x = col === 0 ? -450 : 450; answerBox.y = 250 + row * 220; var answerText = new Text2(questionData.answers[i], { size: 45, fill: 0xFFFFFF, wordWrap: true, wordWrapWidth: 800 }); answerText.anchor.set(0.5, 0.5); answerText.x = answerBox.x; answerText.y = answerBox.y; self.answerBoxes.push(answerBox); self.answerTexts.push(answerText); self.addChild(answerBox); self.addChild(answerText); } self.selectAnswer = function (index) { if (self.isAnswered) return; self.isAnswered = true; self.selectedAnswer = index; // Add bounce animation to selected answer first tween(self.answerBoxes[index], { scaleX: 1.1, scaleY: 1.1 }, { duration: 150, easing: tween.easeOut, onFinish: function onFinish() { tween(self.answerBoxes[index], { scaleX: 1, scaleY: 1 }, { duration: 150, easing: tween.easeIn }); } }); // Change box colors based on correctness with smooth transitions for (var i = 0; i < 4; i++) { if (i === self.data.correct) { var boxX = self.answerBoxes[i].x; var boxY = self.answerBoxes[i].y; self.removeChild(self.answerBoxes[i]); self.answerBoxes[i] = LK.getAsset('correctBox', { anchorX: 0.5, anchorY: 0.5, x: boxX, y: boxY }); self.answerBoxes[i].alpha = 0; self.addChild(self.answerBoxes[i]); // Fade in correct answer with green glow effect var correctBox = self.answerBoxes[i]; tween(correctBox, { alpha: 1 }, { duration: 300, easing: tween.easeOut }); tween(correctBox, { scaleX: 1.05, scaleY: 1.05 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(correctBox, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeIn }); } }); } else if (i === index) { var boxX = self.answerBoxes[i].x; var boxY = self.answerBoxes[i].y; self.removeChild(self.answerBoxes[i]); self.answerBoxes[i] = LK.getAsset('wrongBox', { anchorX: 0.5, anchorY: 0.5, x: boxX, y: boxY }); self.answerBoxes[i].alpha = 0; self.addChild(self.answerBoxes[i]); // Fade in wrong answer with shake effect var wrongBox = self.answerBoxes[i]; var originalX = wrongBox.x; tween(wrongBox, { alpha: 1 }, { duration: 300, easing: tween.easeOut }); tween(wrongBox, { x: originalX + 10 }, { duration: 50, easing: tween.easeOut, onFinish: function onFinish() { tween(wrongBox, { x: originalX - 10 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(wrongBox, { x: originalX }, { duration: 50, easing: tween.easeOut }); } }); } }); } } // Play sound if (index === self.data.correct) { LK.getSound('correct').play(); LK.setScore(LK.getScore() + 10); } else { LK.getSound('wrong').play(); } // Update score display with animation scoreTxt.setText('Score: ' + LK.getScore()); // Animate score text when points are earned if (index === self.data.correct) { tween(scoreTxt, { scaleX: 1.3, scaleY: 1.3, tint: 0x27ae60 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(scoreTxt, { scaleX: 1, scaleY: 1, tint: 0xFFFFFF }, { duration: 300, easing: tween.easeIn }); } }); } // Move to next question after answer is selected nextQuestion(); }; self.down = function (x, y, obj) { if (self.isAnswered) return; // Use the x, y coordinates directly as they are already in the correct space var localPos = { x: x, y: y }; // Check which answer was clicked for (var i = 0; i < 4; i++) { var box = self.answerBoxes[i]; var bounds = { left: box.x - 425, right: box.x + 425, top: box.y - 100, bottom: box.y + 100 }; if (localPos.x >= bounds.left && localPos.x <= bounds.right && localPos.y >= bounds.top && localPos.y <= bounds.bottom) { self.selectAnswer(i); break; } } }; return self; }); /**** * Initialize Game ****/ // Game background var game = new LK.Game({ backgroundColor: 0x1a252f }); /**** * Game Code ****/ // Game background var background = game.attachAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); // Question database var questions = [ // Turkish questions { question: "Merhaba nasıl denir? (How do you say hello?)", answers: ["Hello", "Goodbye", "Thank you", "Please"], correct: 0 }, { question: "Köpek hangi dilde 'Hund' denir?", answers: ["İngilizce", "Almanca", "Fransızca", "İspanyolca"], correct: 1 }, { question: "What is 'kitap' in English?", answers: ["Book", "Chair", "Table", "Window"], correct: 0 }, // German questions { question: "Wie sagt man 'teşekkür ederim' auf Deutsch?", answers: ["Bitte", "Danke", "Hallo", "Tschüss"], correct: 1 }, { question: "Was bedeutet 'good morning' auf Türkisch?", answers: ["İyi akşamlar", "Günaydın", "İyi geceler", "Merhaba"], correct: 1 }, { question: "Der Hund ist... (complete in English)", answers: ["big", "klein", "groß", "small"], correct: 0 }, // English questions { question: "How do you say 'water' in German?", answers: ["Wasser", "Feuer", "Luft", "Erde"], correct: 0 }, { question: "What does 'mavi' mean in English?", answers: ["Red", "Blue", "Green", "Yellow"], correct: 1 }, { question: "Translate 'Ich liebe dich' to English:", answers: ["I like you", "I love you", "I see you", "I know you"], correct: 1 }, // Mixed language questions { question: "Match: Cat = Katze = ?", answers: ["Köpek", "Kedi", "Kuş", "Balık"], correct: 1 }, { question: "Numbers: One = Eins = ?", answers: ["İki", "Üç", "Bir", "Dört"], correct: 2 }, { question: "Colors: Red = Rot = ?", answers: ["Mavi", "Yeşil", "Kırmızı", "Sarı"], correct: 2 }]; // Shuffle questions array for random order each game function shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } } // Shuffle questions at game start shuffleArray(questions); // Game state var currentQuestionIndex = 0; var currentQuestion = null; var questionTimer = null; var timeLeft = 31; var isGameOver = false; // Score display var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Timer display var timerTxt = new Text2('Time: 31', { size: 60, fill: 0xFF6B6B }); timerTxt.anchor.set(1, 0); timerTxt.x = -50; timerTxt.y = 50; LK.gui.topRight.addChild(timerTxt); // Question counter var questionCountTxt = new Text2('Question: 1/12', { size: 60, fill: 0x74B9FF }); questionCountTxt.anchor.set(0, 0); questionCountTxt.x = 50; questionCountTxt.y = 50; LK.gui.topLeft.addChild(questionCountTxt); // Add gentle floating animation to question counter function animateQuestionCounter() { tween(questionCountTxt, { y: 45 }, { duration: 2000, easing: tween.easeInOut, onFinish: function onFinish() { tween(questionCountTxt, { y: 55 }, { duration: 2000, easing: tween.easeInOut, onFinish: animateQuestionCounter }); } }); } animateQuestionCounter(); function loadQuestion() { if (currentQuestionIndex >= questions.length) { // Game completed LK.showYouWin(); return; } // Remove previous question if (currentQuestion) { currentQuestion.destroy(); } // Create new question var questionData = questions[currentQuestionIndex]; currentQuestion = new Question(questionData); currentQuestion.x = 1024; currentQuestion.y = 1200; // Start with scale 0 and fade in with bounce effect currentQuestion.scaleX = 0; currentQuestion.scaleY = 0; currentQuestion.alpha = 0; game.addChild(currentQuestion); // Animate entrance tween(currentQuestion, { scaleX: 1, scaleY: 1, alpha: 1 }, { duration: 800, easing: tween.bounceOut }); // Update question counter questionCountTxt.setText('Question: ' + (currentQuestionIndex + 1) + '/' + questions.length); // Start timer timeLeft = 31; timerTxt.setText('Time: ' + timeLeft); if (questionTimer) { LK.clearInterval(questionTimer); } questionTimer = LK.setInterval(function () { timeLeft--; timerTxt.setText('Time: ' + timeLeft); // Add pulsing animation when time is low if (timeLeft <= 10 && timeLeft > 0) { tween(timerTxt, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(timerTxt, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeIn }); } }); } if (timeLeft <= 0) { // Time's up - game over if (!currentQuestion.isAnswered && !isGameOver) { isGameOver = true; LK.clearInterval(questionTimer); LK.showGameOver(); } } }, 1000); } function nextQuestion() { if (questionTimer) { LK.clearInterval(questionTimer); } // Animate current question exit if (currentQuestion) { tween(currentQuestion, { scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 500, easing: tween.easeIn }); } LK.setTimeout(function () { currentQuestionIndex++; if (currentQuestionIndex >= questions.length) { // Game completed LK.showYouWin(); } else { loadQuestion(); } }, 4000); } // Game update game.update = function () { // Game update logic (removed automatic progression to prevent double-calling) }; // Start the game loadQuestion();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Question = Container.expand(function (questionData) {
var self = Container.call(this);
self.data = questionData;
self.isAnswered = false;
self.selectedAnswer = -1;
// Question background
var questionBg = self.attachAsset('questionBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
// Question text
self.questionText = new Text2(questionData.question, {
size: 60,
fill: 0xFFFFFF,
wordWrap: true,
wordWrapWidth: 1700
});
self.questionText.anchor.set(0.5, 0.5);
self.questionText.x = 0;
self.questionText.y = 0;
self.addChild(self.questionText);
// Answer boxes
self.answerBoxes = [];
self.answerTexts = [];
for (var i = 0; i < 4; i++) {
var answerBox = LK.getAsset('answerBox', {
anchorX: 0.5,
anchorY: 0.5
});
var row = Math.floor(i / 2);
var col = i % 2;
answerBox.x = col === 0 ? -450 : 450;
answerBox.y = 250 + row * 220;
var answerText = new Text2(questionData.answers[i], {
size: 45,
fill: 0xFFFFFF,
wordWrap: true,
wordWrapWidth: 800
});
answerText.anchor.set(0.5, 0.5);
answerText.x = answerBox.x;
answerText.y = answerBox.y;
self.answerBoxes.push(answerBox);
self.answerTexts.push(answerText);
self.addChild(answerBox);
self.addChild(answerText);
}
self.selectAnswer = function (index) {
if (self.isAnswered) return;
self.isAnswered = true;
self.selectedAnswer = index;
// Add bounce animation to selected answer first
tween(self.answerBoxes[index], {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.answerBoxes[index], {
scaleX: 1,
scaleY: 1
}, {
duration: 150,
easing: tween.easeIn
});
}
});
// Change box colors based on correctness with smooth transitions
for (var i = 0; i < 4; i++) {
if (i === self.data.correct) {
var boxX = self.answerBoxes[i].x;
var boxY = self.answerBoxes[i].y;
self.removeChild(self.answerBoxes[i]);
self.answerBoxes[i] = LK.getAsset('correctBox', {
anchorX: 0.5,
anchorY: 0.5,
x: boxX,
y: boxY
});
self.answerBoxes[i].alpha = 0;
self.addChild(self.answerBoxes[i]);
// Fade in correct answer with green glow effect
var correctBox = self.answerBoxes[i];
tween(correctBox, {
alpha: 1
}, {
duration: 300,
easing: tween.easeOut
});
tween(correctBox, {
scaleX: 1.05,
scaleY: 1.05
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(correctBox, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
} else if (i === index) {
var boxX = self.answerBoxes[i].x;
var boxY = self.answerBoxes[i].y;
self.removeChild(self.answerBoxes[i]);
self.answerBoxes[i] = LK.getAsset('wrongBox', {
anchorX: 0.5,
anchorY: 0.5,
x: boxX,
y: boxY
});
self.answerBoxes[i].alpha = 0;
self.addChild(self.answerBoxes[i]);
// Fade in wrong answer with shake effect
var wrongBox = self.answerBoxes[i];
var originalX = wrongBox.x;
tween(wrongBox, {
alpha: 1
}, {
duration: 300,
easing: tween.easeOut
});
tween(wrongBox, {
x: originalX + 10
}, {
duration: 50,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(wrongBox, {
x: originalX - 10
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(wrongBox, {
x: originalX
}, {
duration: 50,
easing: tween.easeOut
});
}
});
}
});
}
}
// Play sound
if (index === self.data.correct) {
LK.getSound('correct').play();
LK.setScore(LK.getScore() + 10);
} else {
LK.getSound('wrong').play();
}
// Update score display with animation
scoreTxt.setText('Score: ' + LK.getScore());
// Animate score text when points are earned
if (index === self.data.correct) {
tween(scoreTxt, {
scaleX: 1.3,
scaleY: 1.3,
tint: 0x27ae60
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(scoreTxt, {
scaleX: 1,
scaleY: 1,
tint: 0xFFFFFF
}, {
duration: 300,
easing: tween.easeIn
});
}
});
}
// Move to next question after answer is selected
nextQuestion();
};
self.down = function (x, y, obj) {
if (self.isAnswered) return;
// Use the x, y coordinates directly as they are already in the correct space
var localPos = {
x: x,
y: y
};
// Check which answer was clicked
for (var i = 0; i < 4; i++) {
var box = self.answerBoxes[i];
var bounds = {
left: box.x - 425,
right: box.x + 425,
top: box.y - 100,
bottom: box.y + 100
};
if (localPos.x >= bounds.left && localPos.x <= bounds.right && localPos.y >= bounds.top && localPos.y <= bounds.bottom) {
self.selectAnswer(i);
break;
}
}
};
return self;
});
/****
* Initialize Game
****/
// Game background
var game = new LK.Game({
backgroundColor: 0x1a252f
});
/****
* Game Code
****/
// Game background
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Question database
var questions = [
// Turkish questions
{
question: "Merhaba nasıl denir? (How do you say hello?)",
answers: ["Hello", "Goodbye", "Thank you", "Please"],
correct: 0
}, {
question: "Köpek hangi dilde 'Hund' denir?",
answers: ["İngilizce", "Almanca", "Fransızca", "İspanyolca"],
correct: 1
}, {
question: "What is 'kitap' in English?",
answers: ["Book", "Chair", "Table", "Window"],
correct: 0
},
// German questions
{
question: "Wie sagt man 'teşekkür ederim' auf Deutsch?",
answers: ["Bitte", "Danke", "Hallo", "Tschüss"],
correct: 1
}, {
question: "Was bedeutet 'good morning' auf Türkisch?",
answers: ["İyi akşamlar", "Günaydın", "İyi geceler", "Merhaba"],
correct: 1
}, {
question: "Der Hund ist... (complete in English)",
answers: ["big", "klein", "groß", "small"],
correct: 0
},
// English questions
{
question: "How do you say 'water' in German?",
answers: ["Wasser", "Feuer", "Luft", "Erde"],
correct: 0
}, {
question: "What does 'mavi' mean in English?",
answers: ["Red", "Blue", "Green", "Yellow"],
correct: 1
}, {
question: "Translate 'Ich liebe dich' to English:",
answers: ["I like you", "I love you", "I see you", "I know you"],
correct: 1
},
// Mixed language questions
{
question: "Match: Cat = Katze = ?",
answers: ["Köpek", "Kedi", "Kuş", "Balık"],
correct: 1
}, {
question: "Numbers: One = Eins = ?",
answers: ["İki", "Üç", "Bir", "Dört"],
correct: 2
}, {
question: "Colors: Red = Rot = ?",
answers: ["Mavi", "Yeşil", "Kırmızı", "Sarı"],
correct: 2
}];
// Shuffle questions array for random order each game
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
// Shuffle questions at game start
shuffleArray(questions);
// Game state
var currentQuestionIndex = 0;
var currentQuestion = null;
var questionTimer = null;
var timeLeft = 31;
var isGameOver = false;
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Timer display
var timerTxt = new Text2('Time: 31', {
size: 60,
fill: 0xFF6B6B
});
timerTxt.anchor.set(1, 0);
timerTxt.x = -50;
timerTxt.y = 50;
LK.gui.topRight.addChild(timerTxt);
// Question counter
var questionCountTxt = new Text2('Question: 1/12', {
size: 60,
fill: 0x74B9FF
});
questionCountTxt.anchor.set(0, 0);
questionCountTxt.x = 50;
questionCountTxt.y = 50;
LK.gui.topLeft.addChild(questionCountTxt);
// Add gentle floating animation to question counter
function animateQuestionCounter() {
tween(questionCountTxt, {
y: 45
}, {
duration: 2000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(questionCountTxt, {
y: 55
}, {
duration: 2000,
easing: tween.easeInOut,
onFinish: animateQuestionCounter
});
}
});
}
animateQuestionCounter();
function loadQuestion() {
if (currentQuestionIndex >= questions.length) {
// Game completed
LK.showYouWin();
return;
}
// Remove previous question
if (currentQuestion) {
currentQuestion.destroy();
}
// Create new question
var questionData = questions[currentQuestionIndex];
currentQuestion = new Question(questionData);
currentQuestion.x = 1024;
currentQuestion.y = 1200;
// Start with scale 0 and fade in with bounce effect
currentQuestion.scaleX = 0;
currentQuestion.scaleY = 0;
currentQuestion.alpha = 0;
game.addChild(currentQuestion);
// Animate entrance
tween(currentQuestion, {
scaleX: 1,
scaleY: 1,
alpha: 1
}, {
duration: 800,
easing: tween.bounceOut
});
// Update question counter
questionCountTxt.setText('Question: ' + (currentQuestionIndex + 1) + '/' + questions.length);
// Start timer
timeLeft = 31;
timerTxt.setText('Time: ' + timeLeft);
if (questionTimer) {
LK.clearInterval(questionTimer);
}
questionTimer = LK.setInterval(function () {
timeLeft--;
timerTxt.setText('Time: ' + timeLeft);
// Add pulsing animation when time is low
if (timeLeft <= 10 && timeLeft > 0) {
tween(timerTxt, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(timerTxt, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
}
if (timeLeft <= 0) {
// Time's up - game over
if (!currentQuestion.isAnswered && !isGameOver) {
isGameOver = true;
LK.clearInterval(questionTimer);
LK.showGameOver();
}
}
}, 1000);
}
function nextQuestion() {
if (questionTimer) {
LK.clearInterval(questionTimer);
}
// Animate current question exit
if (currentQuestion) {
tween(currentQuestion, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 500,
easing: tween.easeIn
});
}
LK.setTimeout(function () {
currentQuestionIndex++;
if (currentQuestionIndex >= questions.length) {
// Game completed
LK.showYouWin();
} else {
loadQuestion();
}
}, 4000);
}
// Game update
game.update = function () {
// Game update logic (removed automatic progression to prevent double-calling)
};
// Start the game
loadQuestion();