/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var NumberDisplay = Container.expand(function () { var self = Container.call(this); var bg = self.attachAsset('numberDisplay', { anchorX: 0.5, anchorY: 0.5 }); var numberText = new Text2('?', { size: 80, fill: 0xFFFFFF }); numberText.anchor.set(0.5, 0.5); self.addChild(numberText); self.currentNumber = 0; self.generateNumber = function () { self.currentNumber = Math.floor(Math.random() * 100) + 1; numberText.setText(self.currentNumber.toString()); // Pulse animation tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 150, easing: tween.easeOut }); tween(self, { scaleX: 1.0, scaleY: 1.0 }, { duration: 150, easing: tween.easeIn }); }; return self; }); var StreakDisplay = Container.expand(function () { var self = Container.call(this); var bg = self.attachAsset('streakBg', { anchorX: 0.5, anchorY: 0.5 }); var streakText = new Text2('Streak: 0', { size: 30, fill: 0x000000 }); streakText.anchor.set(0.5, 0.5); self.addChild(streakText); self.currentStreak = 0; self.updateStreak = function (streak) { self.currentStreak = streak; streakText.setText('Streak: ' + streak); if (streak > 0) { // Flash animation for streak tween(bg, { tint: 0xffffff }, { duration: 200 }); tween(bg, { tint: 0xffd700 }, { duration: 200 }); } }; return self; }); var TargetPattern = Container.expand(function () { var self = Container.call(this); var bg = self.attachAsset('targetPattern', { anchorX: 0.5, anchorY: 0.5 }); var patternText = new Text2('Target: 50-60', { size: 40, fill: 0xFFFFFF }); patternText.anchor.set(0.5, 0.5); self.addChild(patternText); self.targetMin = 50; self.targetMax = 60; self.points = 10; self.generatePattern = function (difficulty) { var patternType = Math.floor(Math.random() * 3); if (patternType === 0) { // Range pattern var center = Math.floor(Math.random() * 80) + 10; var range = Math.max(5, 20 - difficulty * 2); self.targetMin = center - Math.floor(range / 2); self.targetMax = center + Math.floor(range / 2); patternText.setText('Target: ' + self.targetMin + '-' + self.targetMax); self.points = 10 + difficulty * 2; } else if (patternType === 1) { // Even/Odd pattern var isEven = Math.random() < 0.5; self.targetMin = isEven ? 2 : 1; self.targetMax = isEven ? 100 : 99; patternText.setText(isEven ? 'Target: EVEN' : 'Target: ODD'); self.points = 5 + difficulty; } else { // Divisible pattern var divisor = [3, 5, 7, 11][Math.floor(Math.random() * 4)]; self.targetMin = divisor; self.targetMax = divisor; patternText.setText('Target: ÷' + divisor); self.points = 15 + difficulty * 3; } }; self.checkMatch = function (number) { if (self.targetMin === self.targetMax) { // Divisible pattern return number % self.targetMin === 0; } else if (self.targetMin === 1 || self.targetMin === 2) { // Even/Odd pattern return number % 2 === 0 && self.targetMin === 2 || number % 2 === 1 && self.targetMin === 1; } else { // Range pattern return number >= self.targetMin && number <= self.targetMax; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a2e }); /**** * Game Code ****/ // Game state variables var gameTime = 60000; // 60 seconds var timeRemaining = gameTime; var difficulty = 1; var currentStreak = 0; var multiplier = 1; var gameActive = true; // UI Elements var scoreTxt = new Text2('0', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var timeTxt = new Text2('60', { size: 50, fill: 0xFF6B6B }); timeTxt.anchor.set(1, 0); timeTxt.x = -20; timeTxt.y = 20; LK.gui.topRight.addChild(timeTxt); var difficultyTxt = new Text2('Level 1', { size: 40, fill: 0x4ECDC4 }); difficultyTxt.anchor.set(0, 0); difficultyTxt.x = 20; difficultyTxt.y = 20; LK.gui.topLeft.addChild(difficultyTxt); // Game objects var tapArea = game.attachAsset('tapArea', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366, alpha: 0.1 }); var numberDisplay = game.addChild(new NumberDisplay()); numberDisplay.x = 1024; numberDisplay.y = 800; var targetPattern = game.addChild(new TargetPattern()); targetPattern.x = 1024; targetPattern.y = 400; var streakDisplay = game.addChild(new StreakDisplay()); streakDisplay.x = 1024; streakDisplay.y = 1200; // Initialize first pattern targetPattern.generatePattern(difficulty); // Instructions var instructionText = new Text2('TAP TO GENERATE NUMBERS!', { size: 50, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0.5); instructionText.x = 1024; instructionText.y = 600; game.addChild(instructionText); // Fade out instructions after 3 seconds LK.setTimeout(function () { tween(instructionText, { alpha: 0 }, { duration: 1000 }); }, 3000); // Game timer var gameTimer = LK.setInterval(function () { if (!gameActive) return; timeRemaining -= 100; var seconds = Math.ceil(timeRemaining / 1000); timeTxt.setText(seconds.toString()); if (timeRemaining <= 0) { gameActive = false; LK.clearInterval(gameTimer); if (LK.getScore() >= 500) { LK.showYouWin(); } else { LK.showGameOver(); } } }, 100); // Difficulty progression var difficultyTimer = LK.setInterval(function () { if (!gameActive) return; difficulty = Math.min(10, Math.floor((gameTime - timeRemaining) / 10000) + 1); difficultyTxt.setText('Level ' + difficulty); // Generate new pattern every 5 seconds if ((gameTime - timeRemaining) % 5000 < 100) { targetPattern.generatePattern(difficulty); } }, 100); // Touch handling game.down = function (x, y, obj) { if (!gameActive) return; numberDisplay.generateNumber(); LK.getSound('numberGenerate').play(); // Check for match if (targetPattern.checkMatch(numberDisplay.currentNumber)) { // Match found! currentStreak++; multiplier = Math.min(5, 1 + Math.floor(currentStreak / 3)); var points = targetPattern.points * multiplier; LK.setScore(LK.getScore() + points); scoreTxt.setText(LK.getScore().toString()); streakDisplay.updateStreak(currentStreak); // Visual feedback LK.effects.flashObject(targetPattern, 0x00ff00, 500); if (currentStreak > 1) { LK.getSound('streak').play(); } else { LK.getSound('match').play(); } // Generate new pattern targetPattern.generatePattern(difficulty); } else { // No match, reset streak if (currentStreak > 0) { currentStreak = 0; multiplier = 1; streakDisplay.updateStreak(currentStreak); // Flash red for missed match LK.effects.flashObject(numberDisplay, 0xff0000, 300); } } }; // Multiplier display var multiplierTxt = new Text2('x1', { size: 40, fill: 0xFFD700 }); multiplierTxt.anchor.set(0.5, 1); LK.gui.bottom.addChild(multiplierTxt); game.update = function () { if (!gameActive) return; // Update multiplier display multiplierTxt.setText('x' + multiplier); // Pulse multiplier when active if (multiplier > 1) { var pulse = Math.sin(LK.ticks * 0.1) * 0.1 + 1; multiplierTxt.scaleX = pulse; multiplierTxt.scaleY = pulse; } else { multiplierTxt.scaleX = 1; multiplierTxt.scaleY = 1; } // Time warning effect if (timeRemaining < 10000) { var flash = Math.sin(LK.ticks * 0.3) * 0.3 + 0.7; timeTxt.alpha = flash; } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,292 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var NumberDisplay = Container.expand(function () {
+ var self = Container.call(this);
+ var bg = self.attachAsset('numberDisplay', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var numberText = new Text2('?', {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ numberText.anchor.set(0.5, 0.5);
+ self.addChild(numberText);
+ self.currentNumber = 0;
+ self.generateNumber = function () {
+ self.currentNumber = Math.floor(Math.random() * 100) + 1;
+ numberText.setText(self.currentNumber.toString());
+ // Pulse animation
+ tween(self, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 150,
+ easing: tween.easeOut
+ });
+ tween(self, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 150,
+ easing: tween.easeIn
+ });
+ };
+ return self;
+});
+var StreakDisplay = Container.expand(function () {
+ var self = Container.call(this);
+ var bg = self.attachAsset('streakBg', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var streakText = new Text2('Streak: 0', {
+ size: 30,
+ fill: 0x000000
+ });
+ streakText.anchor.set(0.5, 0.5);
+ self.addChild(streakText);
+ self.currentStreak = 0;
+ self.updateStreak = function (streak) {
+ self.currentStreak = streak;
+ streakText.setText('Streak: ' + streak);
+ if (streak > 0) {
+ // Flash animation for streak
+ tween(bg, {
+ tint: 0xffffff
+ }, {
+ duration: 200
+ });
+ tween(bg, {
+ tint: 0xffd700
+ }, {
+ duration: 200
+ });
+ }
+ };
+ return self;
+});
+var TargetPattern = Container.expand(function () {
+ var self = Container.call(this);
+ var bg = self.attachAsset('targetPattern', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var patternText = new Text2('Target: 50-60', {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ patternText.anchor.set(0.5, 0.5);
+ self.addChild(patternText);
+ self.targetMin = 50;
+ self.targetMax = 60;
+ self.points = 10;
+ self.generatePattern = function (difficulty) {
+ var patternType = Math.floor(Math.random() * 3);
+ if (patternType === 0) {
+ // Range pattern
+ var center = Math.floor(Math.random() * 80) + 10;
+ var range = Math.max(5, 20 - difficulty * 2);
+ self.targetMin = center - Math.floor(range / 2);
+ self.targetMax = center + Math.floor(range / 2);
+ patternText.setText('Target: ' + self.targetMin + '-' + self.targetMax);
+ self.points = 10 + difficulty * 2;
+ } else if (patternType === 1) {
+ // Even/Odd pattern
+ var isEven = Math.random() < 0.5;
+ self.targetMin = isEven ? 2 : 1;
+ self.targetMax = isEven ? 100 : 99;
+ patternText.setText(isEven ? 'Target: EVEN' : 'Target: ODD');
+ self.points = 5 + difficulty;
+ } else {
+ // Divisible pattern
+ var divisor = [3, 5, 7, 11][Math.floor(Math.random() * 4)];
+ self.targetMin = divisor;
+ self.targetMax = divisor;
+ patternText.setText('Target: ÷' + divisor);
+ self.points = 15 + difficulty * 3;
+ }
+ };
+ self.checkMatch = function (number) {
+ if (self.targetMin === self.targetMax) {
+ // Divisible pattern
+ return number % self.targetMin === 0;
+ } else if (self.targetMin === 1 || self.targetMin === 2) {
+ // Even/Odd pattern
+ return number % 2 === 0 && self.targetMin === 2 || number % 2 === 1 && self.targetMin === 1;
+ } else {
+ // Range pattern
+ return number >= self.targetMin && number <= self.targetMax;
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a2e
+});
+
+/****
+* Game Code
+****/
+// Game state variables
+var gameTime = 60000; // 60 seconds
+var timeRemaining = gameTime;
+var difficulty = 1;
+var currentStreak = 0;
+var multiplier = 1;
+var gameActive = true;
+// UI Elements
+var scoreTxt = new Text2('0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var timeTxt = new Text2('60', {
+ size: 50,
+ fill: 0xFF6B6B
+});
+timeTxt.anchor.set(1, 0);
+timeTxt.x = -20;
+timeTxt.y = 20;
+LK.gui.topRight.addChild(timeTxt);
+var difficultyTxt = new Text2('Level 1', {
+ size: 40,
+ fill: 0x4ECDC4
+});
+difficultyTxt.anchor.set(0, 0);
+difficultyTxt.x = 20;
+difficultyTxt.y = 20;
+LK.gui.topLeft.addChild(difficultyTxt);
+// Game objects
+var tapArea = game.attachAsset('tapArea', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: 1366,
+ alpha: 0.1
+});
+var numberDisplay = game.addChild(new NumberDisplay());
+numberDisplay.x = 1024;
+numberDisplay.y = 800;
+var targetPattern = game.addChild(new TargetPattern());
+targetPattern.x = 1024;
+targetPattern.y = 400;
+var streakDisplay = game.addChild(new StreakDisplay());
+streakDisplay.x = 1024;
+streakDisplay.y = 1200;
+// Initialize first pattern
+targetPattern.generatePattern(difficulty);
+// Instructions
+var instructionText = new Text2('TAP TO GENERATE NUMBERS!', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0.5);
+instructionText.x = 1024;
+instructionText.y = 600;
+game.addChild(instructionText);
+// Fade out instructions after 3 seconds
+LK.setTimeout(function () {
+ tween(instructionText, {
+ alpha: 0
+ }, {
+ duration: 1000
+ });
+}, 3000);
+// Game timer
+var gameTimer = LK.setInterval(function () {
+ if (!gameActive) return;
+ timeRemaining -= 100;
+ var seconds = Math.ceil(timeRemaining / 1000);
+ timeTxt.setText(seconds.toString());
+ if (timeRemaining <= 0) {
+ gameActive = false;
+ LK.clearInterval(gameTimer);
+ if (LK.getScore() >= 500) {
+ LK.showYouWin();
+ } else {
+ LK.showGameOver();
+ }
+ }
+}, 100);
+// Difficulty progression
+var difficultyTimer = LK.setInterval(function () {
+ if (!gameActive) return;
+ difficulty = Math.min(10, Math.floor((gameTime - timeRemaining) / 10000) + 1);
+ difficultyTxt.setText('Level ' + difficulty);
+ // Generate new pattern every 5 seconds
+ if ((gameTime - timeRemaining) % 5000 < 100) {
+ targetPattern.generatePattern(difficulty);
+ }
+}, 100);
+// Touch handling
+game.down = function (x, y, obj) {
+ if (!gameActive) return;
+ numberDisplay.generateNumber();
+ LK.getSound('numberGenerate').play();
+ // Check for match
+ if (targetPattern.checkMatch(numberDisplay.currentNumber)) {
+ // Match found!
+ currentStreak++;
+ multiplier = Math.min(5, 1 + Math.floor(currentStreak / 3));
+ var points = targetPattern.points * multiplier;
+ LK.setScore(LK.getScore() + points);
+ scoreTxt.setText(LK.getScore().toString());
+ streakDisplay.updateStreak(currentStreak);
+ // Visual feedback
+ LK.effects.flashObject(targetPattern, 0x00ff00, 500);
+ if (currentStreak > 1) {
+ LK.getSound('streak').play();
+ } else {
+ LK.getSound('match').play();
+ }
+ // Generate new pattern
+ targetPattern.generatePattern(difficulty);
+ } else {
+ // No match, reset streak
+ if (currentStreak > 0) {
+ currentStreak = 0;
+ multiplier = 1;
+ streakDisplay.updateStreak(currentStreak);
+ // Flash red for missed match
+ LK.effects.flashObject(numberDisplay, 0xff0000, 300);
+ }
+ }
+};
+// Multiplier display
+var multiplierTxt = new Text2('x1', {
+ size: 40,
+ fill: 0xFFD700
+});
+multiplierTxt.anchor.set(0.5, 1);
+LK.gui.bottom.addChild(multiplierTxt);
+game.update = function () {
+ if (!gameActive) return;
+ // Update multiplier display
+ multiplierTxt.setText('x' + multiplier);
+ // Pulse multiplier when active
+ if (multiplier > 1) {
+ var pulse = Math.sin(LK.ticks * 0.1) * 0.1 + 1;
+ multiplierTxt.scaleX = pulse;
+ multiplierTxt.scaleY = pulse;
+ } else {
+ multiplierTxt.scaleX = 1;
+ multiplierTxt.scaleY = 1;
+ }
+ // Time warning effect
+ if (timeRemaining < 10000) {
+ var flash = Math.sin(LK.ticks * 0.3) * 0.3 + 0.7;
+ timeTxt.alpha = flash;
+ }
+};
\ No newline at end of file