/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var AnswerButton = Container.expand(function () { var self = Container.call(this); var buttonBg = self.attachAsset('answerButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonHover = self.attachAsset('answerButtonHover', { anchorX: 0.5, anchorY: 0.5 }); buttonHover.visible = false; self.answerText = new Text2('', { size: 64, fill: '#ffffff' }); self.answerText.anchor.set(0.5, 0.5); self.addChild(self.answerText); self.answerIndex = 0; self.isSelected = false; self.setText = function (text) { self.answerText.setText(text); }; self.setHover = function (hover) { buttonHover.visible = hover; buttonBg.visible = !hover; }; self.down = function (x, y, obj) { if (!self.isSelected) { LK.getSound('buttonClick').play(); self.isSelected = true; selectAnswer(self.answerIndex); } }; return self; }); var QuestionCard = Container.expand(function () { var self = Container.call(this); var cardBg = self.attachAsset('questionCard', { anchorX: 0.5, anchorY: 0.5 }); self.questionText = new Text2('', { size: 80, fill: '#ffffff' }); self.questionText.anchor.set(0.5, 0.5); self.addChild(self.questionText); self.setQuestion = function (text) { self.questionText.setText(text); }; return self; }); var ResultScreen = Container.expand(function () { var self = Container.call(this); var resultBg = self.attachAsset('resultCard', { anchorX: 0.5, anchorY: 0.5 }); var portrait = self.attachAsset('characterPortrait', { anchorX: 0.5, anchorY: 0.5, y: -300 }); self.characterName = new Text2('', { size: 100, fill: '#ffffff' }); self.characterName.anchor.set(0.5, 0.5); self.characterName.y = -100; self.addChild(self.characterName); self.matchPercentage = new Text2('', { size: 80, fill: '#f39c12' }); self.matchPercentage.anchor.set(0.5, 0.5); self.matchPercentage.y = -20; self.addChild(self.matchPercentage); self.description = new Text2('', { size: 56, fill: '#ecf0f1' }); self.description.anchor.set(0.5, 0.5); self.description.y = 100; self.addChild(self.description); self.retryButton = new Text2('Take Quiz Again', { size: 70, fill: '#3498db' }); self.retryButton.anchor.set(0.5, 0.5); self.retryButton.y = 300; self.addChild(self.retryButton); self.setResult = function (character, percentage) { self.characterName.setText(character.name); self.matchPercentage.setText(percentage + '% Match'); self.description.setText(character.description); portrait.tint = character.color; }; self.down = function (x, y, obj) { // Use the x, y coordinates directly instead of converting through parent if (Math.abs(x) < 200 && Math.abs(y - 300) < 30) { LK.getSound('buttonClick').play(); restartQuiz(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a252f }); /**** * Game Code ****/ var questions = [{ text: "What's your ideal weekend activity?", answers: ["Reading a book at home", "Going on an adventure outdoors", "Partying with friends"] }, { text: "How do you handle stress?", answers: ["Stay calm and think it through", "Take action immediately", "Talk to others about it"] }, { text: "What motivates you most?", answers: ["Personal growth and learning", "Helping others and making a difference", "Success and recognition"] }, { text: "Your biggest strength is:", answers: ["Intelligence and creativity", "Courage and determination", "Charisma and social skills"] }, { text: "In a group project, you are:", answers: ["The strategic planner", "The leader who takes charge", "The motivator who keeps spirits up"] }, { text: "What's most important to you?", answers: ["Freedom and independence", "Justice and doing what's right", "Love and relationships"] }]; var characters = [{ name: "Imperator Furiosa", description: "Strong, determined warrior who fights for justice", color: 0xff6b35, traits: [1, 1, 1, 1, 1, 1] // Answer B for all questions }, { name: "Miles Morales", description: "Young hero balancing responsibility with personal growth", color: 0xff0040, traits: [1, 0, 1, 1, 1, 1] // Mix of A and B answers }, { name: "Jordan Belfort", description: "Ambitious and charismatic, driven by success", color: 0x00ff87, traits: [2, 2, 2, 2, 2, 0] // Mostly C answers }, { name: "Mia Dolan", description: "Creative dreamer pursuing artistic passions", color: 0x9b59b6, traits: [0, 0, 0, 0, 0, 2] // Mix of A and C answers }, { name: "Elsa", description: "Independent spirit learning to embrace her uniqueness", color: 0x3498db, traits: [0, 0, 0, 0, 2, 0] // Mostly A answers }, { name: "Peter Quill", description: "Fun-loving adventurer with a good heart", color: 0xf39c12, traits: [1, 2, 1, 2, 2, 2] // Mix of B and C answers }]; var currentQuestion = 0; var answers = []; var gameState = 'quiz'; // 'quiz' or 'results' var titleText = new Text2('Which Movie Character Are You?', { size: 120, fill: '#ffffff' }); titleText.anchor.set(0.5, 0.5); titleText.x = 1024; titleText.y = 300; game.addChild(titleText); var progressBg = game.addChild(LK.getAsset('progressBg', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 500 })); var progressBar = game.addChild(LK.getAsset('progressBar', { anchorX: 0, anchorY: 0.5, x: 224, y: 500, scaleX: 0 })); var questionCard = game.addChild(new QuestionCard()); questionCard.x = 1024; questionCard.y = 800; var answerButtons = []; for (var i = 0; i < 3; i++) { var button = new AnswerButton(); button.x = 1024; button.y = 1200 + i * 180; button.answerIndex = i; answerButtons.push(button); game.addChild(button); } var resultScreen = null; function updateQuestion() { if (currentQuestion < questions.length) { var question = questions[currentQuestion]; questionCard.setQuestion(question.text); for (var i = 0; i < 3; i++) { answerButtons[i].setText(question.answers[i]); answerButtons[i].isSelected = false; answerButtons[i].setHover(false); } var progress = currentQuestion / questions.length; tween(progressBar.scale, { x: progress }, { duration: 300 }); } else { showResults(); } } function selectAnswer(answerIndex) { answers.push(answerIndex); LK.setTimeout(function () { currentQuestion++; updateQuestion(); }, 500); } function calculateResult() { var scores = []; for (var i = 0; i < characters.length; i++) { scores[i] = 0; for (var j = 0; j < answers.length; j++) { if (characters[i].traits[j] === answers[j]) { scores[i]++; } } } var bestMatch = 0; var bestScore = scores[0]; for (var k = 1; k < scores.length; k++) { if (scores[k] > bestScore) { bestScore = scores[k]; bestMatch = k; } } var percentage = Math.round(bestScore / questions.length * 100); return { character: characters[bestMatch], percentage: percentage }; } function showResults() { gameState = 'results'; LK.getSound('resultReveal').play(); // Hide quiz elements titleText.visible = false; progressBg.visible = false; progressBar.visible = false; questionCard.visible = false; for (var i = 0; i < answerButtons.length; i++) { answerButtons[i].visible = false; } // Show results var result = calculateResult(); resultScreen = new ResultScreen(); resultScreen.x = 1024; resultScreen.y = 1366; resultScreen.setResult(result.character, result.percentage); game.addChild(resultScreen); LK.setScore(result.percentage); } function restartQuiz() { gameState = 'quiz'; currentQuestion = 0; answers = []; // Show quiz elements titleText.visible = true; progressBg.visible = true; progressBar.visible = true; questionCard.visible = true; for (var i = 0; i < answerButtons.length; i++) { answerButtons[i].visible = true; } // Hide results if (resultScreen) { resultScreen.destroy(); resultScreen = null; } // Reset progress progressBar.scale.x = 0; updateQuestion(); } // Initialize first question updateQuestion(); game.update = function () { // Handle hover effects for answer buttons if (gameState === 'quiz') { // Reset all hover states for (var i = 0; i < answerButtons.length; i++) { answerButtons[i].setHover(false); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var AnswerButton = Container.expand(function () {
var self = Container.call(this);
var buttonBg = self.attachAsset('answerButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonHover = self.attachAsset('answerButtonHover', {
anchorX: 0.5,
anchorY: 0.5
});
buttonHover.visible = false;
self.answerText = new Text2('', {
size: 64,
fill: '#ffffff'
});
self.answerText.anchor.set(0.5, 0.5);
self.addChild(self.answerText);
self.answerIndex = 0;
self.isSelected = false;
self.setText = function (text) {
self.answerText.setText(text);
};
self.setHover = function (hover) {
buttonHover.visible = hover;
buttonBg.visible = !hover;
};
self.down = function (x, y, obj) {
if (!self.isSelected) {
LK.getSound('buttonClick').play();
self.isSelected = true;
selectAnswer(self.answerIndex);
}
};
return self;
});
var QuestionCard = Container.expand(function () {
var self = Container.call(this);
var cardBg = self.attachAsset('questionCard', {
anchorX: 0.5,
anchorY: 0.5
});
self.questionText = new Text2('', {
size: 80,
fill: '#ffffff'
});
self.questionText.anchor.set(0.5, 0.5);
self.addChild(self.questionText);
self.setQuestion = function (text) {
self.questionText.setText(text);
};
return self;
});
var ResultScreen = Container.expand(function () {
var self = Container.call(this);
var resultBg = self.attachAsset('resultCard', {
anchorX: 0.5,
anchorY: 0.5
});
var portrait = self.attachAsset('characterPortrait', {
anchorX: 0.5,
anchorY: 0.5,
y: -300
});
self.characterName = new Text2('', {
size: 100,
fill: '#ffffff'
});
self.characterName.anchor.set(0.5, 0.5);
self.characterName.y = -100;
self.addChild(self.characterName);
self.matchPercentage = new Text2('', {
size: 80,
fill: '#f39c12'
});
self.matchPercentage.anchor.set(0.5, 0.5);
self.matchPercentage.y = -20;
self.addChild(self.matchPercentage);
self.description = new Text2('', {
size: 56,
fill: '#ecf0f1'
});
self.description.anchor.set(0.5, 0.5);
self.description.y = 100;
self.addChild(self.description);
self.retryButton = new Text2('Take Quiz Again', {
size: 70,
fill: '#3498db'
});
self.retryButton.anchor.set(0.5, 0.5);
self.retryButton.y = 300;
self.addChild(self.retryButton);
self.setResult = function (character, percentage) {
self.characterName.setText(character.name);
self.matchPercentage.setText(percentage + '% Match');
self.description.setText(character.description);
portrait.tint = character.color;
};
self.down = function (x, y, obj) {
// Use the x, y coordinates directly instead of converting through parent
if (Math.abs(x) < 200 && Math.abs(y - 300) < 30) {
LK.getSound('buttonClick').play();
restartQuiz();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a252f
});
/****
* Game Code
****/
var questions = [{
text: "What's your ideal weekend activity?",
answers: ["Reading a book at home", "Going on an adventure outdoors", "Partying with friends"]
}, {
text: "How do you handle stress?",
answers: ["Stay calm and think it through", "Take action immediately", "Talk to others about it"]
}, {
text: "What motivates you most?",
answers: ["Personal growth and learning", "Helping others and making a difference", "Success and recognition"]
}, {
text: "Your biggest strength is:",
answers: ["Intelligence and creativity", "Courage and determination", "Charisma and social skills"]
}, {
text: "In a group project, you are:",
answers: ["The strategic planner", "The leader who takes charge", "The motivator who keeps spirits up"]
}, {
text: "What's most important to you?",
answers: ["Freedom and independence", "Justice and doing what's right", "Love and relationships"]
}];
var characters = [{
name: "Imperator Furiosa",
description: "Strong, determined warrior who fights for justice",
color: 0xff6b35,
traits: [1, 1, 1, 1, 1, 1] // Answer B for all questions
}, {
name: "Miles Morales",
description: "Young hero balancing responsibility with personal growth",
color: 0xff0040,
traits: [1, 0, 1, 1, 1, 1] // Mix of A and B answers
}, {
name: "Jordan Belfort",
description: "Ambitious and charismatic, driven by success",
color: 0x00ff87,
traits: [2, 2, 2, 2, 2, 0] // Mostly C answers
}, {
name: "Mia Dolan",
description: "Creative dreamer pursuing artistic passions",
color: 0x9b59b6,
traits: [0, 0, 0, 0, 0, 2] // Mix of A and C answers
}, {
name: "Elsa",
description: "Independent spirit learning to embrace her uniqueness",
color: 0x3498db,
traits: [0, 0, 0, 0, 2, 0] // Mostly A answers
}, {
name: "Peter Quill",
description: "Fun-loving adventurer with a good heart",
color: 0xf39c12,
traits: [1, 2, 1, 2, 2, 2] // Mix of B and C answers
}];
var currentQuestion = 0;
var answers = [];
var gameState = 'quiz'; // 'quiz' or 'results'
var titleText = new Text2('Which Movie Character Are You?', {
size: 120,
fill: '#ffffff'
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 300;
game.addChild(titleText);
var progressBg = game.addChild(LK.getAsset('progressBg', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 500
}));
var progressBar = game.addChild(LK.getAsset('progressBar', {
anchorX: 0,
anchorY: 0.5,
x: 224,
y: 500,
scaleX: 0
}));
var questionCard = game.addChild(new QuestionCard());
questionCard.x = 1024;
questionCard.y = 800;
var answerButtons = [];
for (var i = 0; i < 3; i++) {
var button = new AnswerButton();
button.x = 1024;
button.y = 1200 + i * 180;
button.answerIndex = i;
answerButtons.push(button);
game.addChild(button);
}
var resultScreen = null;
function updateQuestion() {
if (currentQuestion < questions.length) {
var question = questions[currentQuestion];
questionCard.setQuestion(question.text);
for (var i = 0; i < 3; i++) {
answerButtons[i].setText(question.answers[i]);
answerButtons[i].isSelected = false;
answerButtons[i].setHover(false);
}
var progress = currentQuestion / questions.length;
tween(progressBar.scale, {
x: progress
}, {
duration: 300
});
} else {
showResults();
}
}
function selectAnswer(answerIndex) {
answers.push(answerIndex);
LK.setTimeout(function () {
currentQuestion++;
updateQuestion();
}, 500);
}
function calculateResult() {
var scores = [];
for (var i = 0; i < characters.length; i++) {
scores[i] = 0;
for (var j = 0; j < answers.length; j++) {
if (characters[i].traits[j] === answers[j]) {
scores[i]++;
}
}
}
var bestMatch = 0;
var bestScore = scores[0];
for (var k = 1; k < scores.length; k++) {
if (scores[k] > bestScore) {
bestScore = scores[k];
bestMatch = k;
}
}
var percentage = Math.round(bestScore / questions.length * 100);
return {
character: characters[bestMatch],
percentage: percentage
};
}
function showResults() {
gameState = 'results';
LK.getSound('resultReveal').play();
// Hide quiz elements
titleText.visible = false;
progressBg.visible = false;
progressBar.visible = false;
questionCard.visible = false;
for (var i = 0; i < answerButtons.length; i++) {
answerButtons[i].visible = false;
}
// Show results
var result = calculateResult();
resultScreen = new ResultScreen();
resultScreen.x = 1024;
resultScreen.y = 1366;
resultScreen.setResult(result.character, result.percentage);
game.addChild(resultScreen);
LK.setScore(result.percentage);
}
function restartQuiz() {
gameState = 'quiz';
currentQuestion = 0;
answers = [];
// Show quiz elements
titleText.visible = true;
progressBg.visible = true;
progressBar.visible = true;
questionCard.visible = true;
for (var i = 0; i < answerButtons.length; i++) {
answerButtons[i].visible = true;
}
// Hide results
if (resultScreen) {
resultScreen.destroy();
resultScreen = null;
}
// Reset progress
progressBar.scale.x = 0;
updateQuestion();
}
// Initialize first question
updateQuestion();
game.update = function () {
// Handle hover effects for answer buttons
if (gameState === 'quiz') {
// Reset all hover states
for (var i = 0; i < answerButtons.length; i++) {
answerButtons[i].setHover(false);
}
}
};