/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var AnswerButton = Container.expand(function (text, isCorrect, onAnswer) {
var self = Container.call(this);
self.isCorrect = isCorrect;
self.onAnswer = onAnswer;
self.answered = false;
var buttonBg = self.attachAsset('answerButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 48,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.setText = function (newText) {
buttonText.setText(newText);
};
self.setCorrect = function () {
self.removeChild(buttonBg);
buttonBg = self.attachAsset('correctButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChildAt(buttonBg, 0);
};
self.setIncorrect = function () {
self.removeChild(buttonBg);
buttonBg = self.attachAsset('incorrectButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChildAt(buttonBg, 0);
};
self.reset = function () {
self.answered = false;
self.removeChild(buttonBg);
buttonBg = self.attachAsset('answerButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChildAt(buttonBg, 0);
};
self.down = function (x, y, obj) {
if (!self.answered && self.onAnswer) {
self.onAnswer(self.isCorrect, self);
}
};
return self;
});
var Flag = Container.expand(function (countryData) {
var self = Container.call(this);
self.countryData = countryData;
var flagBg = self.attachAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0.5
});
// Create flag pattern based on country data
self.createFlagPattern = function () {
var pattern = self.countryData.pattern;
var colors = self.countryData.colors;
if (pattern === 'horizontal') {
var stripeHeight = 300 / colors.length;
for (var i = 0; i < colors.length; i++) {
var stripe = LK.getAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0,
scaleY: stripeHeight / 300
});
stripe.tint = colors[i];
stripe.y = -150 + i * stripeHeight;
self.addChild(stripe);
}
} else if (pattern === 'vertical') {
var stripeWidth = 400 / colors.length;
for (var i = 0; i < colors.length; i++) {
var stripe = LK.getAsset('flagBackground', {
anchorX: 0,
anchorY: 0.5,
scaleX: stripeWidth / 400
});
stripe.tint = colors[i];
stripe.x = -200 + i * stripeWidth;
self.addChild(stripe);
}
} else if (pattern === 'american') {
// Create 13 horizontal stripes
var stripeHeight = 300 / 13;
var stripeColors = [0xb22234, 0xffffff]; // Red and white
for (var i = 0; i < 13; i++) {
var stripe = LK.getAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0,
scaleY: stripeHeight / 300
});
stripe.tint = stripeColors[i % 2];
stripe.y = -150 + i * stripeHeight;
self.addChild(stripe);
}
// Create blue canton (upper left rectangle)
var canton = LK.getAsset('flagBackground', {
anchorX: 0,
anchorY: 0,
scaleX: 0.4,
// 40% of flag width
scaleY: 0.37 // 7/13 of flag height
});
canton.tint = 0x002868; // Blue
canton.x = -200;
canton.y = -150;
self.addChild(canton);
// Add stars to canton (simplified as white circles)
var starRows = [6, 5, 6, 5, 6, 5, 6, 5, 6]; // 50 stars pattern
var starY = -130;
for (var row = 0; row < starRows.length; row++) {
var starsInRow = starRows[row];
var starSpacing = 140 / (starsInRow + 1);
for (var star = 0; star < starsInRow; star++) {
var starCircle = LK.getAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.03,
scaleY: 0.03
});
starCircle.tint = 0xffffff; // White
starCircle.x = -200 + starSpacing * (star + 1);
starCircle.y = starY + row * 12;
self.addChild(starCircle);
}
}
} else if (pattern === 'nordic_cross') {
// Background color
flagBg.tint = colors[0];
// Vertical cross bar
var verticalBar = LK.getAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.15,
scaleY: 1
});
verticalBar.tint = colors[1];
verticalBar.x = -40; // Offset to left
self.addChild(verticalBar);
// Horizontal cross bar
var horizontalBar = LK.getAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1,
scaleY: 0.15
});
horizontalBar.tint = colors[1];
self.addChild(horizontalBar);
} else if (pattern === 'cross') {
// Background color
flagBg.tint = colors[0];
// Vertical cross bar
var verticalBar = LK.getAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 1
});
verticalBar.tint = colors[1];
self.addChild(verticalBar);
// Horizontal cross bar
var horizontalBar = LK.getAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1,
scaleY: 0.2
});
horizontalBar.tint = colors[1];
self.addChild(horizontalBar);
} else if (pattern === 'diagonal') {
// Background color
flagBg.tint = colors[0];
// Create diagonal stripes by using rotated rectangles
for (var i = 0; i < 8; i++) {
var diagonalStripe = LK.getAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.15,
scaleY: 2
});
diagonalStripe.tint = colors[1];
diagonalStripe.rotation = Math.PI / 4; // 45 degrees
diagonalStripe.x = -150 + i * 75;
self.addChild(diagonalStripe);
}
} else if (pattern === 'triangle') {
// Background color
flagBg.tint = colors[0];
// Create triangle using scaled rectangles
var triangle1 = LK.getAsset('flagBackground', {
anchorX: 0,
anchorY: 0,
scaleX: 0.5,
scaleY: 1
});
triangle1.tint = colors[1];
triangle1.x = -200;
triangle1.y = -150;
self.addChild(triangle1);
} else if (pattern === 'australian') {
// Blue background
flagBg.tint = colors[0];
// Union Jack in upper left corner
var unionJack = LK.getAsset('flagBackground', {
anchorX: 0,
anchorY: 0,
scaleX: 0.5,
scaleY: 0.5
});
unionJack.tint = 0x012169; // Dark blue
unionJack.x = -200;
unionJack.y = -150;
self.addChild(unionJack);
// Add simplified Union Jack cross pattern
var redCross1 = LK.getAsset('flagBackground', {
anchorX: 0,
anchorY: 0,
scaleX: 0.5,
scaleY: 0.05
});
redCross1.tint = 0xC8102E; // Red
redCross1.x = -200;
redCross1.y = -75;
self.addChild(redCross1);
var redCross2 = LK.getAsset('flagBackground', {
anchorX: 0,
anchorY: 0,
scaleX: 0.05,
scaleY: 0.5
});
redCross2.tint = 0xC8102E; // Red
redCross2.x = -100;
redCross2.y = -150;
self.addChild(redCross2);
// Southern Cross stars (simplified as white circles)
var starPositions = [{
x: 50,
y: -50
}, {
x: 100,
y: 0
}, {
x: 120,
y: 50
}, {
x: 80,
y: 100
}, {
x: 40,
y: 80
}];
for (var i = 0; i < starPositions.length; i++) {
var star = LK.getAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.06,
scaleY: 0.06
});
star.tint = 0xFFFFFF; // White
star.x = starPositions[i].x;
star.y = starPositions[i].y;
self.addChild(star);
}
} else if (pattern === 'solid') {
flagBg.tint = colors[0];
// Special case for Japan - add red circle
if (self.countryData.name === 'Japan') {
var circle = LK.getAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.4,
scaleY: 0.4
});
circle.tint = 0xbc002d;
self.addChild(circle);
}
}
};
self.createFlagPattern();
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Flag data - simplified flag patterns
var flagData = [{
name: 'France',
pattern: 'vertical',
colors: [0x0055a4, 0xffffff, 0xef4135]
}, {
name: 'Germany',
pattern: 'horizontal',
colors: [0x000000, 0xdd0000, 0xffce00]
}, {
name: 'Italy',
pattern: 'vertical',
colors: [0x009246, 0xffffff, 0xce2b37]
}, {
name: 'Spain',
pattern: 'horizontal',
colors: [0xaa151b, 0xf1bf00, 0xaa151b]
}, {
name: 'Netherlands',
pattern: 'horizontal',
colors: [0xae1c28, 0xffffff, 0x21468b]
}, {
name: 'Belgium',
pattern: 'vertical',
colors: [0x000000, 0xffd700, 0xed2939]
}, {
name: 'Poland',
pattern: 'horizontal',
colors: [0xffffff, 0xdc143c]
}, {
name: 'Ukraine',
pattern: 'horizontal',
colors: [0x005bbb, 0xffd700]
}, {
name: 'Ireland',
pattern: 'vertical',
colors: [0x169b62, 0xffffff, 0xff883e]
}, {
name: 'Austria',
pattern: 'horizontal',
colors: [0xed2939, 0xffffff, 0xed2939]
}, {
name: 'Hungary',
pattern: 'horizontal',
colors: [0xcd212a, 0xffffff, 0x436f4d]
}, {
name: 'Romania',
pattern: 'vertical',
colors: [0x002b7f, 0xfcd116, 0xce1126]
}, {
name: 'Bulgaria',
pattern: 'horizontal',
colors: [0xffffff, 0x00966e, 0xd62612]
}, {
name: 'Lithuania',
pattern: 'horizontal',
colors: [0xfdb462, 0x006a44, 0xc1272d]
}, {
name: 'Latvia',
pattern: 'horizontal',
colors: [0x9e3039, 0xffffff, 0x9e3039]
}, {
name: 'Estonia',
pattern: 'horizontal',
colors: [0x0072ce, 0x000000, 0xffffff]
}, {
name: 'Finland',
pattern: 'nordic_cross',
colors: [0xffffff, 0x003580]
}, {
name: 'Sweden',
pattern: 'nordic_cross',
colors: [0x006aa7, 0xfecc00]
}, {
name: 'Norway',
pattern: 'nordic_cross',
colors: [0xef2b2d, 0x002868]
}, {
name: 'Denmark',
pattern: 'nordic_cross',
colors: [0xc8102e, 0xffffff]
}, {
name: 'Australia',
pattern: 'australian',
colors: [0x00008b, 0xffffff]
}, {
name: 'America',
pattern: 'american',
colors: [0xb22234, 0xffffff, 0x002868]
}, {
name: 'Japan',
pattern: 'solid',
colors: [0xffffff]
}];
var currentFlag = null;
var answerButtons = [];
var correctAnswer = '';
var gameActive = true;
var nextQuestionTimer = null;
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 100;
var questionText = new Text2('Which country does this flag belong to?', {
size: 48,
fill: 0xFFFFFF
});
questionText.anchor.set(0.5, 0.5);
questionText.x = 1024;
questionText.y = 600;
game.addChild(questionText);
// Initialize answer buttons
for (var i = 0; i < 4; i++) {
var button = new AnswerButton('', false, handleAnswer);
button.x = 1024;
button.y = 800 + i * 150;
answerButtons.push(button);
game.addChild(button);
}
function getRandomCountries(correctCountry, count) {
var countries = [];
countries.push(correctCountry);
var availableCountries = flagData.filter(function (country) {
return country.name !== correctCountry.name;
});
while (countries.length < count && availableCountries.length > 0) {
var randomIndex = Math.floor(Math.random() * availableCountries.length);
countries.push(availableCountries[randomIndex]);
availableCountries.splice(randomIndex, 1);
}
return countries;
}
function shuffleArray(array) {
var shuffled = array.slice();
for (var i = shuffled.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = shuffled[i];
shuffled[i] = shuffled[j];
shuffled[j] = temp;
}
return shuffled;
}
function generateNewQuestion() {
gameActive = true;
// Clear previous flag
if (currentFlag) {
currentFlag.destroy();
}
// Select random correct answer
var correctCountry = flagData[Math.floor(Math.random() * flagData.length)];
correctAnswer = correctCountry.name;
// Create flag
currentFlag = new Flag(correctCountry);
currentFlag.x = 1024;
currentFlag.y = 400;
game.addChild(currentFlag);
// Get 4 random countries including the correct one
var countries = getRandomCountries(correctCountry, 4);
var shuffledCountries = shuffleArray(countries);
// Set up answer buttons
for (var i = 0; i < answerButtons.length; i++) {
var button = answerButtons[i];
var country = shuffledCountries[i];
button.setText(country.name);
button.isCorrect = country.name === correctAnswer;
button.reset();
}
}
function handleAnswer(isCorrect, button) {
if (!gameActive) return;
gameActive = false;
button.answered = true;
// Mark all buttons as answered to prevent further clicks
for (var i = 0; i < answerButtons.length; i++) {
answerButtons[i].answered = true;
}
if (isCorrect) {
button.setCorrect();
LK.setScore(LK.getScore() + 1);
scoreText.setText('Score: ' + LK.getScore());
LK.getSound('correct').play();
// Flash screen green briefly
LK.effects.flashScreen(0x7ed321, 300);
} else {
button.setIncorrect();
LK.getSound('incorrect').play();
// Show correct answer
for (var i = 0; i < answerButtons.length; i++) {
if (answerButtons[i].isCorrect) {
answerButtons[i].setCorrect();
break;
}
}
// Flash screen red briefly
LK.effects.flashScreen(0xd0021b, 300);
}
// Schedule next question
nextQuestionTimer = LK.setTimeout(function () {
generateNewQuestion();
}, 2000);
}
// Start first question
generateNewQuestion();
game.update = function () {
// Update score display
scoreText.setText('Score: ' + LK.getScore());
}; ===================================================================
--- original.js
+++ change.js
@@ -135,8 +135,145 @@
starCircle.y = starY + row * 12;
self.addChild(starCircle);
}
}
+ } else if (pattern === 'nordic_cross') {
+ // Background color
+ flagBg.tint = colors[0];
+ // Vertical cross bar
+ var verticalBar = LK.getAsset('flagBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.15,
+ scaleY: 1
+ });
+ verticalBar.tint = colors[1];
+ verticalBar.x = -40; // Offset to left
+ self.addChild(verticalBar);
+ // Horizontal cross bar
+ var horizontalBar = LK.getAsset('flagBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 1,
+ scaleY: 0.15
+ });
+ horizontalBar.tint = colors[1];
+ self.addChild(horizontalBar);
+ } else if (pattern === 'cross') {
+ // Background color
+ flagBg.tint = colors[0];
+ // Vertical cross bar
+ var verticalBar = LK.getAsset('flagBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.2,
+ scaleY: 1
+ });
+ verticalBar.tint = colors[1];
+ self.addChild(verticalBar);
+ // Horizontal cross bar
+ var horizontalBar = LK.getAsset('flagBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 1,
+ scaleY: 0.2
+ });
+ horizontalBar.tint = colors[1];
+ self.addChild(horizontalBar);
+ } else if (pattern === 'diagonal') {
+ // Background color
+ flagBg.tint = colors[0];
+ // Create diagonal stripes by using rotated rectangles
+ for (var i = 0; i < 8; i++) {
+ var diagonalStripe = LK.getAsset('flagBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.15,
+ scaleY: 2
+ });
+ diagonalStripe.tint = colors[1];
+ diagonalStripe.rotation = Math.PI / 4; // 45 degrees
+ diagonalStripe.x = -150 + i * 75;
+ self.addChild(diagonalStripe);
+ }
+ } else if (pattern === 'triangle') {
+ // Background color
+ flagBg.tint = colors[0];
+ // Create triangle using scaled rectangles
+ var triangle1 = LK.getAsset('flagBackground', {
+ anchorX: 0,
+ anchorY: 0,
+ scaleX: 0.5,
+ scaleY: 1
+ });
+ triangle1.tint = colors[1];
+ triangle1.x = -200;
+ triangle1.y = -150;
+ self.addChild(triangle1);
+ } else if (pattern === 'australian') {
+ // Blue background
+ flagBg.tint = colors[0];
+ // Union Jack in upper left corner
+ var unionJack = LK.getAsset('flagBackground', {
+ anchorX: 0,
+ anchorY: 0,
+ scaleX: 0.5,
+ scaleY: 0.5
+ });
+ unionJack.tint = 0x012169; // Dark blue
+ unionJack.x = -200;
+ unionJack.y = -150;
+ self.addChild(unionJack);
+ // Add simplified Union Jack cross pattern
+ var redCross1 = LK.getAsset('flagBackground', {
+ anchorX: 0,
+ anchorY: 0,
+ scaleX: 0.5,
+ scaleY: 0.05
+ });
+ redCross1.tint = 0xC8102E; // Red
+ redCross1.x = -200;
+ redCross1.y = -75;
+ self.addChild(redCross1);
+ var redCross2 = LK.getAsset('flagBackground', {
+ anchorX: 0,
+ anchorY: 0,
+ scaleX: 0.05,
+ scaleY: 0.5
+ });
+ redCross2.tint = 0xC8102E; // Red
+ redCross2.x = -100;
+ redCross2.y = -150;
+ self.addChild(redCross2);
+ // Southern Cross stars (simplified as white circles)
+ var starPositions = [{
+ x: 50,
+ y: -50
+ }, {
+ x: 100,
+ y: 0
+ }, {
+ x: 120,
+ y: 50
+ }, {
+ x: 80,
+ y: 100
+ }, {
+ x: 40,
+ y: 80
+ }];
+ for (var i = 0; i < starPositions.length; i++) {
+ var star = LK.getAsset('flagBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.06,
+ scaleY: 0.06
+ });
+ star.tint = 0xFFFFFF; // White
+ star.x = starPositions[i].x;
+ star.y = starPositions[i].y;
+ self.addChild(star);
+ }
} else if (pattern === 'solid') {
flagBg.tint = colors[0];
// Special case for Japan - add red circle
if (self.countryData.name === 'Japan') {
@@ -231,26 +368,26 @@
pattern: 'horizontal',
colors: [0x0072ce, 0x000000, 0xffffff]
}, {
name: 'Finland',
- pattern: 'solid',
- colors: [0xffffff]
+ pattern: 'nordic_cross',
+ colors: [0xffffff, 0x003580]
}, {
name: 'Sweden',
- pattern: 'solid',
- colors: [0x006aa7]
+ pattern: 'nordic_cross',
+ colors: [0x006aa7, 0xfecc00]
}, {
name: 'Norway',
- pattern: 'solid',
- colors: [0xef2b2d]
+ pattern: 'nordic_cross',
+ colors: [0xef2b2d, 0x002868]
}, {
name: 'Denmark',
- pattern: 'solid',
- colors: [0xc8102e]
+ pattern: 'nordic_cross',
+ colors: [0xc8102e, 0xffffff]
}, {
name: 'Australia',
- pattern: 'solid',
- colors: [0x00008b]
+ pattern: 'australian',
+ colors: [0x00008b, 0xffffff]
}, {
name: 'America',
pattern: 'american',
colors: [0xb22234, 0xffffff, 0x002868]