/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var LetterBox = Container.expand(function (letter, isCompleted, isLocked) {
var self = Container.call(this);
self.letter = letter;
self.isCompleted = isCompleted || false;
self.isLocked = isLocked || false;
// Choose appropriate background based on state
var boxType = 'letterBox';
if (self.isCompleted) {
boxType = 'completedLetterBox';
} else if (self.isLocked) {
boxType = 'lockedLetterBox';
}
var box = self.attachAsset(boxType, {
anchorX: 0.5,
anchorY: 0.5
});
// Add letter text
var letterText = new Text2(letter, {
size: 120,
fill: self.isLocked ? "#666666" : "#FFFFFF"
});
letterText.anchor.set(0.5, 0.5);
letterText.x = 0;
letterText.y = 0;
self.addChild(letterText);
// Add star if completed
if (self.isCompleted) {
var star = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5,
x: 70,
y: -70
});
}
self.down = function (x, y, obj) {
if (!self.isLocked) {
// Scale animation on touch
tween(self, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
// Switch to letter activity
currentGameState = 'letterActivity';
currentLetter = self.letter;
setupLetterActivity(self.letter);
}
};
return self;
});
var NumberBox = Container.expand(function (number, isCompleted, isLocked) {
var self = Container.call(this);
self.number = number;
self.isCompleted = isCompleted || false;
self.isLocked = isLocked || false;
// Choose appropriate background based on state
var boxType = 'letterBox';
if (self.isCompleted) {
boxType = 'completedLetterBox';
} else if (self.isLocked) {
boxType = 'lockedLetterBox';
}
var box = self.attachAsset(boxType, {
anchorX: 0.5,
anchorY: 0.5
});
// Add number text
var numberText = new Text2(number, {
size: 120,
fill: self.isLocked ? "#666666" : "#FFFFFF"
});
numberText.anchor.set(0.5, 0.5);
numberText.x = 0;
numberText.y = 0;
self.addChild(numberText);
// Add star if completed
if (self.isCompleted) {
var star = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5,
x: 70,
y: -70
});
}
self.down = function (x, y, obj) {
if (!self.isLocked) {
// Scale animation on touch
tween(self, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
// Switch to number activity
currentGameState = 'numberActivity';
currentNumber = self.number;
setupNumberActivity(self.number);
}
};
return self;
});
var TraceDot = Container.expand(function (x, y, index) {
var self = Container.call(this);
self.x = x;
self.y = y;
self.index = index;
self.isCompleted = false;
var dot = self.attachAsset('traceDot', {
anchorX: 0.5,
anchorY: 0.5
});
self.complete = function () {
if (!self.isCompleted) {
self.isCompleted = true;
self.removeChild(dot);
var completedDot = self.attachAsset('completedDot', {
anchorX: 0.5,
anchorY: 0.5
});
// Celebration animation
tween(self, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
LK.getSound('correctAction').play();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// X pattern is already implemented in the letterPatterns object
var currentGameState = 'mainSelection'; // 'mainSelection', 'letterSelection', 'letterActivity', 'numberSelection', 'numberActivity', 'sumsActivity'
var currentSum1 = 0;
var currentSum2 = 0;
var currentAnswer = 0;
var sumsCompleted = 0; // Track number of problems completed
var currentDifficulty = 1; // Current difficulty level (1-5)
var sumsProblemText;
var sumsAnswerText;
var currentLetter = '';
var currentNumber = '';
var unlockedLetters = storage.unlockedLetters || 1; // Number of unlocked letters (A=1, B=2, etc.)
var completedLetters = storage.completedLetters || [];
var unlockedNumbers = storage.unlockedNumbers || 1; // Number of unlocked numbers (1=1, 2=2, etc.)
var completedNumbers = storage.completedNumbers || [];
var letterBoxes = [];
var numberBoxes = [];
var traceDots = [];
var currentTraceIndex = 0;
var dotNumbers = []; // Array to store number indicators
var numberButtons = []; // Array to store number input buttons
var currentUserInput = ''; // Store current user input for sums
var userInputText; // Reference to user input text display
var feedbackText; // Reference to feedback text display
// Letter patterns for tracing (properly positioned and shaped)
var letterPatterns = {
'A': [{
x: 1024,
y: 1400
}, {
x: 974,
y: 1500
}, {
x: 924,
y: 1600
}, {
x: 874,
y: 1700
}, {
x: 824,
y: 1800
}, {
x: 1024,
y: 1400
}, {
x: 1074,
y: 1500
}, {
x: 1124,
y: 1600
}, {
x: 1174,
y: 1700
}, {
x: 1224,
y: 1800
}, {
x: 874,
y: 1650
}, {
x: 924,
y: 1650
}, {
x: 974,
y: 1650
}, {
x: 1024,
y: 1650
}, {
x: 1074,
y: 1650
}, {
x: 1124,
y: 1650
}, {
x: 1174,
y: 1650
}],
'B': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1450
}, {
x: 1000,
y: 1600
}, {
x: 1100,
y: 1600
}, {
x: 1150,
y: 1750
}, {
x: 1000,
y: 1800
}],
'C': [{
x: 1150,
y: 1450
}, {
x: 1000,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 1000,
y: 1800
}, {
x: 1150,
y: 1750
}],
'D': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1450
}, {
x: 1150,
y: 1600
}, {
x: 1100,
y: 1750
}, {
x: 1000,
y: 1800
}],
'E': [{
x: 900,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1100,
y: 1800
}, {
x: 1150,
y: 1800
}],
'F': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}],
'G': [{
x: 1150,
y: 1450
}, {
x: 1000,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 1000,
y: 1800
}, {
x: 1150,
y: 1750
}, {
x: 1150,
y: 1650
}, {
x: 1100,
y: 1650
}],
'H': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1100,
y: 1600
}, {
x: 1100,
y: 1500
}, {
x: 1100,
y: 1400
}, {
x: 1100,
y: 1700
}, {
x: 1100,
y: 1800
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}],
'I': [{
x: 900,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1000,
y: 1500
}, {
x: 1000,
y: 1600
}, {
x: 1000,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1100,
y: 1800
}],
'J': [{
x: 850,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 1050,
y: 1500
}, {
x: 1050,
y: 1600
}, {
x: 1050,
y: 1700
}, {
x: 1000,
y: 1800
}, {
x: 900,
y: 1750
}],
'K': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1100,
y: 1400
}, {
x: 1050,
y: 1450
}, {
x: 1000,
y: 1500
}, {
x: 950,
y: 1550
}, {
x: 900,
y: 1600
}, {
x: 950,
y: 1650
}, {
x: 1000,
y: 1700
}, {
x: 1050,
y: 1750
}, {
x: 1100,
y: 1800
}],
'L': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1100,
y: 1800
}, {
x: 1150,
y: 1800
}],
'M': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 950,
y: 1450
}, {
x: 1000,
y: 1500
}, {
x: 1024,
y: 1550
}, {
x: 1050,
y: 1500
}, {
x: 1100,
y: 1450
}, {
x: 1150,
y: 1400
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1800
}],
'N': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 950,
y: 1450
}, {
x: 1000,
y: 1500
}, {
x: 1050,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1150,
y: 1650
}, {
x: 1150,
y: 1400
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1800
}],
'O': [{
x: 1024,
y: 1400
}, {
x: 1100,
y: 1430
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1700
}, {
x: 1100,
y: 1770
}, {
x: 1024,
y: 1800
}, {
x: 948,
y: 1770
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1500
}, {
x: 948,
y: 1430
}, {
x: 1024,
y: 1400
}],
'P': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1450
}, {
x: 1150,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1000,
y: 1600
}],
'Q': [{
x: 1024,
y: 1400
}, {
x: 1100,
y: 1430
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1700
}, {
x: 1100,
y: 1770
}, {
x: 1024,
y: 1800
}, {
x: 948,
y: 1770
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1500
}, {
x: 948,
y: 1430
}, {
x: 1024,
y: 1400
}, {
x: 1050,
y: 1650
}, {
x: 1100,
y: 1700
}, {
x: 1150,
y: 1750
}, {
x: 1200,
y: 1800
}],
'R': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1450
}, {
x: 1150,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1000,
y: 1650
}, {
x: 1050,
y: 1700
}, {
x: 1100,
y: 1750
}, {
x: 1150,
y: 1800
}],
'S': [{
x: 1150,
y: 1450
}, {
x: 1100,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 950,
y: 1430
}, {
x: 900,
y: 1480
}, {
x: 900,
y: 1530
}, {
x: 950,
y: 1580
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1100,
y: 1620
}, {
x: 1150,
y: 1670
}, {
x: 1150,
y: 1720
}, {
x: 1100,
y: 1770
}, {
x: 1000,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 900,
y: 1750
}],
'T': [{
x: 850,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 1200,
y: 1400
}, {
x: 1024,
y: 1400
}, {
x: 1024,
y: 1500
}, {
x: 1024,
y: 1600
}, {
x: 1024,
y: 1700
}, {
x: 1024,
y: 1800
}],
'U': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 950,
y: 1770
}, {
x: 1000,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1100,
y: 1770
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1400
}],
'V': [{
x: 900,
y: 1400
}, {
x: 920,
y: 1500
}, {
x: 940,
y: 1600
}, {
x: 960,
y: 1700
}, {
x: 980,
y: 1750
}, {
x: 1000,
y: 1780
}, {
x: 1024,
y: 1800
}, {
x: 1048,
y: 1780
}, {
x: 1068,
y: 1750
}, {
x: 1088,
y: 1700
}, {
x: 1108,
y: 1600
}, {
x: 1128,
y: 1500
}, {
x: 1150,
y: 1400
}],
'W': [{
x: 850,
y: 1400
}, {
x: 870,
y: 1500
}, {
x: 890,
y: 1600
}, {
x: 910,
y: 1700
}, {
x: 930,
y: 1750
}, {
x: 950,
y: 1800
}, {
x: 970,
y: 1750
}, {
x: 990,
y: 1700
}, {
x: 1010,
y: 1650
}, {
x: 1024,
y: 1600
}, {
x: 1038,
y: 1650
}, {
x: 1058,
y: 1700
}, {
x: 1078,
y: 1750
}, {
x: 1098,
y: 1800
}, {
x: 1118,
y: 1750
}, {
x: 1138,
y: 1700
}, {
x: 1158,
y: 1600
}, {
x: 1178,
y: 1500
}, {
x: 1200,
y: 1400
}],
'X': [{
x: 900,
y: 1400
}, {
x: 950,
y: 1450
}, {
x: 1000,
y: 1500
}, {
x: 1050,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1150,
y: 1650
}, {
x: 1200,
y: 1700
}, {
x: 1250,
y: 1750
}, {
x: 1300,
y: 1800
}, {
x: 1300,
y: 1400
}, {
x: 1250,
y: 1450
}, {
x: 1200,
y: 1500
}, {
x: 1150,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1050,
y: 1650
}, {
x: 1000,
y: 1700
}, {
x: 950,
y: 1750
}, {
x: 900,
y: 1800
}],
'Y': [{
x: 900,
y: 1400
}, {
x: 950,
y: 1450
}, {
x: 1000,
y: 1500
}, {
x: 1024,
y: 1550
}, {
x: 1024,
y: 1600
}, {
x: 1024,
y: 1650
}, {
x: 1024,
y: 1700
}, {
x: 1024,
y: 1750
}, {
x: 1024,
y: 1800
}, {
x: 1048,
y: 1500
}, {
x: 1098,
y: 1450
}, {
x: 1150,
y: 1400
}],
'Z': [{
x: 900,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 1100,
y: 1500
}, {
x: 1050,
y: 1550
}, {
x: 1000,
y: 1600
}, {
x: 950,
y: 1650
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1750
}, {
x: 900,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1100,
y: 1800
}, {
x: 1150,
y: 1800
}]
};
// Number patterns for tracing (digits 1-10)
var numberPatterns = {
'1': [{
x: 1024,
y: 1400
}, {
x: 1024,
y: 1500
}, {
x: 1024,
y: 1600
}, {
x: 1024,
y: 1700
}, {
x: 1024,
y: 1800
}, {
x: 974,
y: 1450
}, {
x: 924,
y: 1500
}],
'2': [{
x: 900,
y: 1450
}, {
x: 950,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1450
}, {
x: 1150,
y: 1500
}, {
x: 1100,
y: 1550
}, {
x: 1050,
y: 1600
}, {
x: 1000,
y: 1650
}, {
x: 950,
y: 1700
}, {
x: 900,
y: 1750
}, {
x: 900,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1100,
y: 1800
}, {
x: 1150,
y: 1800
}],
'3': [{
x: 900,
y: 1450
}, {
x: 950,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1450
}, {
x: 1150,
y: 1500
}, {
x: 1100,
y: 1550
}, {
x: 1050,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1100,
y: 1650
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1750
}, {
x: 1100,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 900,
y: 1750
}],
'4': [{
x: 1100,
y: 1400
}, {
x: 1100,
y: 1500
}, {
x: 1100,
y: 1600
}, {
x: 1100,
y: 1700
}, {
x: 1100,
y: 1800
}, {
x: 1050,
y: 1400
}, {
x: 1000,
y: 1450
}, {
x: 950,
y: 1500
}, {
x: 900,
y: 1550
}, {
x: 900,
y: 1600
}, {
x: 950,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1100,
y: 1600
}, {
x: 1150,
y: 1600
}],
'5': [{
x: 1150,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1550
}, {
x: 950,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1100,
y: 1600
}, {
x: 1150,
y: 1650
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1750
}, {
x: 1100,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 900,
y: 1750
}],
'6': [{
x: 1100,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 900,
y: 1450
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1550
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1650
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1750
}, {
x: 950,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1100,
y: 1800
}, {
x: 1150,
y: 1750
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1650
}, {
x: 1100,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 950,
y: 1600
}],
'7': [{
x: 900,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 1100,
y: 1500
}, {
x: 1050,
y: 1550
}, {
x: 1000,
y: 1600
}, {
x: 950,
y: 1650
}, {
x: 950,
y: 1700
}, {
x: 950,
y: 1750
}, {
x: 950,
y: 1800
}],
'8': [{
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1100,
y: 1430
}, {
x: 1150,
y: 1480
}, {
x: 1150,
y: 1530
}, {
x: 1100,
y: 1580
}, {
x: 1050,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 950,
y: 1600
}, {
x: 900,
y: 1580
}, {
x: 900,
y: 1530
}, {
x: 900,
y: 1480
}, {
x: 950,
y: 1430
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1600
}, {
x: 1100,
y: 1630
}, {
x: 1150,
y: 1680
}, {
x: 1150,
y: 1730
}, {
x: 1100,
y: 1780
}, {
x: 1050,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 900,
y: 1780
}, {
x: 900,
y: 1730
}, {
x: 900,
y: 1680
}, {
x: 950,
y: 1630
}],
'9': [{
x: 1050,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1450
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 950,
y: 1600
}, {
x: 900,
y: 1550
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1450
}, {
x: 950,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1650
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1750
}, {
x: 1150,
y: 1800
}],
'10': [{
x: 850,
y: 1400
}, {
x: 850,
y: 1500
}, {
x: 850,
y: 1600
}, {
x: 850,
y: 1700
}, {
x: 850,
y: 1800
}, {
x: 800,
y: 1450
}, {
x: 750,
y: 1500
}, {
x: 1150,
y: 1400
}, {
x: 1200,
y: 1430
}, {
x: 1250,
y: 1480
}, {
x: 1250,
y: 1530
}, {
x: 1250,
y: 1580
}, {
x: 1250,
y: 1630
}, {
x: 1250,
y: 1680
}, {
x: 1250,
y: 1730
}, {
x: 1200,
y: 1770
}, {
x: 1150,
y: 1800
}, {
x: 1100,
y: 1770
}, {
x: 1050,
y: 1730
}, {
x: 1050,
y: 1680
}, {
x: 1050,
y: 1630
}, {
x: 1050,
y: 1580
}, {
x: 1050,
y: 1530
}, {
x: 1050,
y: 1480
}, {
x: 1100,
y: 1430
}, {
x: 1150,
y: 1400
}]
};
// Add more basic patterns for other letters
for (var i = 0; i < 26; i++) {
var letter = String.fromCharCode(65 + i);
if (!letterPatterns[letter]) {
// Simple default pattern for letters not defined - centered and properly sized
letterPatterns[letter] = [{
x: 924,
y: 1400
}, {
x: 974,
y: 1500
}, {
x: 1024,
y: 1600
}, {
x: 1074,
y: 1700
}, {
x: 1124,
y: 1800
}];
}
}
// UI Elements
var titleText = new Text2('ABC Learning Adventure', {
size: 100,
fill: 0x2E7D32
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
function setupMainSelection() {
currentGameState = 'mainSelection';
// Clear existing elements
game.removeChildren();
// Add title
var mainTitle = new Text2('Learning Adventure', {
size: 120,
fill: 0x2E7D32
});
mainTitle.anchor.set(0.5, 0.5);
mainTitle.x = 1024;
mainTitle.y = 600;
game.addChild(mainTitle);
// Add Letters button
var lettersButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 700,
y: 1200
});
game.addChild(lettersButton);
var lettersText = new Text2('LETTERS\nA-Z', {
size: 80,
fill: 0xFFFFFF
});
lettersText.anchor.set(0.5, 0.5);
lettersText.x = 700;
lettersText.y = 1200;
game.addChild(lettersText);
// Add Numbers button
var numbersButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1348,
y: 1200
});
game.addChild(numbersButton);
var numbersText = new Text2('NUMBERS\n1-10', {
size: 80,
fill: 0xFFFFFF
});
numbersText.anchor.set(0.5, 0.5);
numbersText.x = 1348;
numbersText.y = 1200;
game.addChild(numbersText);
// Add Sums button
var sumsButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1600
});
game.addChild(sumsButton);
var sumsText = new Text2('SUMAS\n1+1=2', {
size: 80,
fill: 0xFFFFFF
});
sumsText.anchor.set(0.5, 0.5);
sumsText.x = 1024;
sumsText.y = 1600;
game.addChild(sumsText);
// Add progress indicators
var letterProgress = new Text2('Letters: ' + completedLetters.length + '/26', {
size: 50,
fill: 0x424242
});
letterProgress.anchor.set(0.5, 0.5);
letterProgress.x = 700;
letterProgress.y = 1400;
game.addChild(letterProgress);
var numberProgress = new Text2('Numbers: ' + completedNumbers.length + '/10', {
size: 50,
fill: 0x424242
});
numberProgress.anchor.set(0.5, 0.5);
numberProgress.x = 1348;
numberProgress.y = 1400;
game.addChild(numberProgress);
var sumsProgress = new Text2('Sums: Level ' + currentDifficulty + ' (' + sumsCompleted + ' completed)', {
size: 50,
fill: 0x424242
});
sumsProgress.anchor.set(0.5, 0.5);
sumsProgress.x = 1024;
sumsProgress.y = 1800;
game.addChild(sumsProgress);
// Add palm trees on the sides as Sprites
var leftPalmTree = LK.getAsset('palmTree', {
anchorX: 0.5,
anchorY: 1.0,
x: 150,
y: 2700
});
game.addChild(leftPalmTree);
var rightPalmTree = LK.getAsset('palmTree', {
anchorX: 0.5,
anchorY: 1.0,
x: 1900,
y: 2700
});
game.addChild(rightPalmTree);
// Add grass under palm trees
var leftGrass = LK.getAsset('grass', {
anchorX: 0.5,
anchorY: 1.0,
x: 150,
y: 2700
});
game.addChild(leftGrass);
var rightGrass = LK.getAsset('grass', {
anchorX: 0.5,
anchorY: 1.0,
x: 1900,
y: 2700
});
game.addChild(rightGrass);
// Add grass in the center between palm trees as a Sprite
var centerGrass = LK.getAsset('grass', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: 2700
});
game.addChild(centerGrass);
}
var backButton = new Text2('← Back', {
size: 80,
fill: 0x1976D2
});
backButton.anchor.set(0, 0);
backButton.x = 150;
backButton.y = 100;
var progressText = new Text2('Progress: 0/26', {
size: 60,
fill: 0x424242
});
progressText.anchor.set(0.5, 0);
progressText.x = 1024;
progressText.y = 200;
function setupLetterSelection() {
currentGameState = 'letterSelection';
// Clear existing elements
game.removeChildren();
// Add progress text
game.addChild(progressText);
progressText.setText('Progress: ' + completedLetters.length + '/26');
// Add restart button
var restartButton = new Text2('🔄 Restart', {
size: 60,
fill: 0xE53935
});
restartButton.anchor.set(1, 0);
restartButton.x = 1900;
restartButton.y = 200;
game.addChild(restartButton);
// Add back button for letter selection
var backToMainFromLetters = new Text2('← Back', {
size: 80,
fill: 0x1976D2
});
backToMainFromLetters.anchor.set(0, 0);
backToMainFromLetters.x = 150;
backToMainFromLetters.y = 100;
game.addChild(backToMainFromLetters);
// Make back button interactive
backToMainFromLetters.down = function (x, y, obj) {
setupMainSelection();
};
// Create letter grid (6x5 layout with last row having 2 letters)
letterBoxes = [];
var startX = 200;
var startY = 400;
var spacing = 300;
for (var i = 0; i < 26; i++) {
var letter = String.fromCharCode(65 + i);
var row = Math.floor(i / 6);
var col = i % 6;
// Center the last row (U, V, W, X, Y, Z)
var x = startX + col * spacing;
if (row === 4) {
x = startX + (col + 1) * spacing;
}
var y = startY + row * spacing;
var isCompleted = completedLetters.indexOf(letter) !== -1;
var isLocked = i + 1 > unlockedLetters;
var letterBox = new LetterBox(letter, isCompleted, isLocked);
letterBox.x = x;
letterBox.y = y;
letterBoxes.push(letterBox);
game.addChild(letterBox);
}
}
function setupNumberSelection() {
currentGameState = 'numberSelection';
// Clear existing elements
game.removeChildren();
// Add progress text
var numberProgressText = new Text2('Progress: ' + completedNumbers.length + '/10', {
size: 60,
fill: 0x424242
});
numberProgressText.anchor.set(0.5, 0);
numberProgressText.x = 1024;
numberProgressText.y = 200;
game.addChild(numberProgressText);
// Add back button
var backToMainButton = new Text2('← Back', {
size: 80,
fill: 0x1976D2
});
backToMainButton.anchor.set(0, 0);
backToMainButton.x = 150;
backToMainButton.y = 100;
game.addChild(backToMainButton);
// Make back button interactive
backToMainButton.down = function (x, y, obj) {
setupMainSelection();
};
// Create number grid (2 rows of 5)
numberBoxes = [];
var startX = 300;
var startY = 600;
var spacing = 300;
for (var i = 0; i < 10; i++) {
var number = (i + 1).toString();
var row = Math.floor(i / 5);
var col = i % 5;
var x = startX + col * spacing;
var y = startY + row * spacing;
var isCompleted = completedNumbers.indexOf(number) !== -1;
var isLocked = i + 1 > unlockedNumbers;
var numberBox = new NumberBox(number, isCompleted, isLocked);
numberBox.x = x;
numberBox.y = y;
numberBoxes.push(numberBox);
game.addChild(numberBox);
}
}
function setupLetterActivity(letter) {
currentGameState = 'letterActivity';
// Clear existing elements
game.removeChildren();
// Add background
var background = game.attachAsset('traceBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
// Add back button
game.addChild(backButton);
// Make back button interactive
backButton.down = function (x, y, obj) {
setupLetterSelection();
};
// Add instruction text
var instructionText = new Text2('Trace the letter ' + letter + ' by touching the dots in order', {
size: 80,
fill: 0x2E7D32
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 300;
game.addChild(instructionText);
// Add starting point instruction
var startText = new Text2('Look for "START" to see where to begin!', {
size: 60,
fill: 0xFF5722
});
startText.anchor.set(0.5, 0.5);
startText.x = 1024;
startText.y = 380;
game.addChild(startText);
// Note: Number indicators removed since dots are now randomly positioned
// Create trace dots with fixed positions from pattern
traceDots = [];
currentTraceIndex = 0;
var pattern = letterPatterns[letter];
dotNumbers = []; // Reset number indicators array
for (var i = 0; i < pattern.length; i++) {
var dot = new TraceDot(pattern[i].x, pattern[i].y, i);
traceDots.push(dot);
game.addChild(dot);
// Add number indicator for each dot (1-10, then continue with higher numbers)
var numberText = (i + 1).toString();
var numberIndicator = new Text2(numberText, {
size: 50,
fill: 0x000000
});
numberIndicator.anchor.set(0.5, 0.5);
numberIndicator.x = pattern[i].x;
numberIndicator.y = pattern[i].y;
// Add white circle background for better visibility
var numberBackground = LK.getAsset('traceDot', {
anchorX: 0.5,
anchorY: 0.5,
x: pattern[i].x,
y: pattern[i].y,
scaleX: 1.2,
scaleY: 1.2
});
numberBackground.tint = 0xFFFFFF;
game.addChild(numberBackground);
// Add number to front
game.addChild(numberIndicator);
dotNumbers.push({
number: numberIndicator,
background: numberBackground
});
}
// Add starting point indicator for the first dot
if (traceDots.length > 0) {
var startIndicator = new Text2('START', {
size: 40,
fill: 0xFF5722
});
startIndicator.anchor.set(0.5, 0.5);
startIndicator.x = traceDots[0].x;
startIndicator.y = traceDots[0].y - 60;
game.addChild(startIndicator);
// Add arrow pointing to start
var arrowText = new Text2('↓', {
size: 60,
fill: 0xFF5722
});
arrowText.anchor.set(0.5, 0.5);
arrowText.x = traceDots[0].x;
arrowText.y = traceDots[0].y - 30;
game.addChild(arrowText);
// Animate the starting indicators
tween(startIndicator, {
alpha: 0.3
}, {
duration: 800
});
tween(startIndicator, {
alpha: 1.0
}, {
duration: 800
});
tween(arrowText, {
alpha: 0.3
}, {
duration: 800
});
tween(arrowText, {
alpha: 1.0
}, {
duration: 800
});
// Animate the first number
if (dotNumbers.length > 0) {
tween(dotNumbers[0].number, {
alpha: 0.3
}, {
duration: 800
});
tween(dotNumbers[0].number, {
alpha: 1.0
}, {
duration: 800
});
}
}
// Highlight first dot
if (traceDots.length > 0) {
tween(traceDots[0], {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 500
});
tween(traceDots[0], {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 500
});
}
}
function setupNumberActivity(number) {
currentGameState = 'numberActivity';
// Clear existing elements
game.removeChildren();
// Add background
var background = game.attachAsset('traceBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
// Add back button
var backToNumbersButton = new Text2('← Back', {
size: 80,
fill: 0x1976D2
});
backToNumbersButton.anchor.set(0, 0);
backToNumbersButton.x = 150;
backToNumbersButton.y = 100;
game.addChild(backToNumbersButton);
// Make back button interactive
backToNumbersButton.down = function (x, y, obj) {
setupNumberSelection();
};
// Add instruction text
var instructionText = new Text2('Trace the number ' + number + ' by touching the dots in order', {
size: 80,
fill: 0x2E7D32
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 300;
game.addChild(instructionText);
// Add starting point instruction
var startText = new Text2('Look for "START" to see where to begin!', {
size: 60,
fill: 0xFF5722
});
startText.anchor.set(0.5, 0.5);
startText.x = 1024;
startText.y = 380;
game.addChild(startText);
// Create trace dots with fixed positions from pattern
traceDots = [];
currentTraceIndex = 0;
var pattern = numberPatterns[number];
dotNumbers = []; // Reset number indicators array
for (var i = 0; i < pattern.length; i++) {
var dot = new TraceDot(pattern[i].x, pattern[i].y, i);
traceDots.push(dot);
game.addChild(dot);
// Add number indicator for each dot
var numberText = (i + 1).toString();
var numberIndicator = new Text2(numberText, {
size: 50,
fill: 0x000000
});
numberIndicator.anchor.set(0.5, 0.5);
numberIndicator.x = pattern[i].x;
numberIndicator.y = pattern[i].y;
// Add white circle background for better visibility
var numberBackground = LK.getAsset('traceDot', {
anchorX: 0.5,
anchorY: 0.5,
x: pattern[i].x,
y: pattern[i].y,
scaleX: 1.2,
scaleY: 1.2
});
numberBackground.tint = 0xFFFFFF;
game.addChild(numberBackground);
// Add number to front
game.addChild(numberIndicator);
dotNumbers.push({
number: numberIndicator,
background: numberBackground
});
}
// Add starting point indicator for the first dot
if (traceDots.length > 0) {
var startIndicator = new Text2('START', {
size: 40,
fill: 0xFF5722
});
startIndicator.anchor.set(0.5, 0.5);
startIndicator.x = traceDots[0].x;
startIndicator.y = traceDots[0].y - 60;
game.addChild(startIndicator);
// Add arrow pointing to start
var arrowText = new Text2('↓', {
size: 60,
fill: 0xFF5722
});
arrowText.anchor.set(0.5, 0.5);
arrowText.x = traceDots[0].x;
arrowText.y = traceDots[0].y - 30;
game.addChild(arrowText);
// Animate the starting indicators
tween(startIndicator, {
alpha: 0.3
}, {
duration: 800
});
tween(startIndicator, {
alpha: 1.0
}, {
duration: 800
});
tween(arrowText, {
alpha: 0.3
}, {
duration: 800
});
tween(arrowText, {
alpha: 1.0
}, {
duration: 800
});
// Animate the first number
if (dotNumbers.length > 0) {
tween(dotNumbers[0].number, {
alpha: 0.3
}, {
duration: 800
});
tween(dotNumbers[0].number, {
alpha: 1.0
}, {
duration: 800
});
}
}
// Highlight first dot
if (traceDots.length > 0) {
tween(traceDots[0], {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 500
});
tween(traceDots[0], {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 500
});
}
}
function completeLetterActivity() {
// Mark letter as completed
if (completedLetters.indexOf(currentLetter) === -1) {
completedLetters.push(currentLetter);
storage.completedLetters = completedLetters;
// Unlock next letter
var letterIndex = currentLetter.charCodeAt(0) - 65;
if (letterIndex + 2 > unlockedLetters) {
unlockedLetters = letterIndex + 2;
storage.unlockedLetters = unlockedLetters;
}
// Add the completed letter on the paper
var letterOnPaper = new Text2(currentLetter, {
size: 400,
fill: 0x1B5E20
});
letterOnPaper.anchor.set(0.5, 0.5);
letterOnPaper.x = 1024;
letterOnPaper.y = 1600;
letterOnPaper.alpha = 1;
letterOnPaper.scaleX = 1.0;
letterOnPaper.scaleY = 1.0;
game.addChild(letterOnPaper);
// Animate letter appearing on paper with dramatic effect
tween(letterOnPaper, {
alpha: 1,
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 1000
});
tween(letterOnPaper, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 600
});
// Play celebration sound
LK.getSound('celebration').play();
// Flash screen green
LK.effects.flashScreen(0x4CAF50, 1000);
// Show completion message
var completionText = new Text2('Great job! Letter ' + currentLetter + ' completed!', {
size: 80,
fill: 0x2E7D32
});
completionText.anchor.set(0.5, 0.5);
completionText.x = 1024;
completionText.y = 2000;
game.addChild(completionText);
// Animate completion text
tween(completionText, {
y: 1200
}, {
duration: 1000
});
// Return to letter selection after delay
LK.setTimeout(function () {
setupLetterSelection();
}, 3000);
}
}
function setupSumsActivity() {
currentGameState = 'sumsActivity';
// Clear existing elements
game.removeChildren();
// Add back button
var backToMainFromSums = new Text2('← Back', {
size: 80,
fill: 0x1976D2
});
backToMainFromSums.anchor.set(0, 0);
backToMainFromSums.x = 150;
backToMainFromSums.y = 100;
game.addChild(backToMainFromSums);
// Make back button interactive
backToMainFromSums.down = function (x, y, obj) {
setupMainSelection();
};
// Generate random addition problem based on difficulty
var maxNumber = Math.min(10 + (currentDifficulty - 1) * 5, 50); // Start with 1-10, increase by 5 each level, max 50
currentSum1 = Math.floor(Math.random() * maxNumber) + 1;
currentSum2 = Math.floor(Math.random() * maxNumber) + 1;
currentAnswer = currentSum1 + currentSum2;
// Add problem text
sumsProblemText = new Text2(currentSum1 + ' + ' + currentSum2 + ' = ?', {
size: 200,
fill: 0x2E7D32
});
sumsProblemText.anchor.set(0.5, 0.5);
sumsProblemText.x = 1024;
sumsProblemText.y = 800;
game.addChild(sumsProblemText);
// Add instruction text
var instructionText = new Text2('Solve the addition problem!', {
size: 100,
fill: 0xFF5722
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 600;
game.addChild(instructionText);
// Add difficulty and progress display
var difficultyText = new Text2('Level ' + currentDifficulty + ' - Problems completed: ' + sumsCompleted, {
size: 60,
fill: 0x666666
});
difficultyText.anchor.set(0.5, 0.5);
difficultyText.x = 1024;
difficultyText.y = 500;
game.addChild(difficultyText);
// Add input field for user answer
userInputText = new Text2('?', {
size: 180,
fill: 0x000000
});
userInputText.anchor.set(0.5, 0.5);
userInputText.x = 1024;
userInputText.y = 1000;
game.addChild(userInputText);
// Add input box background
var inputBox = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1000,
scaleX: 0.8,
scaleY: 0.8
});
game.addChild(inputBox);
// Re-add text on top of box
game.addChild(userInputText);
// Store current user input
currentUserInput = '';
// Add feedback text (initially hidden)
feedbackText = new Text2('', {
size: 100,
fill: 0x4CAF50
});
feedbackText.anchor.set(0.5, 0.5);
feedbackText.x = 1024;
feedbackText.y = 1200;
feedbackText.alpha = 0;
game.addChild(feedbackText);
// Add answer text (initially hidden)
sumsAnswerText = new Text2('Answer: ' + currentAnswer, {
size: 120,
fill: 0x4CAF50
});
sumsAnswerText.anchor.set(0.5, 0.5);
sumsAnswerText.x = 1024;
sumsAnswerText.y = 1300;
sumsAnswerText.alpha = 0;
game.addChild(sumsAnswerText);
// Add "Show Answer" button
var showAnswerButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1400
});
game.addChild(showAnswerButton);
var showAnswerText = new Text2('SHOW ANSWER', {
size: 60,
fill: 0xFFFFFF
});
showAnswerText.anchor.set(0.5, 0.5);
showAnswerText.x = 1024;
showAnswerText.y = 1400;
game.addChild(showAnswerText);
// Add number buttons for input (0-9)
numberButtons = []; // Reset the global array
var buttonStartX = 200;
var buttonStartY = 1450;
var buttonSpacing = 160;
for (var i = 0; i <= 9; i++) {
var buttonX = buttonStartX + i % 5 * buttonSpacing;
var buttonY = buttonStartY + Math.floor(i / 5) * 120;
var numButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: buttonX,
y: buttonY,
scaleX: 0.7,
scaleY: 0.7
});
game.addChild(numButton);
var numButtonText = new Text2(i.toString(), {
size: 100,
fill: 0xFFFFFF
});
numButtonText.anchor.set(0.5, 0.5);
numButtonText.x = buttonX;
numButtonText.y = buttonY;
game.addChild(numButtonText);
numberButtons.push({
button: numButton,
text: numButtonText,
number: i
});
}
// Add clear button
var clearButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1550,
scaleX: 0.6,
scaleY: 0.4
});
game.addChild(clearButton);
var clearButtonText = new Text2('CLEAR', {
size: 50,
fill: 0xFFFFFF
});
clearButtonText.anchor.set(0.5, 0.5);
clearButtonText.x = 1024;
clearButtonText.y = 1550;
game.addChild(clearButtonText);
// Add check answer button
var checkButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1400,
y: 1550,
scaleX: 0.8,
scaleY: 0.4
});
game.addChild(checkButton);
var checkButtonText = new Text2('CHECK', {
size: 50,
fill: 0xFFFFFF
});
checkButtonText.anchor.set(0.5, 0.5);
checkButtonText.x = 1400;
checkButtonText.y = 1550;
game.addChild(checkButtonText);
// Next problem button removed - auto-advance when correct
}
function completeNumberActivity() {
// Mark number as completed
if (completedNumbers.indexOf(currentNumber) === -1) {
completedNumbers.push(currentNumber);
storage.completedNumbers = completedNumbers;
// Unlock next number
var numberIndex = parseInt(currentNumber) - 1;
if (numberIndex + 2 > unlockedNumbers) {
unlockedNumbers = numberIndex + 2;
storage.unlockedNumbers = unlockedNumbers;
}
// Add the completed number on the paper
var numberOnPaper = new Text2(currentNumber, {
size: 400,
fill: 0x1B5E20
});
numberOnPaper.anchor.set(0.5, 0.5);
numberOnPaper.x = 1024;
numberOnPaper.y = 1600;
numberOnPaper.alpha = 1;
numberOnPaper.scaleX = 1.0;
numberOnPaper.scaleY = 1.0;
game.addChild(numberOnPaper);
// Animate number appearing on paper with dramatic effect
tween(numberOnPaper, {
alpha: 1,
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 1000
});
tween(numberOnPaper, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 600
});
// Play celebration sound
LK.getSound('celebration').play();
// Flash screen green
LK.effects.flashScreen(0x4CAF50, 1000);
// Show completion message
var completionText = new Text2('Great job! Number ' + currentNumber + ' completed!', {
size: 80,
fill: 0x2E7D32
});
completionText.anchor.set(0.5, 0.5);
completionText.x = 1024;
completionText.y = 2000;
game.addChild(completionText);
// Animate completion text
tween(completionText, {
y: 1200
}, {
duration: 1000
});
// Return to number selection after delay
LK.setTimeout(function () {
setupNumberSelection();
}, 3000);
}
}
// Restart function to reset game state
function restartGame() {
// Reset game state variables
currentGameState = 'mainSelection';
currentLetter = '';
currentNumber = '';
currentTraceIndex = 0;
sumsCompleted = 0;
currentDifficulty = 1;
// Clear arrays
letterBoxes = [];
numberBoxes = [];
traceDots = [];
// Reset progress - uncommented to fully restart the game
unlockedLetters = 1;
completedLetters = [];
unlockedNumbers = 1;
completedNumbers = [];
storage.unlockedLetters = unlockedLetters;
storage.completedLetters = completedLetters;
storage.unlockedNumbers = unlockedNumbers;
storage.completedNumbers = completedNumbers;
// Return to main selection
setupMainSelection();
}
// Event handlers
game.down = function (x, y, obj) {
if (currentGameState === 'mainSelection') {
// Check if Letters button was clicked
if (x >= 600 && x <= 800 && y >= 1100 && y <= 1300) {
setupLetterSelection();
return;
}
// Check if Numbers button was clicked
if (x >= 1248 && x <= 1448 && y >= 1100 && y <= 1300) {
setupNumberSelection();
return;
}
// Check if Sums button was clicked
if (x >= 924 && x <= 1124 && y >= 1500 && y <= 1700) {
setupSumsActivity();
return;
}
}
if (currentGameState === 'letterSelection') {
// Check if back button was clicked
if (x >= 100 && x <= 300 && y >= 50 && y <= 150) {
setupMainSelection();
return;
}
}
if (currentGameState === 'numberSelection') {
// Check if back button was clicked
if (x >= 100 && x <= 300 && y >= 50 && y <= 150) {
setupMainSelection();
return;
}
}
if (currentGameState === 'letterActivity') {
// Check if back button was clicked
if (x >= 100 && x <= 300 && y >= 50 && y <= 150) {
setupLetterSelection();
return;
}
// Check if current trace dot was touched
if (currentTraceIndex < traceDots.length) {
var currentDot = traceDots[currentTraceIndex];
var distance = Math.sqrt(Math.pow(x - currentDot.x, 2) + Math.pow(y - currentDot.y, 2));
if (distance < 80) {
currentDot.complete();
// Hide the number indicator for the completed dot
if (dotNumbers && dotNumbers[currentTraceIndex]) {
dotNumbers[currentTraceIndex].number.alpha = 0;
dotNumbers[currentTraceIndex].background.alpha = 0;
}
currentTraceIndex++;
// Highlight next dot
if (currentTraceIndex < traceDots.length) {
var nextDot = traceDots[currentTraceIndex];
tween(nextDot, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 300
});
tween(nextDot, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300
});
} else {
// All dots completed
LK.getSound('letterComplete').play();
LK.setTimeout(function () {
completeLetterActivity();
}, 1000);
}
}
}
}
if (currentGameState === 'numberActivity') {
// Check if back button was clicked
if (x >= 100 && x <= 300 && y >= 50 && y <= 150) {
setupNumberSelection();
return;
}
// Check if current trace dot was touched
if (currentTraceIndex < traceDots.length) {
var currentDot = traceDots[currentTraceIndex];
var distance = Math.sqrt(Math.pow(x - currentDot.x, 2) + Math.pow(y - currentDot.y, 2));
if (distance < 80) {
currentDot.complete();
// Hide the number indicator for the completed dot
if (dotNumbers && dotNumbers[currentTraceIndex]) {
dotNumbers[currentTraceIndex].number.alpha = 0;
dotNumbers[currentTraceIndex].background.alpha = 0;
}
currentTraceIndex++;
// Highlight next dot
if (currentTraceIndex < traceDots.length) {
var nextDot = traceDots[currentTraceIndex];
tween(nextDot, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 300
});
tween(nextDot, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300
});
} else {
// All dots completed
LK.getSound('letterComplete').play();
LK.setTimeout(function () {
completeNumberActivity();
}, 1000);
}
}
}
}
if (currentGameState === 'sumsActivity') {
// Check if back button was clicked
if (x >= 100 && x <= 300 && y >= 50 && y <= 150) {
setupMainSelection();
return;
}
// Check number button clicks
for (var i = 0; i < numberButtons.length; i++) {
var btn = numberButtons[i];
var btnX = btn.button.x;
var btnY = btn.button.y;
if (x >= btnX - 56 && x <= btnX + 56 && y >= btnY - 42 && y <= btnY + 42) {
if (currentUserInput.length < 2) {
// Limit to 2 digits
currentUserInput += btn.number.toString();
userInputText.setText(currentUserInput);
}
return;
}
}
// Check clear button
if (x >= 924 && x <= 1124 && y >= 1500 && y <= 1600) {
currentUserInput = '';
userInputText.setText('?');
feedbackText.alpha = 0;
return;
}
// Check answer button
if (x >= 1300 && x <= 1500 && y >= 1500 && y <= 1600) {
if (currentUserInput !== '') {
var userAnswer = parseInt(currentUserInput);
if (userAnswer === currentAnswer) {
sumsCompleted++; // Increment completed problems counter
// Check if difficulty should increase (every 5 problems)
if (sumsCompleted % 5 === 0 && currentDifficulty < 10) {
currentDifficulty++;
feedbackText.setText('¡Correcto! Level up! Now Level ' + currentDifficulty);
LK.effects.flashScreen(0xFFD700, 1000); // Gold flash for level up
} else {
feedbackText.setText('¡Correcto! Well done!');
LK.effects.flashScreen(0x4CAF50, 500);
}
feedbackText.fill = 0x4CAF50; // Green
LK.getSound('correctAction').play();
// Auto-advance to next problem immediately when correct
LK.setTimeout(function () {
setupSumsActivity();
}, 1500);
} else {
feedbackText.setText('Incorrecto. Try again!');
feedbackText.fill = 0xF44336; // Red
LK.effects.flashScreen(0xF44336, 500);
}
tween(feedbackText, {
alpha: 1
}, {
duration: 500
});
}
return;
}
// Check if Show Answer button was clicked
if (x >= 924 && x <= 1124 && y >= 1300 && y <= 1500) {
// Show the answer with animation
tween(sumsAnswerText, {
alpha: 1
}, {
duration: 500
});
// Play correct action sound
LK.getSound('correctAction').play();
return;
}
// Next problem button click handler removed - auto-advance when correct
}
};
game.update = function () {
// Update any ongoing animations or game logic
if (currentGameState === 'letterActivity') {
// Removed floating animation to prevent letters from moving
}
};
// Create monkey sprite and make it visible
var monkey = LK.getAsset('Monkey', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
game.addChild(monkey);
// Initialize the game
setupMainSelection(); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var LetterBox = Container.expand(function (letter, isCompleted, isLocked) {
var self = Container.call(this);
self.letter = letter;
self.isCompleted = isCompleted || false;
self.isLocked = isLocked || false;
// Choose appropriate background based on state
var boxType = 'letterBox';
if (self.isCompleted) {
boxType = 'completedLetterBox';
} else if (self.isLocked) {
boxType = 'lockedLetterBox';
}
var box = self.attachAsset(boxType, {
anchorX: 0.5,
anchorY: 0.5
});
// Add letter text
var letterText = new Text2(letter, {
size: 120,
fill: self.isLocked ? "#666666" : "#FFFFFF"
});
letterText.anchor.set(0.5, 0.5);
letterText.x = 0;
letterText.y = 0;
self.addChild(letterText);
// Add star if completed
if (self.isCompleted) {
var star = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5,
x: 70,
y: -70
});
}
self.down = function (x, y, obj) {
if (!self.isLocked) {
// Scale animation on touch
tween(self, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
// Switch to letter activity
currentGameState = 'letterActivity';
currentLetter = self.letter;
setupLetterActivity(self.letter);
}
};
return self;
});
var NumberBox = Container.expand(function (number, isCompleted, isLocked) {
var self = Container.call(this);
self.number = number;
self.isCompleted = isCompleted || false;
self.isLocked = isLocked || false;
// Choose appropriate background based on state
var boxType = 'letterBox';
if (self.isCompleted) {
boxType = 'completedLetterBox';
} else if (self.isLocked) {
boxType = 'lockedLetterBox';
}
var box = self.attachAsset(boxType, {
anchorX: 0.5,
anchorY: 0.5
});
// Add number text
var numberText = new Text2(number, {
size: 120,
fill: self.isLocked ? "#666666" : "#FFFFFF"
});
numberText.anchor.set(0.5, 0.5);
numberText.x = 0;
numberText.y = 0;
self.addChild(numberText);
// Add star if completed
if (self.isCompleted) {
var star = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5,
x: 70,
y: -70
});
}
self.down = function (x, y, obj) {
if (!self.isLocked) {
// Scale animation on touch
tween(self, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
// Switch to number activity
currentGameState = 'numberActivity';
currentNumber = self.number;
setupNumberActivity(self.number);
}
};
return self;
});
var TraceDot = Container.expand(function (x, y, index) {
var self = Container.call(this);
self.x = x;
self.y = y;
self.index = index;
self.isCompleted = false;
var dot = self.attachAsset('traceDot', {
anchorX: 0.5,
anchorY: 0.5
});
self.complete = function () {
if (!self.isCompleted) {
self.isCompleted = true;
self.removeChild(dot);
var completedDot = self.attachAsset('completedDot', {
anchorX: 0.5,
anchorY: 0.5
});
// Celebration animation
tween(self, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
LK.getSound('correctAction').play();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// X pattern is already implemented in the letterPatterns object
var currentGameState = 'mainSelection'; // 'mainSelection', 'letterSelection', 'letterActivity', 'numberSelection', 'numberActivity', 'sumsActivity'
var currentSum1 = 0;
var currentSum2 = 0;
var currentAnswer = 0;
var sumsCompleted = 0; // Track number of problems completed
var currentDifficulty = 1; // Current difficulty level (1-5)
var sumsProblemText;
var sumsAnswerText;
var currentLetter = '';
var currentNumber = '';
var unlockedLetters = storage.unlockedLetters || 1; // Number of unlocked letters (A=1, B=2, etc.)
var completedLetters = storage.completedLetters || [];
var unlockedNumbers = storage.unlockedNumbers || 1; // Number of unlocked numbers (1=1, 2=2, etc.)
var completedNumbers = storage.completedNumbers || [];
var letterBoxes = [];
var numberBoxes = [];
var traceDots = [];
var currentTraceIndex = 0;
var dotNumbers = []; // Array to store number indicators
var numberButtons = []; // Array to store number input buttons
var currentUserInput = ''; // Store current user input for sums
var userInputText; // Reference to user input text display
var feedbackText; // Reference to feedback text display
// Letter patterns for tracing (properly positioned and shaped)
var letterPatterns = {
'A': [{
x: 1024,
y: 1400
}, {
x: 974,
y: 1500
}, {
x: 924,
y: 1600
}, {
x: 874,
y: 1700
}, {
x: 824,
y: 1800
}, {
x: 1024,
y: 1400
}, {
x: 1074,
y: 1500
}, {
x: 1124,
y: 1600
}, {
x: 1174,
y: 1700
}, {
x: 1224,
y: 1800
}, {
x: 874,
y: 1650
}, {
x: 924,
y: 1650
}, {
x: 974,
y: 1650
}, {
x: 1024,
y: 1650
}, {
x: 1074,
y: 1650
}, {
x: 1124,
y: 1650
}, {
x: 1174,
y: 1650
}],
'B': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1450
}, {
x: 1000,
y: 1600
}, {
x: 1100,
y: 1600
}, {
x: 1150,
y: 1750
}, {
x: 1000,
y: 1800
}],
'C': [{
x: 1150,
y: 1450
}, {
x: 1000,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 1000,
y: 1800
}, {
x: 1150,
y: 1750
}],
'D': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1450
}, {
x: 1150,
y: 1600
}, {
x: 1100,
y: 1750
}, {
x: 1000,
y: 1800
}],
'E': [{
x: 900,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1100,
y: 1800
}, {
x: 1150,
y: 1800
}],
'F': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}],
'G': [{
x: 1150,
y: 1450
}, {
x: 1000,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 1000,
y: 1800
}, {
x: 1150,
y: 1750
}, {
x: 1150,
y: 1650
}, {
x: 1100,
y: 1650
}],
'H': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1100,
y: 1600
}, {
x: 1100,
y: 1500
}, {
x: 1100,
y: 1400
}, {
x: 1100,
y: 1700
}, {
x: 1100,
y: 1800
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}],
'I': [{
x: 900,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1000,
y: 1500
}, {
x: 1000,
y: 1600
}, {
x: 1000,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1100,
y: 1800
}],
'J': [{
x: 850,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 1050,
y: 1500
}, {
x: 1050,
y: 1600
}, {
x: 1050,
y: 1700
}, {
x: 1000,
y: 1800
}, {
x: 900,
y: 1750
}],
'K': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1100,
y: 1400
}, {
x: 1050,
y: 1450
}, {
x: 1000,
y: 1500
}, {
x: 950,
y: 1550
}, {
x: 900,
y: 1600
}, {
x: 950,
y: 1650
}, {
x: 1000,
y: 1700
}, {
x: 1050,
y: 1750
}, {
x: 1100,
y: 1800
}],
'L': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1100,
y: 1800
}, {
x: 1150,
y: 1800
}],
'M': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 950,
y: 1450
}, {
x: 1000,
y: 1500
}, {
x: 1024,
y: 1550
}, {
x: 1050,
y: 1500
}, {
x: 1100,
y: 1450
}, {
x: 1150,
y: 1400
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1800
}],
'N': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 950,
y: 1450
}, {
x: 1000,
y: 1500
}, {
x: 1050,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1150,
y: 1650
}, {
x: 1150,
y: 1400
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1800
}],
'O': [{
x: 1024,
y: 1400
}, {
x: 1100,
y: 1430
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1700
}, {
x: 1100,
y: 1770
}, {
x: 1024,
y: 1800
}, {
x: 948,
y: 1770
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1500
}, {
x: 948,
y: 1430
}, {
x: 1024,
y: 1400
}],
'P': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1450
}, {
x: 1150,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1000,
y: 1600
}],
'Q': [{
x: 1024,
y: 1400
}, {
x: 1100,
y: 1430
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1700
}, {
x: 1100,
y: 1770
}, {
x: 1024,
y: 1800
}, {
x: 948,
y: 1770
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1500
}, {
x: 948,
y: 1430
}, {
x: 1024,
y: 1400
}, {
x: 1050,
y: 1650
}, {
x: 1100,
y: 1700
}, {
x: 1150,
y: 1750
}, {
x: 1200,
y: 1800
}],
'R': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1800
}, {
x: 1000,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1450
}, {
x: 1150,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1000,
y: 1650
}, {
x: 1050,
y: 1700
}, {
x: 1100,
y: 1750
}, {
x: 1150,
y: 1800
}],
'S': [{
x: 1150,
y: 1450
}, {
x: 1100,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 950,
y: 1430
}, {
x: 900,
y: 1480
}, {
x: 900,
y: 1530
}, {
x: 950,
y: 1580
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1100,
y: 1620
}, {
x: 1150,
y: 1670
}, {
x: 1150,
y: 1720
}, {
x: 1100,
y: 1770
}, {
x: 1000,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 900,
y: 1750
}],
'T': [{
x: 850,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 1200,
y: 1400
}, {
x: 1024,
y: 1400
}, {
x: 1024,
y: 1500
}, {
x: 1024,
y: 1600
}, {
x: 1024,
y: 1700
}, {
x: 1024,
y: 1800
}],
'U': [{
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1700
}, {
x: 950,
y: 1770
}, {
x: 1000,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1100,
y: 1770
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1400
}],
'V': [{
x: 900,
y: 1400
}, {
x: 920,
y: 1500
}, {
x: 940,
y: 1600
}, {
x: 960,
y: 1700
}, {
x: 980,
y: 1750
}, {
x: 1000,
y: 1780
}, {
x: 1024,
y: 1800
}, {
x: 1048,
y: 1780
}, {
x: 1068,
y: 1750
}, {
x: 1088,
y: 1700
}, {
x: 1108,
y: 1600
}, {
x: 1128,
y: 1500
}, {
x: 1150,
y: 1400
}],
'W': [{
x: 850,
y: 1400
}, {
x: 870,
y: 1500
}, {
x: 890,
y: 1600
}, {
x: 910,
y: 1700
}, {
x: 930,
y: 1750
}, {
x: 950,
y: 1800
}, {
x: 970,
y: 1750
}, {
x: 990,
y: 1700
}, {
x: 1010,
y: 1650
}, {
x: 1024,
y: 1600
}, {
x: 1038,
y: 1650
}, {
x: 1058,
y: 1700
}, {
x: 1078,
y: 1750
}, {
x: 1098,
y: 1800
}, {
x: 1118,
y: 1750
}, {
x: 1138,
y: 1700
}, {
x: 1158,
y: 1600
}, {
x: 1178,
y: 1500
}, {
x: 1200,
y: 1400
}],
'X': [{
x: 900,
y: 1400
}, {
x: 950,
y: 1450
}, {
x: 1000,
y: 1500
}, {
x: 1050,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1150,
y: 1650
}, {
x: 1200,
y: 1700
}, {
x: 1250,
y: 1750
}, {
x: 1300,
y: 1800
}, {
x: 1300,
y: 1400
}, {
x: 1250,
y: 1450
}, {
x: 1200,
y: 1500
}, {
x: 1150,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1050,
y: 1650
}, {
x: 1000,
y: 1700
}, {
x: 950,
y: 1750
}, {
x: 900,
y: 1800
}],
'Y': [{
x: 900,
y: 1400
}, {
x: 950,
y: 1450
}, {
x: 1000,
y: 1500
}, {
x: 1024,
y: 1550
}, {
x: 1024,
y: 1600
}, {
x: 1024,
y: 1650
}, {
x: 1024,
y: 1700
}, {
x: 1024,
y: 1750
}, {
x: 1024,
y: 1800
}, {
x: 1048,
y: 1500
}, {
x: 1098,
y: 1450
}, {
x: 1150,
y: 1400
}],
'Z': [{
x: 900,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 1100,
y: 1500
}, {
x: 1050,
y: 1550
}, {
x: 1000,
y: 1600
}, {
x: 950,
y: 1650
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1750
}, {
x: 900,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1100,
y: 1800
}, {
x: 1150,
y: 1800
}]
};
// Number patterns for tracing (digits 1-10)
var numberPatterns = {
'1': [{
x: 1024,
y: 1400
}, {
x: 1024,
y: 1500
}, {
x: 1024,
y: 1600
}, {
x: 1024,
y: 1700
}, {
x: 1024,
y: 1800
}, {
x: 974,
y: 1450
}, {
x: 924,
y: 1500
}],
'2': [{
x: 900,
y: 1450
}, {
x: 950,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1450
}, {
x: 1150,
y: 1500
}, {
x: 1100,
y: 1550
}, {
x: 1050,
y: 1600
}, {
x: 1000,
y: 1650
}, {
x: 950,
y: 1700
}, {
x: 900,
y: 1750
}, {
x: 900,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1100,
y: 1800
}, {
x: 1150,
y: 1800
}],
'3': [{
x: 900,
y: 1450
}, {
x: 950,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1450
}, {
x: 1150,
y: 1500
}, {
x: 1100,
y: 1550
}, {
x: 1050,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1100,
y: 1650
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1750
}, {
x: 1100,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 900,
y: 1750
}],
'4': [{
x: 1100,
y: 1400
}, {
x: 1100,
y: 1500
}, {
x: 1100,
y: 1600
}, {
x: 1100,
y: 1700
}, {
x: 1100,
y: 1800
}, {
x: 1050,
y: 1400
}, {
x: 1000,
y: 1450
}, {
x: 950,
y: 1500
}, {
x: 900,
y: 1550
}, {
x: 900,
y: 1600
}, {
x: 950,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1100,
y: 1600
}, {
x: 1150,
y: 1600
}],
'5': [{
x: 1150,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 900,
y: 1400
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1550
}, {
x: 950,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1100,
y: 1600
}, {
x: 1150,
y: 1650
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1750
}, {
x: 1100,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 900,
y: 1750
}],
'6': [{
x: 1100,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 900,
y: 1450
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1550
}, {
x: 900,
y: 1600
}, {
x: 900,
y: 1650
}, {
x: 900,
y: 1700
}, {
x: 900,
y: 1750
}, {
x: 950,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 1050,
y: 1800
}, {
x: 1100,
y: 1800
}, {
x: 1150,
y: 1750
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1650
}, {
x: 1100,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 950,
y: 1600
}],
'7': [{
x: 900,
y: 1400
}, {
x: 950,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1400
}, {
x: 1100,
y: 1500
}, {
x: 1050,
y: 1550
}, {
x: 1000,
y: 1600
}, {
x: 950,
y: 1650
}, {
x: 950,
y: 1700
}, {
x: 950,
y: 1750
}, {
x: 950,
y: 1800
}],
'8': [{
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1100,
y: 1430
}, {
x: 1150,
y: 1480
}, {
x: 1150,
y: 1530
}, {
x: 1100,
y: 1580
}, {
x: 1050,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 950,
y: 1600
}, {
x: 900,
y: 1580
}, {
x: 900,
y: 1530
}, {
x: 900,
y: 1480
}, {
x: 950,
y: 1430
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1600
}, {
x: 1100,
y: 1630
}, {
x: 1150,
y: 1680
}, {
x: 1150,
y: 1730
}, {
x: 1100,
y: 1780
}, {
x: 1050,
y: 1800
}, {
x: 1000,
y: 1800
}, {
x: 950,
y: 1800
}, {
x: 900,
y: 1780
}, {
x: 900,
y: 1730
}, {
x: 900,
y: 1680
}, {
x: 950,
y: 1630
}],
'9': [{
x: 1050,
y: 1400
}, {
x: 1100,
y: 1400
}, {
x: 1150,
y: 1450
}, {
x: 1150,
y: 1500
}, {
x: 1150,
y: 1550
}, {
x: 1100,
y: 1600
}, {
x: 1050,
y: 1600
}, {
x: 1000,
y: 1600
}, {
x: 950,
y: 1600
}, {
x: 900,
y: 1550
}, {
x: 900,
y: 1500
}, {
x: 900,
y: 1450
}, {
x: 950,
y: 1400
}, {
x: 1000,
y: 1400
}, {
x: 1050,
y: 1400
}, {
x: 1150,
y: 1600
}, {
x: 1150,
y: 1650
}, {
x: 1150,
y: 1700
}, {
x: 1150,
y: 1750
}, {
x: 1150,
y: 1800
}],
'10': [{
x: 850,
y: 1400
}, {
x: 850,
y: 1500
}, {
x: 850,
y: 1600
}, {
x: 850,
y: 1700
}, {
x: 850,
y: 1800
}, {
x: 800,
y: 1450
}, {
x: 750,
y: 1500
}, {
x: 1150,
y: 1400
}, {
x: 1200,
y: 1430
}, {
x: 1250,
y: 1480
}, {
x: 1250,
y: 1530
}, {
x: 1250,
y: 1580
}, {
x: 1250,
y: 1630
}, {
x: 1250,
y: 1680
}, {
x: 1250,
y: 1730
}, {
x: 1200,
y: 1770
}, {
x: 1150,
y: 1800
}, {
x: 1100,
y: 1770
}, {
x: 1050,
y: 1730
}, {
x: 1050,
y: 1680
}, {
x: 1050,
y: 1630
}, {
x: 1050,
y: 1580
}, {
x: 1050,
y: 1530
}, {
x: 1050,
y: 1480
}, {
x: 1100,
y: 1430
}, {
x: 1150,
y: 1400
}]
};
// Add more basic patterns for other letters
for (var i = 0; i < 26; i++) {
var letter = String.fromCharCode(65 + i);
if (!letterPatterns[letter]) {
// Simple default pattern for letters not defined - centered and properly sized
letterPatterns[letter] = [{
x: 924,
y: 1400
}, {
x: 974,
y: 1500
}, {
x: 1024,
y: 1600
}, {
x: 1074,
y: 1700
}, {
x: 1124,
y: 1800
}];
}
}
// UI Elements
var titleText = new Text2('ABC Learning Adventure', {
size: 100,
fill: 0x2E7D32
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
function setupMainSelection() {
currentGameState = 'mainSelection';
// Clear existing elements
game.removeChildren();
// Add title
var mainTitle = new Text2('Learning Adventure', {
size: 120,
fill: 0x2E7D32
});
mainTitle.anchor.set(0.5, 0.5);
mainTitle.x = 1024;
mainTitle.y = 600;
game.addChild(mainTitle);
// Add Letters button
var lettersButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 700,
y: 1200
});
game.addChild(lettersButton);
var lettersText = new Text2('LETTERS\nA-Z', {
size: 80,
fill: 0xFFFFFF
});
lettersText.anchor.set(0.5, 0.5);
lettersText.x = 700;
lettersText.y = 1200;
game.addChild(lettersText);
// Add Numbers button
var numbersButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1348,
y: 1200
});
game.addChild(numbersButton);
var numbersText = new Text2('NUMBERS\n1-10', {
size: 80,
fill: 0xFFFFFF
});
numbersText.anchor.set(0.5, 0.5);
numbersText.x = 1348;
numbersText.y = 1200;
game.addChild(numbersText);
// Add Sums button
var sumsButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1600
});
game.addChild(sumsButton);
var sumsText = new Text2('SUMAS\n1+1=2', {
size: 80,
fill: 0xFFFFFF
});
sumsText.anchor.set(0.5, 0.5);
sumsText.x = 1024;
sumsText.y = 1600;
game.addChild(sumsText);
// Add progress indicators
var letterProgress = new Text2('Letters: ' + completedLetters.length + '/26', {
size: 50,
fill: 0x424242
});
letterProgress.anchor.set(0.5, 0.5);
letterProgress.x = 700;
letterProgress.y = 1400;
game.addChild(letterProgress);
var numberProgress = new Text2('Numbers: ' + completedNumbers.length + '/10', {
size: 50,
fill: 0x424242
});
numberProgress.anchor.set(0.5, 0.5);
numberProgress.x = 1348;
numberProgress.y = 1400;
game.addChild(numberProgress);
var sumsProgress = new Text2('Sums: Level ' + currentDifficulty + ' (' + sumsCompleted + ' completed)', {
size: 50,
fill: 0x424242
});
sumsProgress.anchor.set(0.5, 0.5);
sumsProgress.x = 1024;
sumsProgress.y = 1800;
game.addChild(sumsProgress);
// Add palm trees on the sides as Sprites
var leftPalmTree = LK.getAsset('palmTree', {
anchorX: 0.5,
anchorY: 1.0,
x: 150,
y: 2700
});
game.addChild(leftPalmTree);
var rightPalmTree = LK.getAsset('palmTree', {
anchorX: 0.5,
anchorY: 1.0,
x: 1900,
y: 2700
});
game.addChild(rightPalmTree);
// Add grass under palm trees
var leftGrass = LK.getAsset('grass', {
anchorX: 0.5,
anchorY: 1.0,
x: 150,
y: 2700
});
game.addChild(leftGrass);
var rightGrass = LK.getAsset('grass', {
anchorX: 0.5,
anchorY: 1.0,
x: 1900,
y: 2700
});
game.addChild(rightGrass);
// Add grass in the center between palm trees as a Sprite
var centerGrass = LK.getAsset('grass', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: 2700
});
game.addChild(centerGrass);
}
var backButton = new Text2('← Back', {
size: 80,
fill: 0x1976D2
});
backButton.anchor.set(0, 0);
backButton.x = 150;
backButton.y = 100;
var progressText = new Text2('Progress: 0/26', {
size: 60,
fill: 0x424242
});
progressText.anchor.set(0.5, 0);
progressText.x = 1024;
progressText.y = 200;
function setupLetterSelection() {
currentGameState = 'letterSelection';
// Clear existing elements
game.removeChildren();
// Add progress text
game.addChild(progressText);
progressText.setText('Progress: ' + completedLetters.length + '/26');
// Add restart button
var restartButton = new Text2('🔄 Restart', {
size: 60,
fill: 0xE53935
});
restartButton.anchor.set(1, 0);
restartButton.x = 1900;
restartButton.y = 200;
game.addChild(restartButton);
// Add back button for letter selection
var backToMainFromLetters = new Text2('← Back', {
size: 80,
fill: 0x1976D2
});
backToMainFromLetters.anchor.set(0, 0);
backToMainFromLetters.x = 150;
backToMainFromLetters.y = 100;
game.addChild(backToMainFromLetters);
// Make back button interactive
backToMainFromLetters.down = function (x, y, obj) {
setupMainSelection();
};
// Create letter grid (6x5 layout with last row having 2 letters)
letterBoxes = [];
var startX = 200;
var startY = 400;
var spacing = 300;
for (var i = 0; i < 26; i++) {
var letter = String.fromCharCode(65 + i);
var row = Math.floor(i / 6);
var col = i % 6;
// Center the last row (U, V, W, X, Y, Z)
var x = startX + col * spacing;
if (row === 4) {
x = startX + (col + 1) * spacing;
}
var y = startY + row * spacing;
var isCompleted = completedLetters.indexOf(letter) !== -1;
var isLocked = i + 1 > unlockedLetters;
var letterBox = new LetterBox(letter, isCompleted, isLocked);
letterBox.x = x;
letterBox.y = y;
letterBoxes.push(letterBox);
game.addChild(letterBox);
}
}
function setupNumberSelection() {
currentGameState = 'numberSelection';
// Clear existing elements
game.removeChildren();
// Add progress text
var numberProgressText = new Text2('Progress: ' + completedNumbers.length + '/10', {
size: 60,
fill: 0x424242
});
numberProgressText.anchor.set(0.5, 0);
numberProgressText.x = 1024;
numberProgressText.y = 200;
game.addChild(numberProgressText);
// Add back button
var backToMainButton = new Text2('← Back', {
size: 80,
fill: 0x1976D2
});
backToMainButton.anchor.set(0, 0);
backToMainButton.x = 150;
backToMainButton.y = 100;
game.addChild(backToMainButton);
// Make back button interactive
backToMainButton.down = function (x, y, obj) {
setupMainSelection();
};
// Create number grid (2 rows of 5)
numberBoxes = [];
var startX = 300;
var startY = 600;
var spacing = 300;
for (var i = 0; i < 10; i++) {
var number = (i + 1).toString();
var row = Math.floor(i / 5);
var col = i % 5;
var x = startX + col * spacing;
var y = startY + row * spacing;
var isCompleted = completedNumbers.indexOf(number) !== -1;
var isLocked = i + 1 > unlockedNumbers;
var numberBox = new NumberBox(number, isCompleted, isLocked);
numberBox.x = x;
numberBox.y = y;
numberBoxes.push(numberBox);
game.addChild(numberBox);
}
}
function setupLetterActivity(letter) {
currentGameState = 'letterActivity';
// Clear existing elements
game.removeChildren();
// Add background
var background = game.attachAsset('traceBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
// Add back button
game.addChild(backButton);
// Make back button interactive
backButton.down = function (x, y, obj) {
setupLetterSelection();
};
// Add instruction text
var instructionText = new Text2('Trace the letter ' + letter + ' by touching the dots in order', {
size: 80,
fill: 0x2E7D32
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 300;
game.addChild(instructionText);
// Add starting point instruction
var startText = new Text2('Look for "START" to see where to begin!', {
size: 60,
fill: 0xFF5722
});
startText.anchor.set(0.5, 0.5);
startText.x = 1024;
startText.y = 380;
game.addChild(startText);
// Note: Number indicators removed since dots are now randomly positioned
// Create trace dots with fixed positions from pattern
traceDots = [];
currentTraceIndex = 0;
var pattern = letterPatterns[letter];
dotNumbers = []; // Reset number indicators array
for (var i = 0; i < pattern.length; i++) {
var dot = new TraceDot(pattern[i].x, pattern[i].y, i);
traceDots.push(dot);
game.addChild(dot);
// Add number indicator for each dot (1-10, then continue with higher numbers)
var numberText = (i + 1).toString();
var numberIndicator = new Text2(numberText, {
size: 50,
fill: 0x000000
});
numberIndicator.anchor.set(0.5, 0.5);
numberIndicator.x = pattern[i].x;
numberIndicator.y = pattern[i].y;
// Add white circle background for better visibility
var numberBackground = LK.getAsset('traceDot', {
anchorX: 0.5,
anchorY: 0.5,
x: pattern[i].x,
y: pattern[i].y,
scaleX: 1.2,
scaleY: 1.2
});
numberBackground.tint = 0xFFFFFF;
game.addChild(numberBackground);
// Add number to front
game.addChild(numberIndicator);
dotNumbers.push({
number: numberIndicator,
background: numberBackground
});
}
// Add starting point indicator for the first dot
if (traceDots.length > 0) {
var startIndicator = new Text2('START', {
size: 40,
fill: 0xFF5722
});
startIndicator.anchor.set(0.5, 0.5);
startIndicator.x = traceDots[0].x;
startIndicator.y = traceDots[0].y - 60;
game.addChild(startIndicator);
// Add arrow pointing to start
var arrowText = new Text2('↓', {
size: 60,
fill: 0xFF5722
});
arrowText.anchor.set(0.5, 0.5);
arrowText.x = traceDots[0].x;
arrowText.y = traceDots[0].y - 30;
game.addChild(arrowText);
// Animate the starting indicators
tween(startIndicator, {
alpha: 0.3
}, {
duration: 800
});
tween(startIndicator, {
alpha: 1.0
}, {
duration: 800
});
tween(arrowText, {
alpha: 0.3
}, {
duration: 800
});
tween(arrowText, {
alpha: 1.0
}, {
duration: 800
});
// Animate the first number
if (dotNumbers.length > 0) {
tween(dotNumbers[0].number, {
alpha: 0.3
}, {
duration: 800
});
tween(dotNumbers[0].number, {
alpha: 1.0
}, {
duration: 800
});
}
}
// Highlight first dot
if (traceDots.length > 0) {
tween(traceDots[0], {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 500
});
tween(traceDots[0], {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 500
});
}
}
function setupNumberActivity(number) {
currentGameState = 'numberActivity';
// Clear existing elements
game.removeChildren();
// Add background
var background = game.attachAsset('traceBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
// Add back button
var backToNumbersButton = new Text2('← Back', {
size: 80,
fill: 0x1976D2
});
backToNumbersButton.anchor.set(0, 0);
backToNumbersButton.x = 150;
backToNumbersButton.y = 100;
game.addChild(backToNumbersButton);
// Make back button interactive
backToNumbersButton.down = function (x, y, obj) {
setupNumberSelection();
};
// Add instruction text
var instructionText = new Text2('Trace the number ' + number + ' by touching the dots in order', {
size: 80,
fill: 0x2E7D32
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 300;
game.addChild(instructionText);
// Add starting point instruction
var startText = new Text2('Look for "START" to see where to begin!', {
size: 60,
fill: 0xFF5722
});
startText.anchor.set(0.5, 0.5);
startText.x = 1024;
startText.y = 380;
game.addChild(startText);
// Create trace dots with fixed positions from pattern
traceDots = [];
currentTraceIndex = 0;
var pattern = numberPatterns[number];
dotNumbers = []; // Reset number indicators array
for (var i = 0; i < pattern.length; i++) {
var dot = new TraceDot(pattern[i].x, pattern[i].y, i);
traceDots.push(dot);
game.addChild(dot);
// Add number indicator for each dot
var numberText = (i + 1).toString();
var numberIndicator = new Text2(numberText, {
size: 50,
fill: 0x000000
});
numberIndicator.anchor.set(0.5, 0.5);
numberIndicator.x = pattern[i].x;
numberIndicator.y = pattern[i].y;
// Add white circle background for better visibility
var numberBackground = LK.getAsset('traceDot', {
anchorX: 0.5,
anchorY: 0.5,
x: pattern[i].x,
y: pattern[i].y,
scaleX: 1.2,
scaleY: 1.2
});
numberBackground.tint = 0xFFFFFF;
game.addChild(numberBackground);
// Add number to front
game.addChild(numberIndicator);
dotNumbers.push({
number: numberIndicator,
background: numberBackground
});
}
// Add starting point indicator for the first dot
if (traceDots.length > 0) {
var startIndicator = new Text2('START', {
size: 40,
fill: 0xFF5722
});
startIndicator.anchor.set(0.5, 0.5);
startIndicator.x = traceDots[0].x;
startIndicator.y = traceDots[0].y - 60;
game.addChild(startIndicator);
// Add arrow pointing to start
var arrowText = new Text2('↓', {
size: 60,
fill: 0xFF5722
});
arrowText.anchor.set(0.5, 0.5);
arrowText.x = traceDots[0].x;
arrowText.y = traceDots[0].y - 30;
game.addChild(arrowText);
// Animate the starting indicators
tween(startIndicator, {
alpha: 0.3
}, {
duration: 800
});
tween(startIndicator, {
alpha: 1.0
}, {
duration: 800
});
tween(arrowText, {
alpha: 0.3
}, {
duration: 800
});
tween(arrowText, {
alpha: 1.0
}, {
duration: 800
});
// Animate the first number
if (dotNumbers.length > 0) {
tween(dotNumbers[0].number, {
alpha: 0.3
}, {
duration: 800
});
tween(dotNumbers[0].number, {
alpha: 1.0
}, {
duration: 800
});
}
}
// Highlight first dot
if (traceDots.length > 0) {
tween(traceDots[0], {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 500
});
tween(traceDots[0], {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 500
});
}
}
function completeLetterActivity() {
// Mark letter as completed
if (completedLetters.indexOf(currentLetter) === -1) {
completedLetters.push(currentLetter);
storage.completedLetters = completedLetters;
// Unlock next letter
var letterIndex = currentLetter.charCodeAt(0) - 65;
if (letterIndex + 2 > unlockedLetters) {
unlockedLetters = letterIndex + 2;
storage.unlockedLetters = unlockedLetters;
}
// Add the completed letter on the paper
var letterOnPaper = new Text2(currentLetter, {
size: 400,
fill: 0x1B5E20
});
letterOnPaper.anchor.set(0.5, 0.5);
letterOnPaper.x = 1024;
letterOnPaper.y = 1600;
letterOnPaper.alpha = 1;
letterOnPaper.scaleX = 1.0;
letterOnPaper.scaleY = 1.0;
game.addChild(letterOnPaper);
// Animate letter appearing on paper with dramatic effect
tween(letterOnPaper, {
alpha: 1,
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 1000
});
tween(letterOnPaper, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 600
});
// Play celebration sound
LK.getSound('celebration').play();
// Flash screen green
LK.effects.flashScreen(0x4CAF50, 1000);
// Show completion message
var completionText = new Text2('Great job! Letter ' + currentLetter + ' completed!', {
size: 80,
fill: 0x2E7D32
});
completionText.anchor.set(0.5, 0.5);
completionText.x = 1024;
completionText.y = 2000;
game.addChild(completionText);
// Animate completion text
tween(completionText, {
y: 1200
}, {
duration: 1000
});
// Return to letter selection after delay
LK.setTimeout(function () {
setupLetterSelection();
}, 3000);
}
}
function setupSumsActivity() {
currentGameState = 'sumsActivity';
// Clear existing elements
game.removeChildren();
// Add back button
var backToMainFromSums = new Text2('← Back', {
size: 80,
fill: 0x1976D2
});
backToMainFromSums.anchor.set(0, 0);
backToMainFromSums.x = 150;
backToMainFromSums.y = 100;
game.addChild(backToMainFromSums);
// Make back button interactive
backToMainFromSums.down = function (x, y, obj) {
setupMainSelection();
};
// Generate random addition problem based on difficulty
var maxNumber = Math.min(10 + (currentDifficulty - 1) * 5, 50); // Start with 1-10, increase by 5 each level, max 50
currentSum1 = Math.floor(Math.random() * maxNumber) + 1;
currentSum2 = Math.floor(Math.random() * maxNumber) + 1;
currentAnswer = currentSum1 + currentSum2;
// Add problem text
sumsProblemText = new Text2(currentSum1 + ' + ' + currentSum2 + ' = ?', {
size: 200,
fill: 0x2E7D32
});
sumsProblemText.anchor.set(0.5, 0.5);
sumsProblemText.x = 1024;
sumsProblemText.y = 800;
game.addChild(sumsProblemText);
// Add instruction text
var instructionText = new Text2('Solve the addition problem!', {
size: 100,
fill: 0xFF5722
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 600;
game.addChild(instructionText);
// Add difficulty and progress display
var difficultyText = new Text2('Level ' + currentDifficulty + ' - Problems completed: ' + sumsCompleted, {
size: 60,
fill: 0x666666
});
difficultyText.anchor.set(0.5, 0.5);
difficultyText.x = 1024;
difficultyText.y = 500;
game.addChild(difficultyText);
// Add input field for user answer
userInputText = new Text2('?', {
size: 180,
fill: 0x000000
});
userInputText.anchor.set(0.5, 0.5);
userInputText.x = 1024;
userInputText.y = 1000;
game.addChild(userInputText);
// Add input box background
var inputBox = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1000,
scaleX: 0.8,
scaleY: 0.8
});
game.addChild(inputBox);
// Re-add text on top of box
game.addChild(userInputText);
// Store current user input
currentUserInput = '';
// Add feedback text (initially hidden)
feedbackText = new Text2('', {
size: 100,
fill: 0x4CAF50
});
feedbackText.anchor.set(0.5, 0.5);
feedbackText.x = 1024;
feedbackText.y = 1200;
feedbackText.alpha = 0;
game.addChild(feedbackText);
// Add answer text (initially hidden)
sumsAnswerText = new Text2('Answer: ' + currentAnswer, {
size: 120,
fill: 0x4CAF50
});
sumsAnswerText.anchor.set(0.5, 0.5);
sumsAnswerText.x = 1024;
sumsAnswerText.y = 1300;
sumsAnswerText.alpha = 0;
game.addChild(sumsAnswerText);
// Add "Show Answer" button
var showAnswerButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1400
});
game.addChild(showAnswerButton);
var showAnswerText = new Text2('SHOW ANSWER', {
size: 60,
fill: 0xFFFFFF
});
showAnswerText.anchor.set(0.5, 0.5);
showAnswerText.x = 1024;
showAnswerText.y = 1400;
game.addChild(showAnswerText);
// Add number buttons for input (0-9)
numberButtons = []; // Reset the global array
var buttonStartX = 200;
var buttonStartY = 1450;
var buttonSpacing = 160;
for (var i = 0; i <= 9; i++) {
var buttonX = buttonStartX + i % 5 * buttonSpacing;
var buttonY = buttonStartY + Math.floor(i / 5) * 120;
var numButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: buttonX,
y: buttonY,
scaleX: 0.7,
scaleY: 0.7
});
game.addChild(numButton);
var numButtonText = new Text2(i.toString(), {
size: 100,
fill: 0xFFFFFF
});
numButtonText.anchor.set(0.5, 0.5);
numButtonText.x = buttonX;
numButtonText.y = buttonY;
game.addChild(numButtonText);
numberButtons.push({
button: numButton,
text: numButtonText,
number: i
});
}
// Add clear button
var clearButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1550,
scaleX: 0.6,
scaleY: 0.4
});
game.addChild(clearButton);
var clearButtonText = new Text2('CLEAR', {
size: 50,
fill: 0xFFFFFF
});
clearButtonText.anchor.set(0.5, 0.5);
clearButtonText.x = 1024;
clearButtonText.y = 1550;
game.addChild(clearButtonText);
// Add check answer button
var checkButton = LK.getAsset('letterBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 1400,
y: 1550,
scaleX: 0.8,
scaleY: 0.4
});
game.addChild(checkButton);
var checkButtonText = new Text2('CHECK', {
size: 50,
fill: 0xFFFFFF
});
checkButtonText.anchor.set(0.5, 0.5);
checkButtonText.x = 1400;
checkButtonText.y = 1550;
game.addChild(checkButtonText);
// Next problem button removed - auto-advance when correct
}
function completeNumberActivity() {
// Mark number as completed
if (completedNumbers.indexOf(currentNumber) === -1) {
completedNumbers.push(currentNumber);
storage.completedNumbers = completedNumbers;
// Unlock next number
var numberIndex = parseInt(currentNumber) - 1;
if (numberIndex + 2 > unlockedNumbers) {
unlockedNumbers = numberIndex + 2;
storage.unlockedNumbers = unlockedNumbers;
}
// Add the completed number on the paper
var numberOnPaper = new Text2(currentNumber, {
size: 400,
fill: 0x1B5E20
});
numberOnPaper.anchor.set(0.5, 0.5);
numberOnPaper.x = 1024;
numberOnPaper.y = 1600;
numberOnPaper.alpha = 1;
numberOnPaper.scaleX = 1.0;
numberOnPaper.scaleY = 1.0;
game.addChild(numberOnPaper);
// Animate number appearing on paper with dramatic effect
tween(numberOnPaper, {
alpha: 1,
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 1000
});
tween(numberOnPaper, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 600
});
// Play celebration sound
LK.getSound('celebration').play();
// Flash screen green
LK.effects.flashScreen(0x4CAF50, 1000);
// Show completion message
var completionText = new Text2('Great job! Number ' + currentNumber + ' completed!', {
size: 80,
fill: 0x2E7D32
});
completionText.anchor.set(0.5, 0.5);
completionText.x = 1024;
completionText.y = 2000;
game.addChild(completionText);
// Animate completion text
tween(completionText, {
y: 1200
}, {
duration: 1000
});
// Return to number selection after delay
LK.setTimeout(function () {
setupNumberSelection();
}, 3000);
}
}
// Restart function to reset game state
function restartGame() {
// Reset game state variables
currentGameState = 'mainSelection';
currentLetter = '';
currentNumber = '';
currentTraceIndex = 0;
sumsCompleted = 0;
currentDifficulty = 1;
// Clear arrays
letterBoxes = [];
numberBoxes = [];
traceDots = [];
// Reset progress - uncommented to fully restart the game
unlockedLetters = 1;
completedLetters = [];
unlockedNumbers = 1;
completedNumbers = [];
storage.unlockedLetters = unlockedLetters;
storage.completedLetters = completedLetters;
storage.unlockedNumbers = unlockedNumbers;
storage.completedNumbers = completedNumbers;
// Return to main selection
setupMainSelection();
}
// Event handlers
game.down = function (x, y, obj) {
if (currentGameState === 'mainSelection') {
// Check if Letters button was clicked
if (x >= 600 && x <= 800 && y >= 1100 && y <= 1300) {
setupLetterSelection();
return;
}
// Check if Numbers button was clicked
if (x >= 1248 && x <= 1448 && y >= 1100 && y <= 1300) {
setupNumberSelection();
return;
}
// Check if Sums button was clicked
if (x >= 924 && x <= 1124 && y >= 1500 && y <= 1700) {
setupSumsActivity();
return;
}
}
if (currentGameState === 'letterSelection') {
// Check if back button was clicked
if (x >= 100 && x <= 300 && y >= 50 && y <= 150) {
setupMainSelection();
return;
}
}
if (currentGameState === 'numberSelection') {
// Check if back button was clicked
if (x >= 100 && x <= 300 && y >= 50 && y <= 150) {
setupMainSelection();
return;
}
}
if (currentGameState === 'letterActivity') {
// Check if back button was clicked
if (x >= 100 && x <= 300 && y >= 50 && y <= 150) {
setupLetterSelection();
return;
}
// Check if current trace dot was touched
if (currentTraceIndex < traceDots.length) {
var currentDot = traceDots[currentTraceIndex];
var distance = Math.sqrt(Math.pow(x - currentDot.x, 2) + Math.pow(y - currentDot.y, 2));
if (distance < 80) {
currentDot.complete();
// Hide the number indicator for the completed dot
if (dotNumbers && dotNumbers[currentTraceIndex]) {
dotNumbers[currentTraceIndex].number.alpha = 0;
dotNumbers[currentTraceIndex].background.alpha = 0;
}
currentTraceIndex++;
// Highlight next dot
if (currentTraceIndex < traceDots.length) {
var nextDot = traceDots[currentTraceIndex];
tween(nextDot, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 300
});
tween(nextDot, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300
});
} else {
// All dots completed
LK.getSound('letterComplete').play();
LK.setTimeout(function () {
completeLetterActivity();
}, 1000);
}
}
}
}
if (currentGameState === 'numberActivity') {
// Check if back button was clicked
if (x >= 100 && x <= 300 && y >= 50 && y <= 150) {
setupNumberSelection();
return;
}
// Check if current trace dot was touched
if (currentTraceIndex < traceDots.length) {
var currentDot = traceDots[currentTraceIndex];
var distance = Math.sqrt(Math.pow(x - currentDot.x, 2) + Math.pow(y - currentDot.y, 2));
if (distance < 80) {
currentDot.complete();
// Hide the number indicator for the completed dot
if (dotNumbers && dotNumbers[currentTraceIndex]) {
dotNumbers[currentTraceIndex].number.alpha = 0;
dotNumbers[currentTraceIndex].background.alpha = 0;
}
currentTraceIndex++;
// Highlight next dot
if (currentTraceIndex < traceDots.length) {
var nextDot = traceDots[currentTraceIndex];
tween(nextDot, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 300
});
tween(nextDot, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300
});
} else {
// All dots completed
LK.getSound('letterComplete').play();
LK.setTimeout(function () {
completeNumberActivity();
}, 1000);
}
}
}
}
if (currentGameState === 'sumsActivity') {
// Check if back button was clicked
if (x >= 100 && x <= 300 && y >= 50 && y <= 150) {
setupMainSelection();
return;
}
// Check number button clicks
for (var i = 0; i < numberButtons.length; i++) {
var btn = numberButtons[i];
var btnX = btn.button.x;
var btnY = btn.button.y;
if (x >= btnX - 56 && x <= btnX + 56 && y >= btnY - 42 && y <= btnY + 42) {
if (currentUserInput.length < 2) {
// Limit to 2 digits
currentUserInput += btn.number.toString();
userInputText.setText(currentUserInput);
}
return;
}
}
// Check clear button
if (x >= 924 && x <= 1124 && y >= 1500 && y <= 1600) {
currentUserInput = '';
userInputText.setText('?');
feedbackText.alpha = 0;
return;
}
// Check answer button
if (x >= 1300 && x <= 1500 && y >= 1500 && y <= 1600) {
if (currentUserInput !== '') {
var userAnswer = parseInt(currentUserInput);
if (userAnswer === currentAnswer) {
sumsCompleted++; // Increment completed problems counter
// Check if difficulty should increase (every 5 problems)
if (sumsCompleted % 5 === 0 && currentDifficulty < 10) {
currentDifficulty++;
feedbackText.setText('¡Correcto! Level up! Now Level ' + currentDifficulty);
LK.effects.flashScreen(0xFFD700, 1000); // Gold flash for level up
} else {
feedbackText.setText('¡Correcto! Well done!');
LK.effects.flashScreen(0x4CAF50, 500);
}
feedbackText.fill = 0x4CAF50; // Green
LK.getSound('correctAction').play();
// Auto-advance to next problem immediately when correct
LK.setTimeout(function () {
setupSumsActivity();
}, 1500);
} else {
feedbackText.setText('Incorrecto. Try again!');
feedbackText.fill = 0xF44336; // Red
LK.effects.flashScreen(0xF44336, 500);
}
tween(feedbackText, {
alpha: 1
}, {
duration: 500
});
}
return;
}
// Check if Show Answer button was clicked
if (x >= 924 && x <= 1124 && y >= 1300 && y <= 1500) {
// Show the answer with animation
tween(sumsAnswerText, {
alpha: 1
}, {
duration: 500
});
// Play correct action sound
LK.getSound('correctAction').play();
return;
}
// Next problem button click handler removed - auto-advance when correct
}
};
game.update = function () {
// Update any ongoing animations or game logic
if (currentGameState === 'letterActivity') {
// Removed floating animation to prevent letters from moving
}
};
// Create monkey sprite and make it visible
var monkey = LK.getAsset('Monkey', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
game.addChild(monkey);
// Initialize the game
setupMainSelection();
Fullscreen modern App Store landscape banner, 16:9, high definition, for a game titled "ABC Learning Adventure" and with the description "An educational alphabet learning game where children interact with letters A-Z through touch-based puzzles and mini-games, designed to make learning the alphabet fun and engaging.". No text on banner!
star. In-Game asset. 2d. High contrast. No shadows
horizontal papel blanco. In-Game asset. 2d. High contrast. No shadows
Cuadrado verde con lados circulares. In-Game asset. 2d. High contrast. No shadows
Cuadrado gris con lados circulares
Palm tree. In-Game asset. 2d. High contrast. No shadows
Grass. In-Game asset. 2d. High contrast. No shadows