/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var AICompetitor = Container.expand(function () { var self = Container.call(this); var aiDisplay = self.attachAsset('numberDisplay', { anchorX: 0.5, anchorY: 0.5 }); aiDisplay.tint = 0xff6b6b; // Red tint for AI var aiText = new Text2('AI', { size: 40, fill: 0xFFFFFF }); aiText.anchor.set(0.5, 0.5); aiText.y = -80; self.addChild(aiText); var aiNumberText = new Text2('?', { size: 60, fill: 0xFFFFFF }); aiNumberText.anchor.set(0.5, 0.5); self.addChild(aiNumberText); self.currentNumber = 0; self.aiScore = 0; self.aiStreak = 0; self.lastAttemptTime = 0; self.difficulty = 1; // AI intelligence parameters self.reactionTime = 1000; // Base reaction time in ms self.accuracy = 0.7; // Base accuracy (70%) self.patternMemory = []; self.setDifficulty = function (diff) { self.difficulty = diff; // Adjust AI parameters based on difficulty if (diff <= 3) { self.reactionTime = 1500 - diff * 100; // Slower at lower difficulties self.accuracy = 0.5 + diff * 0.1; // Less accurate } else if (diff <= 7) { self.reactionTime = 1200 - diff * 50; self.accuracy = 0.6 + diff * 0.05; } else { self.reactionTime = 800; // Very fast at high difficulty self.accuracy = 0.85; // Very accurate } }; self.generateNumber = function () { self.currentNumber = Math.floor(Math.random() * 100) + 1; aiNumberText.setText(self.currentNumber.toString()); // Add subtle pulse animation to AI number generation tween(aiNumberText, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(aiNumberText, { scaleX: 1.0, scaleY: 1.0 }, { duration: 300, easing: tween.bounceOut }); } }); // Subtle color flash for AI display tween(aiDisplay, { tint: 0xff9999 }, { duration: 150, easing: tween.easeOut, onFinish: function onFinish() { tween(aiDisplay, { tint: 0xff6b6b }, { duration: 200, easing: tween.easeIn }); } }); }; self.attemptMatch = function (targetPattern) { var currentTime = Date.now(); if (currentTime - self.lastAttemptTime < self.reactionTime) { return false; // Still in cooldown } // AI decision making with some randomness var shouldAttempt = Math.random() < 0.3; // 30% chance to attempt each update if (!shouldAttempt) return false; self.lastAttemptTime = currentTime; // Smart number generation based on pattern var targetNumber = self.generateSmartNumber(targetPattern); if (targetNumber !== null) { self.currentNumber = targetNumber; } else { // Fallback to random if can't determine good number self.generateNumber(); return false; } aiNumberText.setText(self.currentNumber.toString()); // Check if AI's number matches the pattern var isMatch = targetPattern.checkMatch(self.currentNumber); // Add some inaccuracy - AI might miss even when it should match if (isMatch && Math.random() > self.accuracy) { isMatch = false; // AI missed due to inaccuracy } if (isMatch) { self.aiStreak++; var aiMultiplier = Math.min(5, 1 + Math.floor(self.aiStreak / 3)); var points = targetPattern.points * aiMultiplier; // Only allow AI to get points if KEMALDEV effect is active if (kemaldevEffectActive) { self.aiScore += points; } // Visual feedback for AI success tween(self, { rotation: Math.PI }, { duration: 400, easing: tween.easeOut }); // Success particles if (typeof particleSystem !== 'undefined') { particleSystem.burst(self.x, self.y, 0xff6b6b, 8); } return true; } else { // AI missed - reset streak if (self.aiStreak > 0) { self.aiStreak = 0; } return false; } }; self.generateSmartNumber = function (targetPattern) { // AI tries to be smart about number generation if (targetPattern.targetMin === targetPattern.targetMax) { // Divisible pattern var divisor = targetPattern.targetMin; var multiple = Math.floor(Math.random() * (100 / divisor)) + 1; return multiple * divisor; } else if (targetPattern.targetMin === 1 || targetPattern.targetMin === 2) { // Even/Odd pattern if (targetPattern.targetMin === 2) { // Even number needed return (Math.floor(Math.random() * 50) + 1) * 2; } else { // Odd number needed return Math.floor(Math.random() * 50) * 2 + 1; } } else { // Range pattern var range = targetPattern.targetMax - targetPattern.targetMin + 1; return targetPattern.targetMin + Math.floor(Math.random() * range); } }; return self; }); 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()); // Enhanced pulse with rainbow color cycling tween(self, { scaleX: 1.4, scaleY: 1.4, rotation: 0.2 }, { duration: 150, easing: tween.easeOut }); tween(self, { scaleX: 1.0, scaleY: 1.0, rotation: 0 }, { duration: 400, easing: tween.bounceOut }); // Multi-color flash sequence tween(bg, { tint: 0xfd79a8 }, { duration: 80, easing: tween.easeOut, onFinish: function onFinish() { tween(bg, { tint: 0x74b9ff }, { duration: 80, easing: tween.easeOut, onFinish: function onFinish() { tween(bg, { tint: 0x6c5ce7 }, { duration: 150, easing: tween.easeIn }); } }); } }); // Text glow effect tween(numberText, { tint: 0xfdcb6e }, { duration: 100, easing: tween.easeOut }); tween(numberText, { tint: 0xffffff }, { duration: 200, easing: tween.easeIn }); }; return self; }); var Particle = Container.expand(function () { var self = Container.call(this); var particle = self.attachAsset('numberDisplay', { anchorX: 0.5, anchorY: 0.5 }); self.vx = 0; self.vy = 0; self.life = 1.0; self.decay = 0.02; self.init = function (color, size) { particle.tint = color; self.scaleX = size; self.scaleY = size; self.alpha = 0.9; // Enhanced random velocity with more dynamic movement self.vx = (Math.random() - 0.5) * 15; self.vy = (Math.random() - 0.5) * 15 - 8; // Add rotation for more dynamic particles self.rotation = Math.random() * Math.PI * 2; self.rotationSpeed = (Math.random() - 0.5) * 0.3; }; self.update = function () { self.x += self.vx; self.y += self.vy; self.vy += 0.3; // gravity self.vx *= 0.99; // air resistance self.life -= self.decay; self.alpha = self.life * 0.8; self.scaleX *= 0.97; self.scaleY *= 0.97; // Add rotation animation self.rotation += self.rotationSpeed; // Color shifting effect as particle fades var lifeFactor = self.life; if (lifeFactor > 0.5) { particle.tint = particle.tint; // Keep original color } else { // Fade to warm colors var fadeAmount = (0.5 - lifeFactor) * 2; particle.tint = 0xfdcb6e * fadeAmount + particle.tint * (1 - fadeAmount); } if (self.life <= 0) { self.destroy(); } }; return self; }); var ParticleSystem = Container.expand(function () { var self = Container.call(this); var particles = []; self.burst = function (x, y, color, count) { for (var i = 0; i < count; i++) { var particle = new Particle(); particle.x = x; particle.y = y; particle.init(color, Math.random() * 0.3 + 0.2); particles.push(particle); self.addChild(particle); } }; self.update = function () { for (var i = particles.length - 1; i >= 0; i--) { if (particles[i].life <= 0) { particles.splice(i, 1); } } }; return self; }); var StartMenu = Container.expand(function () { var self = Container.call(this); // Background overlay with gradient effect var bg = self.attachAsset('tapArea', { anchorX: 0.5, anchorY: 0.5, alpha: 0.95 }); bg.tint = 0x2d3436; // Add title background for better contrast var titleBg = self.attachAsset('titleBg', { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 }); titleBg.y = -300; titleBg.tint = 0x636e72; self.addChild(titleBg); // Title with enhanced styling - centered var titleText = new Text2(getText('title'), { size: 85, fill: 0xfdcb6e }); titleText.anchor.set(0.5, 0.5); titleText.x = 0; titleText.y = -300; self.addChild(titleText); // Add subtitle glow effect - centered var titleGlow = new Text2(getText('title'), { size: 87, fill: 0xffffff }); titleGlow.anchor.set(0.5, 0.5); titleGlow.x = 0; titleGlow.y = -300; titleGlow.alpha = 0.3; self.addChild(titleGlow); self.addChild(titleText); // Ensure title is on top // Instructions - centered var instructText = new Text2(getText('instructions'), { size: 50, fill: 0xCCCCCC }); instructText.anchor.set(0.5, 0.5); instructText.x = 0; instructText.y = 100; self.addChild(instructText); // Entrance animations self.show = function () { self.alpha = 0; self.scaleX = 0.8; self.scaleY = 0.8; tween(self, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 800, easing: tween.bounceOut }); // Pulse title var _pulseTitleAnim = function pulseTitleAnim() { tween(titleText, { scaleX: 1.05, scaleY: 1.05 }, { duration: 1500, easing: tween.easeInOut, onFinish: function onFinish() { tween(titleText, { scaleX: 1, scaleY: 1 }, { duration: 1500, easing: tween.easeInOut, onFinish: _pulseTitleAnim }); } }); }; LK.setTimeout(_pulseTitleAnim, 500); // Gentle left-right movement for instruction text var _instructMoveAnim = function instructMoveAnim() { tween(instructText, { x: 5 }, { duration: 3000, easing: tween.easeInOut, onFinish: function onFinish() { tween(instructText, { x: -5 }, { duration: 3000, easing: tween.easeInOut, onFinish: function onFinish() { tween(instructText, { x: 0 }, { duration: 3000, easing: tween.easeInOut, onFinish: _instructMoveAnim }); } }); } }); }; LK.setTimeout(_instructMoveAnim, 1500); // Subtle left-right movement for title text var _titleMoveAnim = function titleMoveAnim() { tween(titleText, { x: 8 }, { duration: 4000, easing: tween.easeInOut, onFinish: function onFinish() { tween(titleText, { x: -8 }, { duration: 4000, easing: tween.easeInOut, onFinish: function onFinish() { tween(titleText, { x: 0 }, { duration: 4000, easing: tween.easeInOut, onFinish: _titleMoveAnim }); } }); } }); }; LK.setTimeout(_titleMoveAnim, 1000); // Subtle left-right movement for title glow (synchronized) var _titleGlowMoveAnim = function titleGlowMoveAnim() { tween(titleGlow, { x: 8 }, { duration: 4000, easing: tween.easeInOut, onFinish: function onFinish() { tween(titleGlow, { x: -8 }, { duration: 4000, easing: tween.easeInOut, onFinish: function onFinish() { tween(titleGlow, { x: 0 }, { duration: 4000, easing: tween.easeInOut, onFinish: _titleGlowMoveAnim }); } }); } }); }; LK.setTimeout(_titleGlowMoveAnim, 1000); }; self.hide = function (callback) { tween(self, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 500, easing: tween.easeIn, onFinish: function onFinish() { self.destroy(); if (callback) callback(); } }); }; // Language toggle button var langButton = new Text2(getText('language'), { size: 40, fill: 0x74b9ff }); langButton.anchor.set(1, 0); langButton.x = 280; langButton.y = -450; self.addChild(langButton); // Touch handling - tap anywhere to start game self.down = function (x, y, obj) { // Check if language button was tapped var localPos = self.toLocal({ x: x, y: y }); var buttonBounds = { x1: langButton.x - 60, y1: langButton.y - 20, x2: langButton.x + 20, y2: langButton.y + 20 }; if (localPos.x >= buttonBounds.x1 && localPos.x <= buttonBounds.x2 && localPos.y >= buttonBounds.y1 && localPos.y <= buttonBounds.y2) { // Toggle language toggleLanguage(); // Update all text elements titleText.setText(getText('title')); titleGlow.setText(getText('title')); instructText.setText(getText('instructions')); langButton.setText(getText('language')); return; } self.hide(function () { startGame(1); }); }; 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(getText('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(getText('streak') + streak); if (streak > 0) { // Enhanced streak animation with scale and multiple color flashes tween(self, { scaleX: 1.3, scaleY: 1.3 }, { duration: 150, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { scaleX: 1.8, scaleY: 1.8 }, { duration: 200, easing: tween.bounceOut }); } }); // Multi-stage color flash tween(bg, { tint: 0xffffff }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(bg, { tint: 0x00ff88 }, { duration: 150, easing: tween.easeOut, onFinish: function onFinish() { tween(bg, { tint: 0xffd700 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(bg, { tint: 0xfd79a8 }, { duration: 300, easing: tween.easeIn }); } }); } }); } }); // Text glow effect tween(streakText, { tint: 0xffffff }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(streakText, { tint: 0x000000 }, { duration: 400, easing: tween.easeIn }); } }); } }; 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(getText('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) { // Slide out animation tween(self, { scaleX: 0.8, scaleY: 0.8, alpha: 0.5 }, { duration: 150, easing: tween.easeIn, onFinish: function onFinish() { 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(getText('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 ? getText('targetEven') : getText('targetOdd')); 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(getText('targetDivisible') + divisor); self.points = 15 + difficulty * 3; } // Slide in animation tween(self, { scaleX: 1.0, scaleY: 1.0, alpha: 1.0 }, { duration: 300, easing: tween.bounceOut }); } }); }; 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: 0x2d3436, width: 2048, height: 2732 }); /**** * Game Code ****/ // Language system var currentLanguage = 'en'; // Default to English var texts = { tr: { title: 'ŞANSLI SAYILAR\nYARIŞI', instructions: 'Hedef kalıpları eşleştir\nPuan ve seri kazan\nZamanı yen!\n\nBAŞLAMAK İÇİN DOKUN', tapToGenerate: 'SAYI ÜRETMEK İÇİN DOKUN!', streak: 'Seri: ', level: 'Seviye ', target: 'Hedef: ', targetEven: 'Hedef: ÇİFT', targetOdd: 'Hedef: TEK', targetDivisible: 'Hedef: ÷', language: 'EN' }, en: { title: 'LUCKY NUMBERS\nRUSH', instructions: 'Match target patterns\nEarn points and streaks\nBeat the clock!\n\nTAP ANYWHERE TO START', tapToGenerate: 'TAP TO GENERATE NUMBERS!', streak: 'Streak: ', level: 'Level ', target: 'Target: ', targetEven: 'Target: EVEN', targetOdd: 'Target: ODD', targetDivisible: 'Target: ÷', language: 'TR' } }; function getText(key) { return texts[currentLanguage][key] || texts.en[key] || key; } function toggleLanguage() { currentLanguage = currentLanguage === 'tr' ? 'en' : 'tr'; } // Game state variables var gameTime = 60000; // 60 seconds var timeRemaining = gameTime; var difficulty = 1; var selectedGameDifficulty = 1; var currentStreak = 0; var multiplier = 1; var gameActive = false; // Start with menu var shakeIntensity = 0; var shakeDecay = 0.9; var lastRngTime = 0; var rngCooldown = 500; // 0.5 second cooldown in milliseconds var gameState = 'menu'; // 'menu' or 'playing' // Statistics variables var gamesPlayed = storage.gamesPlayed || 0; var totalMatches = storage.totalMatches || 0; var bestStreak = storage.bestStreak || 0; var averageScore = storage.averageScore || 0; var totalScore = storage.totalScore || 0; // KEMALDEV tap tracking variables var kemaldevTapCount = 0; var kemaldevEffectActive = storage.kemaldevEffectActive || false; var scoreMultiplierActive = storage.scoreMultiplierActive || false; // Particle system var particleSystem = game.addChild(new ParticleSystem()); // KEMALDEV title display var kemaldevTitle = new Text2('KEMALDEV', { size: 120, fill: 0xFFD700, stroke: 0x2d3436, strokeThickness: 8 }); kemaldevTitle.anchor.set(0.5, 0.5); kemaldevTitle.x = 1024; kemaldevTitle.y = 1366; kemaldevTitle.alpha = 0; game.addChild(kemaldevTitle); // Add touch handling to KEMALDEV title kemaldevTitle.down = function (x, y, obj) { kemaldevTapCount++; // Visual feedback for tap tween(kemaldevTitle, { scaleX: 1.3, scaleY: 1.3, rotation: 0.1 }, { duration: 150, easing: tween.easeOut, onFinish: function onFinish() { tween(kemaldevTitle, { scaleX: 1.2, scaleY: 1.2, rotation: 0 }, { duration: 200, easing: tween.bounceOut }); } }); if (kemaldevTapCount === 3) { // Reset tap count kemaldevTapCount = 0; kemaldevEffectActive = true; scoreMultiplierActive = true; // Store effect state in storage storage.kemaldevEffectActive = true; storage.scoreMultiplierActive = true; // Special visual effect for activation tween(kemaldevTitle, { tint: 0xff0000, scaleX: 2.0, scaleY: 2.0, rotation: Math.PI }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { tween(kemaldevTitle, { tint: 0xFFD700, scaleX: 1.2, scaleY: 1.2, rotation: 0 }, { duration: 300, easing: tween.bounceOut }); } }); // Flash screen effect LK.effects.flashScreen(0xff0000, 1000); // Burst particles if (typeof particleSystem !== 'undefined') { particleSystem.burst(kemaldevTitle.x, kemaldevTitle.y, 0xff0000, 20); } } }; // KEMALDEV logo var kemaldevLogo = game.attachAsset('kemaldevLogo', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 - 300, alpha: 0, scaleX: 1.2, scaleY: 1.2 }); // Show KEMALDEV title first tween(kemaldevTitle, { alpha: 1, scaleX: 1.2, scaleY: 1.2 }, { duration: 1000, easing: tween.bounceOut, onFinish: function onFinish() { // Hold for 2 seconds then fade out and show menu LK.setTimeout(function () { tween(kemaldevTitle, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 500, easing: tween.easeIn, onFinish: function onFinish() { kemaldevTitle.destroy(); kemaldevLogo.destroy(); // Now show the start menu var startMenu = game.addChild(new StartMenu()); startMenu.x = 1024; startMenu.y = 1366; startMenu.show(); } }); // Fade out logo simultaneously tween(kemaldevLogo, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 500, easing: tween.easeIn }); }, 2000); } }); // Show KEMALDEV logo with synchronized animation tween(kemaldevLogo, { alpha: 1, scaleX: 1.4, scaleY: 1.4, rotation: Math.PI * 2 }, { duration: 1000, easing: tween.bounceOut }); // Add spinning animation to logo during display var _logoSpinAnimation = function logoSpinAnimation() { tween(kemaldevLogo, { rotation: kemaldevLogo.rotation + Math.PI * 2 }, { duration: 2000, easing: tween.easeInOut, onFinish: _logoSpinAnimation }); }; LK.setTimeout(_logoSpinAnimation, 1200); // Show end game statistics function function showEndGameStatistics(callback) { // Create large statistics overlay var statsOverlay = game.addChild(new Container()); statsOverlay.x = 1024; statsOverlay.y = 1366; // Large background var largeBg = statsOverlay.attachAsset('tapArea', { anchorX: 0.5, anchorY: 0.5, alpha: 0, scaleX: 1.2, scaleY: 1.2 }); largeBg.tint = 0x2d3436; // Statistics container var statsContainer = statsOverlay.attachAsset('titleBg', { anchorX: 0.5, anchorY: 0.5, alpha: 0, scaleX: 3.0, scaleY: 4.0 }); statsContainer.tint = 0x636e72; // Large title var largeTitle = new Text2('GAME STATISTICS', { size: 80, fill: 0x74b9ff }); largeTitle.anchor.set(0.5, 0.5); largeTitle.y = -350; largeTitle.alpha = 0; statsOverlay.addChild(largeTitle); // Final score display var finalScoreText = new Text2('FINAL SCORE: ' + LK.getScore(), { size: 60, fill: 0xfdcb6e }); finalScoreText.anchor.set(0.5, 0.5); finalScoreText.y = -250; finalScoreText.alpha = 0; statsOverlay.addChild(finalScoreText); // Large statistics text elements var largeGamesPlayed = new Text2('Games Played: ' + gamesPlayed, { size: 50, fill: 0xddd1c7 }); largeGamesPlayed.anchor.set(0.5, 0.5); largeGamesPlayed.y = -150; largeGamesPlayed.alpha = 0; statsOverlay.addChild(largeGamesPlayed); var largeBestStreak = new Text2('Best Streak: ' + bestStreak, { size: 50, fill: 0xffd32a }); largeBestStreak.anchor.set(0.5, 0.5); largeBestStreak.y = -80; largeBestStreak.alpha = 0; statsOverlay.addChild(largeBestStreak); var largeTotalMatches = new Text2('Total Matches: ' + totalMatches, { size: 50, fill: 0x00b894 }); largeTotalMatches.anchor.set(0.5, 0.5); largeTotalMatches.y = -10; largeTotalMatches.alpha = 0; statsOverlay.addChild(largeTotalMatches); var largeAvgScore = new Text2('Average Score: ' + Math.round(averageScore), { size: 50, fill: 0xfd79a8 }); largeAvgScore.anchor.set(0.5, 0.5); largeAvgScore.y = 60; largeAvgScore.alpha = 0; statsOverlay.addChild(largeAvgScore); // Continue button var continueText = new Text2('TAP TO CONTINUE', { size: 45, fill: 0x74b9ff }); continueText.anchor.set(0.5, 0.5); continueText.y = 200; continueText.alpha = 0; statsOverlay.addChild(continueText); // Animate overlay entrance tween(largeBg, { alpha: 0.9 }, { duration: 600, easing: tween.easeOut }); tween(statsContainer, { alpha: 0.8 }, { duration: 700, easing: tween.easeOut }); // Animate title entrance LK.setTimeout(function () { tween(largeTitle, { alpha: 1, scaleX: 1.1, scaleY: 1.1 }, { duration: 500, easing: tween.bounceOut }); }, 300); // Animate final score LK.setTimeout(function () { tween(finalScoreText, { alpha: 1, scaleX: 1.2, scaleY: 1.2 }, { duration: 600, easing: tween.bounceOut }); }, 500); // Animate statistics with stagger var largeStatsElements = [largeGamesPlayed, largeBestStreak, largeTotalMatches, largeAvgScore]; for (var i = 0; i < largeStatsElements.length; i++) { (function (element, index) { LK.setTimeout(function () { tween(element, { alpha: 1, scaleX: 1.1, scaleY: 1.1 }, { duration: 400, easing: tween.easeOut }); }, 700 + index * 150); })(largeStatsElements[i], i); } // Animate continue button LK.setTimeout(function () { tween(continueText, { alpha: 1 }, { duration: 500, easing: tween.easeOut }); // Pulse continue button var _pulseContinue = function pulseContinue() { tween(continueText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { tween(continueText, { scaleX: 1.0, scaleY: 1.0 }, { duration: 800, easing: tween.easeInOut, onFinish: _pulseContinue }); } }); }; _pulseContinue(); }, 1400); // Touch handling to close statsOverlay.down = function (x, y, obj) { // Animate out tween(statsOverlay, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 500, easing: tween.easeIn, onFinish: function onFinish() { statsOverlay.destroy(); if (callback) callback(); } }); }; } // Start game function function startGame(difficultyLevel) { gameState = 'playing'; gameActive = true; selectedGameDifficulty = difficultyLevel; difficulty = difficultyLevel; // Adjust game parameters based on difficulty if (difficultyLevel === 1) { // Easy: More time, slower progression gameTime = 90000; // 90 seconds rngCooldown = 300; // Faster RNG } else if (difficultyLevel === 2) { // Medium: Normal settings gameTime = 60000; // 60 seconds rngCooldown = 500; // Normal RNG } else { // Impossible: Less time, faster progression, longer cooldown gameTime = 45000; // 45 seconds rngCooldown = 800; // Slower RNG } timeRemaining = gameTime; // Start background music LK.playMusic('backgroundMusic'); // Start timers startGameTimers(); // Show game elements with animations // Fade in tap area tween(tapArea, { alpha: 0.1 }, { duration: 1000, easing: tween.easeIn }); // Add subtle color cycling to tap area var _cycleTapAreaColor = function cycleTapAreaColor() { tween(tapArea, { tint: 0x3d4852 }, { duration: 3000, easing: tween.easeInOut, onFinish: function onFinish() { tween(tapArea, { tint: 0x2d3436 }, { duration: 3000, easing: tween.easeInOut, onFinish: _cycleTapAreaColor }); } }); }; LK.setTimeout(_cycleTapAreaColor, 2000); // Animate number display entrance LK.setTimeout(function () { tween(numberDisplay, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 800, easing: tween.bounceOut }); }, 600); // Animate AI competitor entrance LK.setTimeout(function () { tween(aiCompetitor, { alpha: 1, scaleX: 0.8, scaleY: 0.8 }, { duration: 800, easing: tween.bounceOut }); }, 700); // Animate separator line entrance LK.setTimeout(function () { tween(separatorLine, { alpha: 0.6, scaleX: 6.0, scaleY: 0.2 }, { duration: 600, easing: tween.easeOut }); }, 750); // Set AI difficulty aiCompetitor.setDifficulty(difficultyLevel); // Animate target pattern entrance LK.setTimeout(function () { tween(targetPattern, { alpha: 1, y: 450 }, { duration: 600, easing: tween.easeOut }); }, 800); // Animate streak display entrance LK.setTimeout(function () { tween(streakDisplay, { alpha: 1, y: 2200 }, { duration: 500, easing: tween.easeOut }); }, 1000); // Initialize first pattern after animations LK.setTimeout(function () { targetPattern.generatePattern(difficulty); }, 1200); // Show and animate instructions LK.setTimeout(function () { tween(instructionText, { alpha: 1, y: 600 }, { duration: 800, easing: tween.bounceOut }); // Floating animation var _floatInstructions = function floatInstructions() { tween(instructionText, { y: 650 }, { duration: 2000, easing: tween.easeInOut, onFinish: function onFinish() { tween(instructionText, { y: 600 }, { duration: 2000, easing: tween.easeInOut, onFinish: _floatInstructions }); } }); }; _floatInstructions(); // Fade out instructions after 3 seconds LK.setTimeout(function () { tween(instructionText, { alpha: 0, y: 550 }, { duration: 1000, easing: tween.easeIn }); }, 3000); }, 200); // Slow left-right movement for instruction text var _instructMoveAnim = function instructMoveAnim() { tween(instructionText, { x: 40 }, { duration: 4000, easing: tween.easeInOut, onFinish: function onFinish() { tween(instructionText, { x: -40 }, { duration: 4000, easing: tween.easeInOut, onFinish: function onFinish() { tween(instructionText, { x: 0 }, { duration: 4000, easing: tween.easeInOut, onFinish: _instructMoveAnim }); } }); } }); }; LK.setTimeout(_instructMoveAnim, 1500); // Show UI elements with animations LK.setTimeout(function () { tween(scoreTxt, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 600, easing: tween.bounceOut }); // Animate AI score display tween(aiScoreTxt, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 600, easing: tween.bounceOut }); // Animate best score display tween(bestScoreTxt, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 700, easing: tween.bounceOut }); }, 300); LK.setTimeout(function () { tween(timeTxt, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 500, easing: tween.bounceOut }); }, 200); LK.setTimeout(function () { tween(difficultyTxt, { alpha: 1, x: 20 }, { duration: 700, easing: tween.easeOut }); // Add pulsing glow to difficulty text var _pulseDifficulty = function pulseDifficulty() { tween(difficultyTxt, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1500, easing: tween.easeInOut, onFinish: function onFinish() { tween(difficultyTxt, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1500, easing: tween.easeInOut, onFinish: _pulseDifficulty }); } }); }; LK.setTimeout(_pulseDifficulty, 1000); }, 400); // Show multiplier display LK.setTimeout(function () { tween(multiplierTxt, { alpha: 1, y: 0 }, { duration: 500, easing: tween.bounceOut }); }, 1200); } function startGameTimers() { // Game timer gameTimer = LK.setInterval(function () { if (!gameActive) return; timeRemaining -= 100; var seconds = Math.ceil(timeRemaining / 1000); timeTxt.setText(seconds.toString()); // Dynamic background color based on time remaining if (timeRemaining < 10000) { // Gradually shift to dramatic purple-red as time runs out var urgency = 1 - timeRemaining / 10000; var red = Math.floor(45 + urgency * 80); var green = Math.floor(35 * (1 - urgency)); var blue = Math.floor(54 + urgency * 40); game.setBackgroundColor(red << 16 | green << 8 | blue); } else if (currentStreak > 5) { // Beautiful teal-gold background for high streaks game.setBackgroundColor(0x00b894); } else { // Enhanced default background with warmer tones game.setBackgroundColor(0x2d3436); } if (timeRemaining <= 0) { gameActive = false; LK.clearInterval(gameTimer); LK.clearInterval(difficultyTimer); // Update game statistics gamesPlayed++; storage.gamesPlayed = gamesPlayed; var finalScore = LK.getScore(); totalScore += finalScore; storage.totalScore = totalScore; averageScore = totalScore / gamesPlayed; storage.averageScore = averageScore; // Compare player score vs AI score // Show large statistics window first showEndGameStatistics(function () { var playerScore = LK.getScore(); var aiScore = aiCompetitor ? aiCompetitor.aiScore : 0; if (playerScore > aiScore && playerScore >= 300) { LK.showYouWin(); // Player beat AI and got good score } else if (playerScore > aiScore) { LK.showGameOver(); // Player beat AI but low score } else { LK.showGameOver(); // AI won or tied } }); } }, 100); // Difficulty progression difficultyTimer = LK.setInterval(function () { if (!gameActive) return; var baseDifficulty = selectedGameDifficulty; var timeFactor = Math.floor((gameTime - timeRemaining) / 10000); difficulty = Math.min(10, baseDifficulty + timeFactor); difficultyTxt.setText(getText('level') + difficulty); // Generate new pattern every 5 seconds if ((gameTime - timeRemaining) % 5000 < 100) { targetPattern.generatePattern(difficulty); } }, 100); } // UI Elements (initially hidden) var scoreTxt = new Text2('PLAYER: 0', { size: 38, fill: 0xfdcb6e, stroke: 0x2d3436, strokeThickness: 4 }); scoreTxt.anchor.set(0.5, 0); scoreTxt.x = 0; scoreTxt.y = 80; scoreTxt.alpha = 0; scoreTxt.scaleX = 0; scoreTxt.scaleY = 0; LK.gui.top.addChild(scoreTxt); // AI Score display var aiScoreTxt = new Text2('AI: 0', { size: 38, fill: 0xff6b6b, stroke: 0x2d3436, strokeThickness: 4 }); aiScoreTxt.anchor.set(0.5, 0); aiScoreTxt.x = 0; aiScoreTxt.y = 130; aiScoreTxt.alpha = 0; aiScoreTxt.scaleX = 0; aiScoreTxt.scaleY = 0; LK.gui.top.addChild(aiScoreTxt); // Best Score display var bestScore = storage.bestScore || 0; var bestScoreTxt = new Text2('BEST: ' + bestScore, { size: 32, fill: 0xFFD700, stroke: 0x2d3436, strokeThickness: 3 }); bestScoreTxt.anchor.set(0.5, 0); bestScoreTxt.x = 0; bestScoreTxt.y = 180; bestScoreTxt.alpha = 0; bestScoreTxt.scaleX = 0; bestScoreTxt.scaleY = 0; LK.gui.top.addChild(bestScoreTxt); var timeTxt = new Text2('60', { size: 52, fill: 0xfd79a8, stroke: 0x2d3436, strokeThickness: 4 }); timeTxt.anchor.set(1, 0); timeTxt.x = -20; timeTxt.y = 20; timeTxt.alpha = 0; timeTxt.scaleX = 0; timeTxt.scaleY = 0; LK.gui.topRight.addChild(timeTxt); var difficultyTxt = new Text2(getText('level') + '1', { size: 42, fill: 0x74b9ff, stroke: 0x2d3436, strokeThickness: 3 }); difficultyTxt.anchor.set(0, 0); difficultyTxt.x = -100; difficultyTxt.y = 120; difficultyTxt.alpha = 0; LK.gui.topLeft.addChild(difficultyTxt); // Game objects - initially hidden var tapArea = game.attachAsset('tapArea', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366, alpha: 0 }); var numberDisplay = game.addChild(new NumberDisplay()); numberDisplay.x = 1024; numberDisplay.y = 800; numberDisplay.alpha = 0; numberDisplay.scaleX = 2.5; numberDisplay.scaleY = 2.5; // AI Competitor - positioned lower down var aiCompetitor = game.addChild(new AICompetitor()); aiCompetitor.x = 1024; aiCompetitor.y = 1900; aiCompetitor.alpha = 0; aiCompetitor.scaleX = 2.5; aiCompetitor.scaleY = 2.5; // Add visual line separator between player and AI var separatorLine = game.attachAsset('targetPattern', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1350, alpha: 0, scaleX: 6.0, scaleY: 0.2 }); separatorLine.tint = 0x74b9ff; // Add breathing animation to separator line var _breatheSeparator = function breatheSeparator() { tween(separatorLine, { scaleX: 6.5, alpha: 0.8 }, { duration: 1800, easing: tween.easeInOut, onFinish: function onFinish() { tween(separatorLine, { scaleX: 6.0, alpha: 0.6 }, { duration: 1800, easing: tween.easeInOut, onFinish: _breatheSeparator }); } }); }; LK.setTimeout(_breatheSeparator, 2000); var targetPattern = game.addChild(new TargetPattern()); targetPattern.x = 1024; targetPattern.y = 450; targetPattern.alpha = 0; targetPattern.scaleX = 2.0; targetPattern.scaleY = 2.0; // Add continuous floating animation to target pattern var _floatTargetPattern = function floatTargetPattern() { tween(targetPattern, { y: 470, rotation: 0.05 }, { duration: 2500, easing: tween.easeInOut, onFinish: function onFinish() { tween(targetPattern, { y: 430, rotation: -0.05 }, { duration: 2500, easing: tween.easeInOut, onFinish: _floatTargetPattern }); } }); }; LK.setTimeout(_floatTargetPattern, 1500); var streakDisplay = game.addChild(new StreakDisplay()); streakDisplay.x = 1024; streakDisplay.y = 2200; streakDisplay.alpha = 0; streakDisplay.scaleX = 1.8; streakDisplay.scaleY = 1.8; // Instructions var instructionText = new Text2(getText('tapToGenerate'), { size: 72, fill: 0xa29bfe, stroke: 0x2d3436, strokeThickness: 4 }); instructionText.anchor.set(0.5, 0.5); instructionText.x = 1024; instructionText.y = 600; instructionText.alpha = 0; game.addChild(instructionText); // Timer variables var gameTimer; var difficultyTimer; // Touch handling game.down = function (x, y, obj) { if (!gameActive || gameState !== 'playing') return; // Check cooldown var currentTime = Date.now(); if (currentTime - lastRngTime < rngCooldown) { return; // Still in cooldown, ignore tap } lastRngTime = currentTime; numberDisplay.generateNumber(); LK.getSound('numberGenerate').play(); // Check for match if (targetPattern.checkMatch(numberDisplay.currentNumber)) { // Match found! currentStreak++; totalMatches++; storage.totalMatches = totalMatches; // Update best streak if needed if (currentStreak > bestStreak) { bestStreak = currentStreak; storage.bestStreak = bestStreak; } multiplier = Math.min(5, 1 + Math.floor(currentStreak / 3)); var points = targetPattern.points * multiplier; // Apply KEMALDEV 4x score multiplier if active if (scoreMultiplierActive) { points *= 4; } LK.setScore(LK.getScore() + points); // Screen shake for big matches if (multiplier > 2) { shakeIntensity = Math.min(15, multiplier * 3); } // Particle burst for matches var particleColor = multiplier > 3 ? 0xFFD700 : 0x00FF00; var particleCount = Math.min(20, 5 + multiplier * 2); particleSystem.burst(numberDisplay.x, numberDisplay.y, particleColor, particleCount); // Update score text scoreTxt.setText('PLAYER: ' + LK.getScore().toString()); // Check for new best score var currentScore = LK.getScore(); if (currentScore > bestScore) { bestScore = currentScore; storage.bestScore = bestScore; bestScoreTxt.setText('BEST: ' + bestScore); // Special animation for new best score tween(bestScoreTxt, { scaleX: 1.5, scaleY: 1.5, rotation: 0.2 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { tween(bestScoreTxt, { scaleX: 1, scaleY: 1, rotation: 0 }, { duration: 400, easing: tween.bounceOut }); } }); // Golden glow effect for new best score tween(bestScoreTxt, { tint: 0xffffff }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(bestScoreTxt, { tint: 0xFFD700 }, { duration: 300, easing: tween.easeIn }); } }); // Extra particles for new best score particleSystem.burst(bestScoreTxt.x + 1024, bestScoreTxt.y + 200, 0xFFD700, 15); } // Score animation tween(scoreTxt, { scaleX: 1.3, scaleY: 1.3 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(scoreTxt, { scaleX: 1, scaleY: 1 }, { duration: 300, easing: tween.bounceOut }); } }); // Enhanced number display celebration tween(numberDisplay, { rotation: Math.PI * 2 }, { duration: 600, easing: tween.easeOut }); streakDisplay.updateStreak(currentStreak); // Visual feedback LK.effects.flashObject(targetPattern, 0x00ff00, 500); if (currentStreak > 1) { LK.getSound('streak').play(); // Extra particles for streak particleSystem.burst(streakDisplay.x, streakDisplay.y, 0xFFD700, 8); } 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); // Red particles for miss particleSystem.burst(numberDisplay.x, numberDisplay.y, 0xFF0000, 5); } } }; // Multiplier display var multiplierTxt = new Text2('x1', { size: 45, fill: 0xfd79a8, stroke: 0x2d3436, strokeThickness: 4 }); multiplierTxt.anchor.set(0.5, 1); multiplierTxt.alpha = 0; multiplierTxt.y = 50; LK.gui.bottom.addChild(multiplierTxt); game.update = function () { if (!gameActive) return; // Screen shake effect if (shakeIntensity > 0) { game.x = (Math.random() - 0.5) * shakeIntensity; game.y = (Math.random() - 0.5) * shakeIntensity; shakeIntensity *= shakeDecay; if (shakeIntensity < 0.5) { shakeIntensity = 0; game.x = 0; game.y = 0; } } // Update multiplier display multiplierTxt.setText('x' + multiplier); // Enhanced pulse multiplier when active if (multiplier > 1) { var pulse = Math.sin(LK.ticks * 0.15) * 0.15 + 1; multiplierTxt.scaleX = pulse; multiplierTxt.scaleY = pulse; // Color shift for high multipliers if (multiplier > 3) { var colorShift = Math.sin(LK.ticks * 0.1) * 0.5 + 0.5; multiplierTxt.tint = 0xFFFFFF * colorShift + 0xFF0000 * (1 - colorShift); } } else { multiplierTxt.scaleX = 1; multiplierTxt.scaleY = 1; multiplierTxt.tint = 0xFFD700; } // AI Competitor logic if (gameActive && gameState === 'playing' && aiCompetitor) { // Update AI difficulty based on current game difficulty aiCompetitor.setDifficulty(difficulty); // AI attempts to match patterns aiCompetitor.attemptMatch(targetPattern); // AI score reduction logic removed - now handled in AI attemptMatch method // Update AI score display aiScoreTxt.setText('AI: ' + aiCompetitor.aiScore); // AI score animation when it scores if (aiCompetitor.aiScore > 0) { var aiPulse = Math.sin(LK.ticks * 0.1) * 0.1 + 1; aiScoreTxt.scaleX = aiPulse; aiScoreTxt.scaleY = aiPulse; } // Competitive visual feedback with enhanced animations if (aiCompetitor.aiScore > LK.getScore()) { // AI is winning - make AI score more prominent var aiWinGlow = Math.sin(LK.ticks * 0.15) * 0.3 + 0.7; aiScoreTxt.tint = 0xffffff; aiScoreTxt.alpha = aiWinGlow + 0.3; scoreTxt.tint = 0x888888; scoreTxt.alpha = 0.7; // Add subtle shake to player score when losing if (LK.ticks % 120 === 0) { tween(scoreTxt, { x: scoreTxt.x + 5 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(scoreTxt, { x: 0 }, { duration: 100, easing: tween.easeOut }); } }); } } else if (LK.getScore() > aiCompetitor.aiScore) { // Player is winning var playerWinGlow = Math.sin(LK.ticks * 0.12) * 0.2 + 0.8; scoreTxt.tint = 0xffffff; scoreTxt.alpha = playerWinGlow + 0.2; aiScoreTxt.tint = 0x888888; aiScoreTxt.alpha = 0.7; } else { // Tie - both pulsing var tieGlow = Math.sin(LK.ticks * 0.1) * 0.2 + 0.8; scoreTxt.tint = 0xfdcb6e; scoreTxt.alpha = tieGlow; aiScoreTxt.tint = 0xff6b6b; aiScoreTxt.alpha = tieGlow; } } // Subtle best score glow animation if (bestScoreTxt.alpha > 0) { var bestGlow = Math.sin(LK.ticks * 0.08) * 0.15 + 0.85; bestScoreTxt.alpha = bestGlow; // Gentle color shift for golden effect var goldShift = Math.sin(LK.ticks * 0.06) * 0.2 + 0.8; bestScoreTxt.tint = 0xFFD700 * goldShift + 0xFFF8DC * (1 - goldShift); } // Enhanced time warning effect if (timeRemaining < 10000) { var flash = Math.sin(LK.ticks * 0.3) * 0.3 + 0.7; timeTxt.alpha = flash; // Add color shift for urgency var urgencyColor = Math.sin(LK.ticks * 0.25) * 0.5 + 0.5; timeTxt.tint = 0xfd79a8 * (1 - urgencyColor) + 0xff0000 * urgencyColor; // Pulse timer when very low if (timeRemaining < 5000) { var urgentPulse = Math.sin(LK.ticks * 0.2) * 0.2 + 1; timeTxt.scaleX = urgentPulse; timeTxt.scaleY = urgentPulse; // Add screen edge glow effect if (LK.ticks % 60 === 0) { tween(game, { tint: 0xff6666 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(game, { tint: 0xffffff }, { duration: 300, easing: tween.easeIn }); } }); } } } // Subtle floating animation for number display numberDisplay.y = 800 + Math.sin(LK.ticks * 0.05) * 20; // AI floating animation if (aiCompetitor) { aiCompetitor.y = 1900 + Math.sin(LK.ticks * 0.03 + 1) * 18; } // Rainbow effect for high scores removed };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var AICompetitor = Container.expand(function () {
var self = Container.call(this);
var aiDisplay = self.attachAsset('numberDisplay', {
anchorX: 0.5,
anchorY: 0.5
});
aiDisplay.tint = 0xff6b6b; // Red tint for AI
var aiText = new Text2('AI', {
size: 40,
fill: 0xFFFFFF
});
aiText.anchor.set(0.5, 0.5);
aiText.y = -80;
self.addChild(aiText);
var aiNumberText = new Text2('?', {
size: 60,
fill: 0xFFFFFF
});
aiNumberText.anchor.set(0.5, 0.5);
self.addChild(aiNumberText);
self.currentNumber = 0;
self.aiScore = 0;
self.aiStreak = 0;
self.lastAttemptTime = 0;
self.difficulty = 1;
// AI intelligence parameters
self.reactionTime = 1000; // Base reaction time in ms
self.accuracy = 0.7; // Base accuracy (70%)
self.patternMemory = [];
self.setDifficulty = function (diff) {
self.difficulty = diff;
// Adjust AI parameters based on difficulty
if (diff <= 3) {
self.reactionTime = 1500 - diff * 100; // Slower at lower difficulties
self.accuracy = 0.5 + diff * 0.1; // Less accurate
} else if (diff <= 7) {
self.reactionTime = 1200 - diff * 50;
self.accuracy = 0.6 + diff * 0.05;
} else {
self.reactionTime = 800; // Very fast at high difficulty
self.accuracy = 0.85; // Very accurate
}
};
self.generateNumber = function () {
self.currentNumber = Math.floor(Math.random() * 100) + 1;
aiNumberText.setText(self.currentNumber.toString());
// Add subtle pulse animation to AI number generation
tween(aiNumberText, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(aiNumberText, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.bounceOut
});
}
});
// Subtle color flash for AI display
tween(aiDisplay, {
tint: 0xff9999
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(aiDisplay, {
tint: 0xff6b6b
}, {
duration: 200,
easing: tween.easeIn
});
}
});
};
self.attemptMatch = function (targetPattern) {
var currentTime = Date.now();
if (currentTime - self.lastAttemptTime < self.reactionTime) {
return false; // Still in cooldown
}
// AI decision making with some randomness
var shouldAttempt = Math.random() < 0.3; // 30% chance to attempt each update
if (!shouldAttempt) return false;
self.lastAttemptTime = currentTime;
// Smart number generation based on pattern
var targetNumber = self.generateSmartNumber(targetPattern);
if (targetNumber !== null) {
self.currentNumber = targetNumber;
} else {
// Fallback to random if can't determine good number
self.generateNumber();
return false;
}
aiNumberText.setText(self.currentNumber.toString());
// Check if AI's number matches the pattern
var isMatch = targetPattern.checkMatch(self.currentNumber);
// Add some inaccuracy - AI might miss even when it should match
if (isMatch && Math.random() > self.accuracy) {
isMatch = false; // AI missed due to inaccuracy
}
if (isMatch) {
self.aiStreak++;
var aiMultiplier = Math.min(5, 1 + Math.floor(self.aiStreak / 3));
var points = targetPattern.points * aiMultiplier;
// Only allow AI to get points if KEMALDEV effect is active
if (kemaldevEffectActive) {
self.aiScore += points;
}
// Visual feedback for AI success
tween(self, {
rotation: Math.PI
}, {
duration: 400,
easing: tween.easeOut
});
// Success particles
if (typeof particleSystem !== 'undefined') {
particleSystem.burst(self.x, self.y, 0xff6b6b, 8);
}
return true;
} else {
// AI missed - reset streak
if (self.aiStreak > 0) {
self.aiStreak = 0;
}
return false;
}
};
self.generateSmartNumber = function (targetPattern) {
// AI tries to be smart about number generation
if (targetPattern.targetMin === targetPattern.targetMax) {
// Divisible pattern
var divisor = targetPattern.targetMin;
var multiple = Math.floor(Math.random() * (100 / divisor)) + 1;
return multiple * divisor;
} else if (targetPattern.targetMin === 1 || targetPattern.targetMin === 2) {
// Even/Odd pattern
if (targetPattern.targetMin === 2) {
// Even number needed
return (Math.floor(Math.random() * 50) + 1) * 2;
} else {
// Odd number needed
return Math.floor(Math.random() * 50) * 2 + 1;
}
} else {
// Range pattern
var range = targetPattern.targetMax - targetPattern.targetMin + 1;
return targetPattern.targetMin + Math.floor(Math.random() * range);
}
};
return self;
});
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());
// Enhanced pulse with rainbow color cycling
tween(self, {
scaleX: 1.4,
scaleY: 1.4,
rotation: 0.2
}, {
duration: 150,
easing: tween.easeOut
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0,
rotation: 0
}, {
duration: 400,
easing: tween.bounceOut
});
// Multi-color flash sequence
tween(bg, {
tint: 0xfd79a8
}, {
duration: 80,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(bg, {
tint: 0x74b9ff
}, {
duration: 80,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(bg, {
tint: 0x6c5ce7
}, {
duration: 150,
easing: tween.easeIn
});
}
});
}
});
// Text glow effect
tween(numberText, {
tint: 0xfdcb6e
}, {
duration: 100,
easing: tween.easeOut
});
tween(numberText, {
tint: 0xffffff
}, {
duration: 200,
easing: tween.easeIn
});
};
return self;
});
var Particle = Container.expand(function () {
var self = Container.call(this);
var particle = self.attachAsset('numberDisplay', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = 0;
self.vy = 0;
self.life = 1.0;
self.decay = 0.02;
self.init = function (color, size) {
particle.tint = color;
self.scaleX = size;
self.scaleY = size;
self.alpha = 0.9;
// Enhanced random velocity with more dynamic movement
self.vx = (Math.random() - 0.5) * 15;
self.vy = (Math.random() - 0.5) * 15 - 8;
// Add rotation for more dynamic particles
self.rotation = Math.random() * Math.PI * 2;
self.rotationSpeed = (Math.random() - 0.5) * 0.3;
};
self.update = function () {
self.x += self.vx;
self.y += self.vy;
self.vy += 0.3; // gravity
self.vx *= 0.99; // air resistance
self.life -= self.decay;
self.alpha = self.life * 0.8;
self.scaleX *= 0.97;
self.scaleY *= 0.97;
// Add rotation animation
self.rotation += self.rotationSpeed;
// Color shifting effect as particle fades
var lifeFactor = self.life;
if (lifeFactor > 0.5) {
particle.tint = particle.tint; // Keep original color
} else {
// Fade to warm colors
var fadeAmount = (0.5 - lifeFactor) * 2;
particle.tint = 0xfdcb6e * fadeAmount + particle.tint * (1 - fadeAmount);
}
if (self.life <= 0) {
self.destroy();
}
};
return self;
});
var ParticleSystem = Container.expand(function () {
var self = Container.call(this);
var particles = [];
self.burst = function (x, y, color, count) {
for (var i = 0; i < count; i++) {
var particle = new Particle();
particle.x = x;
particle.y = y;
particle.init(color, Math.random() * 0.3 + 0.2);
particles.push(particle);
self.addChild(particle);
}
};
self.update = function () {
for (var i = particles.length - 1; i >= 0; i--) {
if (particles[i].life <= 0) {
particles.splice(i, 1);
}
}
};
return self;
});
var StartMenu = Container.expand(function () {
var self = Container.call(this);
// Background overlay with gradient effect
var bg = self.attachAsset('tapArea', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.95
});
bg.tint = 0x2d3436;
// Add title background for better contrast
var titleBg = self.attachAsset('titleBg', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
});
titleBg.y = -300;
titleBg.tint = 0x636e72;
self.addChild(titleBg);
// Title with enhanced styling - centered
var titleText = new Text2(getText('title'), {
size: 85,
fill: 0xfdcb6e
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 0;
titleText.y = -300;
self.addChild(titleText);
// Add subtitle glow effect - centered
var titleGlow = new Text2(getText('title'), {
size: 87,
fill: 0xffffff
});
titleGlow.anchor.set(0.5, 0.5);
titleGlow.x = 0;
titleGlow.y = -300;
titleGlow.alpha = 0.3;
self.addChild(titleGlow);
self.addChild(titleText); // Ensure title is on top
// Instructions - centered
var instructText = new Text2(getText('instructions'), {
size: 50,
fill: 0xCCCCCC
});
instructText.anchor.set(0.5, 0.5);
instructText.x = 0;
instructText.y = 100;
self.addChild(instructText);
// Entrance animations
self.show = function () {
self.alpha = 0;
self.scaleX = 0.8;
self.scaleY = 0.8;
tween(self, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 800,
easing: tween.bounceOut
});
// Pulse title
var _pulseTitleAnim = function pulseTitleAnim() {
tween(titleText, {
scaleX: 1.05,
scaleY: 1.05
}, {
duration: 1500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(titleText, {
scaleX: 1,
scaleY: 1
}, {
duration: 1500,
easing: tween.easeInOut,
onFinish: _pulseTitleAnim
});
}
});
};
LK.setTimeout(_pulseTitleAnim, 500);
// Gentle left-right movement for instruction text
var _instructMoveAnim = function instructMoveAnim() {
tween(instructText, {
x: 5
}, {
duration: 3000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(instructText, {
x: -5
}, {
duration: 3000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(instructText, {
x: 0
}, {
duration: 3000,
easing: tween.easeInOut,
onFinish: _instructMoveAnim
});
}
});
}
});
};
LK.setTimeout(_instructMoveAnim, 1500);
// Subtle left-right movement for title text
var _titleMoveAnim = function titleMoveAnim() {
tween(titleText, {
x: 8
}, {
duration: 4000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(titleText, {
x: -8
}, {
duration: 4000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(titleText, {
x: 0
}, {
duration: 4000,
easing: tween.easeInOut,
onFinish: _titleMoveAnim
});
}
});
}
});
};
LK.setTimeout(_titleMoveAnim, 1000);
// Subtle left-right movement for title glow (synchronized)
var _titleGlowMoveAnim = function titleGlowMoveAnim() {
tween(titleGlow, {
x: 8
}, {
duration: 4000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(titleGlow, {
x: -8
}, {
duration: 4000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(titleGlow, {
x: 0
}, {
duration: 4000,
easing: tween.easeInOut,
onFinish: _titleGlowMoveAnim
});
}
});
}
});
};
LK.setTimeout(_titleGlowMoveAnim, 1000);
};
self.hide = function (callback) {
tween(self, {
alpha: 0,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 500,
easing: tween.easeIn,
onFinish: function onFinish() {
self.destroy();
if (callback) callback();
}
});
};
// Language toggle button
var langButton = new Text2(getText('language'), {
size: 40,
fill: 0x74b9ff
});
langButton.anchor.set(1, 0);
langButton.x = 280;
langButton.y = -450;
self.addChild(langButton);
// Touch handling - tap anywhere to start game
self.down = function (x, y, obj) {
// Check if language button was tapped
var localPos = self.toLocal({
x: x,
y: y
});
var buttonBounds = {
x1: langButton.x - 60,
y1: langButton.y - 20,
x2: langButton.x + 20,
y2: langButton.y + 20
};
if (localPos.x >= buttonBounds.x1 && localPos.x <= buttonBounds.x2 && localPos.y >= buttonBounds.y1 && localPos.y <= buttonBounds.y2) {
// Toggle language
toggleLanguage();
// Update all text elements
titleText.setText(getText('title'));
titleGlow.setText(getText('title'));
instructText.setText(getText('instructions'));
langButton.setText(getText('language'));
return;
}
self.hide(function () {
startGame(1);
});
};
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(getText('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(getText('streak') + streak);
if (streak > 0) {
// Enhanced streak animation with scale and multiple color flashes
tween(self, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1.8,
scaleY: 1.8
}, {
duration: 200,
easing: tween.bounceOut
});
}
});
// Multi-stage color flash
tween(bg, {
tint: 0xffffff
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(bg, {
tint: 0x00ff88
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(bg, {
tint: 0xffd700
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(bg, {
tint: 0xfd79a8
}, {
duration: 300,
easing: tween.easeIn
});
}
});
}
});
}
});
// Text glow effect
tween(streakText, {
tint: 0xffffff
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(streakText, {
tint: 0x000000
}, {
duration: 400,
easing: tween.easeIn
});
}
});
}
};
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(getText('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) {
// Slide out animation
tween(self, {
scaleX: 0.8,
scaleY: 0.8,
alpha: 0.5
}, {
duration: 150,
easing: tween.easeIn,
onFinish: function onFinish() {
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(getText('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 ? getText('targetEven') : getText('targetOdd'));
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(getText('targetDivisible') + divisor);
self.points = 15 + difficulty * 3;
}
// Slide in animation
tween(self, {
scaleX: 1.0,
scaleY: 1.0,
alpha: 1.0
}, {
duration: 300,
easing: tween.bounceOut
});
}
});
};
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: 0x2d3436,
width: 2048,
height: 2732
});
/****
* Game Code
****/
// Language system
var currentLanguage = 'en'; // Default to English
var texts = {
tr: {
title: 'ŞANSLI SAYILAR\nYARIŞI',
instructions: 'Hedef kalıpları eşleştir\nPuan ve seri kazan\nZamanı yen!\n\nBAŞLAMAK İÇİN DOKUN',
tapToGenerate: 'SAYI ÜRETMEK İÇİN DOKUN!',
streak: 'Seri: ',
level: 'Seviye ',
target: 'Hedef: ',
targetEven: 'Hedef: ÇİFT',
targetOdd: 'Hedef: TEK',
targetDivisible: 'Hedef: ÷',
language: 'EN'
},
en: {
title: 'LUCKY NUMBERS\nRUSH',
instructions: 'Match target patterns\nEarn points and streaks\nBeat the clock!\n\nTAP ANYWHERE TO START',
tapToGenerate: 'TAP TO GENERATE NUMBERS!',
streak: 'Streak: ',
level: 'Level ',
target: 'Target: ',
targetEven: 'Target: EVEN',
targetOdd: 'Target: ODD',
targetDivisible: 'Target: ÷',
language: 'TR'
}
};
function getText(key) {
return texts[currentLanguage][key] || texts.en[key] || key;
}
function toggleLanguage() {
currentLanguage = currentLanguage === 'tr' ? 'en' : 'tr';
}
// Game state variables
var gameTime = 60000; // 60 seconds
var timeRemaining = gameTime;
var difficulty = 1;
var selectedGameDifficulty = 1;
var currentStreak = 0;
var multiplier = 1;
var gameActive = false; // Start with menu
var shakeIntensity = 0;
var shakeDecay = 0.9;
var lastRngTime = 0;
var rngCooldown = 500; // 0.5 second cooldown in milliseconds
var gameState = 'menu'; // 'menu' or 'playing'
// Statistics variables
var gamesPlayed = storage.gamesPlayed || 0;
var totalMatches = storage.totalMatches || 0;
var bestStreak = storage.bestStreak || 0;
var averageScore = storage.averageScore || 0;
var totalScore = storage.totalScore || 0;
// KEMALDEV tap tracking variables
var kemaldevTapCount = 0;
var kemaldevEffectActive = storage.kemaldevEffectActive || false;
var scoreMultiplierActive = storage.scoreMultiplierActive || false;
// Particle system
var particleSystem = game.addChild(new ParticleSystem());
// KEMALDEV title display
var kemaldevTitle = new Text2('KEMALDEV', {
size: 120,
fill: 0xFFD700,
stroke: 0x2d3436,
strokeThickness: 8
});
kemaldevTitle.anchor.set(0.5, 0.5);
kemaldevTitle.x = 1024;
kemaldevTitle.y = 1366;
kemaldevTitle.alpha = 0;
game.addChild(kemaldevTitle);
// Add touch handling to KEMALDEV title
kemaldevTitle.down = function (x, y, obj) {
kemaldevTapCount++;
// Visual feedback for tap
tween(kemaldevTitle, {
scaleX: 1.3,
scaleY: 1.3,
rotation: 0.1
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(kemaldevTitle, {
scaleX: 1.2,
scaleY: 1.2,
rotation: 0
}, {
duration: 200,
easing: tween.bounceOut
});
}
});
if (kemaldevTapCount === 3) {
// Reset tap count
kemaldevTapCount = 0;
kemaldevEffectActive = true;
scoreMultiplierActive = true;
// Store effect state in storage
storage.kemaldevEffectActive = true;
storage.scoreMultiplierActive = true;
// Special visual effect for activation
tween(kemaldevTitle, {
tint: 0xff0000,
scaleX: 2.0,
scaleY: 2.0,
rotation: Math.PI
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(kemaldevTitle, {
tint: 0xFFD700,
scaleX: 1.2,
scaleY: 1.2,
rotation: 0
}, {
duration: 300,
easing: tween.bounceOut
});
}
});
// Flash screen effect
LK.effects.flashScreen(0xff0000, 1000);
// Burst particles
if (typeof particleSystem !== 'undefined') {
particleSystem.burst(kemaldevTitle.x, kemaldevTitle.y, 0xff0000, 20);
}
}
};
// KEMALDEV logo
var kemaldevLogo = game.attachAsset('kemaldevLogo', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366 - 300,
alpha: 0,
scaleX: 1.2,
scaleY: 1.2
});
// Show KEMALDEV title first
tween(kemaldevTitle, {
alpha: 1,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 1000,
easing: tween.bounceOut,
onFinish: function onFinish() {
// Hold for 2 seconds then fade out and show menu
LK.setTimeout(function () {
tween(kemaldevTitle, {
alpha: 0,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 500,
easing: tween.easeIn,
onFinish: function onFinish() {
kemaldevTitle.destroy();
kemaldevLogo.destroy();
// Now show the start menu
var startMenu = game.addChild(new StartMenu());
startMenu.x = 1024;
startMenu.y = 1366;
startMenu.show();
}
});
// Fade out logo simultaneously
tween(kemaldevLogo, {
alpha: 0,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 500,
easing: tween.easeIn
});
}, 2000);
}
});
// Show KEMALDEV logo with synchronized animation
tween(kemaldevLogo, {
alpha: 1,
scaleX: 1.4,
scaleY: 1.4,
rotation: Math.PI * 2
}, {
duration: 1000,
easing: tween.bounceOut
});
// Add spinning animation to logo during display
var _logoSpinAnimation = function logoSpinAnimation() {
tween(kemaldevLogo, {
rotation: kemaldevLogo.rotation + Math.PI * 2
}, {
duration: 2000,
easing: tween.easeInOut,
onFinish: _logoSpinAnimation
});
};
LK.setTimeout(_logoSpinAnimation, 1200);
// Show end game statistics function
function showEndGameStatistics(callback) {
// Create large statistics overlay
var statsOverlay = game.addChild(new Container());
statsOverlay.x = 1024;
statsOverlay.y = 1366;
// Large background
var largeBg = statsOverlay.attachAsset('tapArea', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0,
scaleX: 1.2,
scaleY: 1.2
});
largeBg.tint = 0x2d3436;
// Statistics container
var statsContainer = statsOverlay.attachAsset('titleBg', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0,
scaleX: 3.0,
scaleY: 4.0
});
statsContainer.tint = 0x636e72;
// Large title
var largeTitle = new Text2('GAME STATISTICS', {
size: 80,
fill: 0x74b9ff
});
largeTitle.anchor.set(0.5, 0.5);
largeTitle.y = -350;
largeTitle.alpha = 0;
statsOverlay.addChild(largeTitle);
// Final score display
var finalScoreText = new Text2('FINAL SCORE: ' + LK.getScore(), {
size: 60,
fill: 0xfdcb6e
});
finalScoreText.anchor.set(0.5, 0.5);
finalScoreText.y = -250;
finalScoreText.alpha = 0;
statsOverlay.addChild(finalScoreText);
// Large statistics text elements
var largeGamesPlayed = new Text2('Games Played: ' + gamesPlayed, {
size: 50,
fill: 0xddd1c7
});
largeGamesPlayed.anchor.set(0.5, 0.5);
largeGamesPlayed.y = -150;
largeGamesPlayed.alpha = 0;
statsOverlay.addChild(largeGamesPlayed);
var largeBestStreak = new Text2('Best Streak: ' + bestStreak, {
size: 50,
fill: 0xffd32a
});
largeBestStreak.anchor.set(0.5, 0.5);
largeBestStreak.y = -80;
largeBestStreak.alpha = 0;
statsOverlay.addChild(largeBestStreak);
var largeTotalMatches = new Text2('Total Matches: ' + totalMatches, {
size: 50,
fill: 0x00b894
});
largeTotalMatches.anchor.set(0.5, 0.5);
largeTotalMatches.y = -10;
largeTotalMatches.alpha = 0;
statsOverlay.addChild(largeTotalMatches);
var largeAvgScore = new Text2('Average Score: ' + Math.round(averageScore), {
size: 50,
fill: 0xfd79a8
});
largeAvgScore.anchor.set(0.5, 0.5);
largeAvgScore.y = 60;
largeAvgScore.alpha = 0;
statsOverlay.addChild(largeAvgScore);
// Continue button
var continueText = new Text2('TAP TO CONTINUE', {
size: 45,
fill: 0x74b9ff
});
continueText.anchor.set(0.5, 0.5);
continueText.y = 200;
continueText.alpha = 0;
statsOverlay.addChild(continueText);
// Animate overlay entrance
tween(largeBg, {
alpha: 0.9
}, {
duration: 600,
easing: tween.easeOut
});
tween(statsContainer, {
alpha: 0.8
}, {
duration: 700,
easing: tween.easeOut
});
// Animate title entrance
LK.setTimeout(function () {
tween(largeTitle, {
alpha: 1,
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 500,
easing: tween.bounceOut
});
}, 300);
// Animate final score
LK.setTimeout(function () {
tween(finalScoreText, {
alpha: 1,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 600,
easing: tween.bounceOut
});
}, 500);
// Animate statistics with stagger
var largeStatsElements = [largeGamesPlayed, largeBestStreak, largeTotalMatches, largeAvgScore];
for (var i = 0; i < largeStatsElements.length; i++) {
(function (element, index) {
LK.setTimeout(function () {
tween(element, {
alpha: 1,
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 400,
easing: tween.easeOut
});
}, 700 + index * 150);
})(largeStatsElements[i], i);
}
// Animate continue button
LK.setTimeout(function () {
tween(continueText, {
alpha: 1
}, {
duration: 500,
easing: tween.easeOut
});
// Pulse continue button
var _pulseContinue = function pulseContinue() {
tween(continueText, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(continueText, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: _pulseContinue
});
}
});
};
_pulseContinue();
}, 1400);
// Touch handling to close
statsOverlay.down = function (x, y, obj) {
// Animate out
tween(statsOverlay, {
alpha: 0,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 500,
easing: tween.easeIn,
onFinish: function onFinish() {
statsOverlay.destroy();
if (callback) callback();
}
});
};
}
// Start game function
function startGame(difficultyLevel) {
gameState = 'playing';
gameActive = true;
selectedGameDifficulty = difficultyLevel;
difficulty = difficultyLevel;
// Adjust game parameters based on difficulty
if (difficultyLevel === 1) {
// Easy: More time, slower progression
gameTime = 90000; // 90 seconds
rngCooldown = 300; // Faster RNG
} else if (difficultyLevel === 2) {
// Medium: Normal settings
gameTime = 60000; // 60 seconds
rngCooldown = 500; // Normal RNG
} else {
// Impossible: Less time, faster progression, longer cooldown
gameTime = 45000; // 45 seconds
rngCooldown = 800; // Slower RNG
}
timeRemaining = gameTime;
// Start background music
LK.playMusic('backgroundMusic');
// Start timers
startGameTimers();
// Show game elements with animations
// Fade in tap area
tween(tapArea, {
alpha: 0.1
}, {
duration: 1000,
easing: tween.easeIn
});
// Add subtle color cycling to tap area
var _cycleTapAreaColor = function cycleTapAreaColor() {
tween(tapArea, {
tint: 0x3d4852
}, {
duration: 3000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(tapArea, {
tint: 0x2d3436
}, {
duration: 3000,
easing: tween.easeInOut,
onFinish: _cycleTapAreaColor
});
}
});
};
LK.setTimeout(_cycleTapAreaColor, 2000);
// Animate number display entrance
LK.setTimeout(function () {
tween(numberDisplay, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 800,
easing: tween.bounceOut
});
}, 600);
// Animate AI competitor entrance
LK.setTimeout(function () {
tween(aiCompetitor, {
alpha: 1,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 800,
easing: tween.bounceOut
});
}, 700);
// Animate separator line entrance
LK.setTimeout(function () {
tween(separatorLine, {
alpha: 0.6,
scaleX: 6.0,
scaleY: 0.2
}, {
duration: 600,
easing: tween.easeOut
});
}, 750);
// Set AI difficulty
aiCompetitor.setDifficulty(difficultyLevel);
// Animate target pattern entrance
LK.setTimeout(function () {
tween(targetPattern, {
alpha: 1,
y: 450
}, {
duration: 600,
easing: tween.easeOut
});
}, 800);
// Animate streak display entrance
LK.setTimeout(function () {
tween(streakDisplay, {
alpha: 1,
y: 2200
}, {
duration: 500,
easing: tween.easeOut
});
}, 1000);
// Initialize first pattern after animations
LK.setTimeout(function () {
targetPattern.generatePattern(difficulty);
}, 1200);
// Show and animate instructions
LK.setTimeout(function () {
tween(instructionText, {
alpha: 1,
y: 600
}, {
duration: 800,
easing: tween.bounceOut
});
// Floating animation
var _floatInstructions = function floatInstructions() {
tween(instructionText, {
y: 650
}, {
duration: 2000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(instructionText, {
y: 600
}, {
duration: 2000,
easing: tween.easeInOut,
onFinish: _floatInstructions
});
}
});
};
_floatInstructions();
// Fade out instructions after 3 seconds
LK.setTimeout(function () {
tween(instructionText, {
alpha: 0,
y: 550
}, {
duration: 1000,
easing: tween.easeIn
});
}, 3000);
}, 200);
// Slow left-right movement for instruction text
var _instructMoveAnim = function instructMoveAnim() {
tween(instructionText, {
x: 40
}, {
duration: 4000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(instructionText, {
x: -40
}, {
duration: 4000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(instructionText, {
x: 0
}, {
duration: 4000,
easing: tween.easeInOut,
onFinish: _instructMoveAnim
});
}
});
}
});
};
LK.setTimeout(_instructMoveAnim, 1500);
// Show UI elements with animations
LK.setTimeout(function () {
tween(scoreTxt, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 600,
easing: tween.bounceOut
});
// Animate AI score display
tween(aiScoreTxt, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 600,
easing: tween.bounceOut
});
// Animate best score display
tween(bestScoreTxt, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 700,
easing: tween.bounceOut
});
}, 300);
LK.setTimeout(function () {
tween(timeTxt, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.bounceOut
});
}, 200);
LK.setTimeout(function () {
tween(difficultyTxt, {
alpha: 1,
x: 20
}, {
duration: 700,
easing: tween.easeOut
});
// Add pulsing glow to difficulty text
var _pulseDifficulty = function pulseDifficulty() {
tween(difficultyTxt, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(difficultyTxt, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1500,
easing: tween.easeInOut,
onFinish: _pulseDifficulty
});
}
});
};
LK.setTimeout(_pulseDifficulty, 1000);
}, 400);
// Show multiplier display
LK.setTimeout(function () {
tween(multiplierTxt, {
alpha: 1,
y: 0
}, {
duration: 500,
easing: tween.bounceOut
});
}, 1200);
}
function startGameTimers() {
// Game timer
gameTimer = LK.setInterval(function () {
if (!gameActive) return;
timeRemaining -= 100;
var seconds = Math.ceil(timeRemaining / 1000);
timeTxt.setText(seconds.toString());
// Dynamic background color based on time remaining
if (timeRemaining < 10000) {
// Gradually shift to dramatic purple-red as time runs out
var urgency = 1 - timeRemaining / 10000;
var red = Math.floor(45 + urgency * 80);
var green = Math.floor(35 * (1 - urgency));
var blue = Math.floor(54 + urgency * 40);
game.setBackgroundColor(red << 16 | green << 8 | blue);
} else if (currentStreak > 5) {
// Beautiful teal-gold background for high streaks
game.setBackgroundColor(0x00b894);
} else {
// Enhanced default background with warmer tones
game.setBackgroundColor(0x2d3436);
}
if (timeRemaining <= 0) {
gameActive = false;
LK.clearInterval(gameTimer);
LK.clearInterval(difficultyTimer);
// Update game statistics
gamesPlayed++;
storage.gamesPlayed = gamesPlayed;
var finalScore = LK.getScore();
totalScore += finalScore;
storage.totalScore = totalScore;
averageScore = totalScore / gamesPlayed;
storage.averageScore = averageScore;
// Compare player score vs AI score
// Show large statistics window first
showEndGameStatistics(function () {
var playerScore = LK.getScore();
var aiScore = aiCompetitor ? aiCompetitor.aiScore : 0;
if (playerScore > aiScore && playerScore >= 300) {
LK.showYouWin(); // Player beat AI and got good score
} else if (playerScore > aiScore) {
LK.showGameOver(); // Player beat AI but low score
} else {
LK.showGameOver(); // AI won or tied
}
});
}
}, 100);
// Difficulty progression
difficultyTimer = LK.setInterval(function () {
if (!gameActive) return;
var baseDifficulty = selectedGameDifficulty;
var timeFactor = Math.floor((gameTime - timeRemaining) / 10000);
difficulty = Math.min(10, baseDifficulty + timeFactor);
difficultyTxt.setText(getText('level') + difficulty);
// Generate new pattern every 5 seconds
if ((gameTime - timeRemaining) % 5000 < 100) {
targetPattern.generatePattern(difficulty);
}
}, 100);
}
// UI Elements (initially hidden)
var scoreTxt = new Text2('PLAYER: 0', {
size: 38,
fill: 0xfdcb6e,
stroke: 0x2d3436,
strokeThickness: 4
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.x = 0;
scoreTxt.y = 80;
scoreTxt.alpha = 0;
scoreTxt.scaleX = 0;
scoreTxt.scaleY = 0;
LK.gui.top.addChild(scoreTxt);
// AI Score display
var aiScoreTxt = new Text2('AI: 0', {
size: 38,
fill: 0xff6b6b,
stroke: 0x2d3436,
strokeThickness: 4
});
aiScoreTxt.anchor.set(0.5, 0);
aiScoreTxt.x = 0;
aiScoreTxt.y = 130;
aiScoreTxt.alpha = 0;
aiScoreTxt.scaleX = 0;
aiScoreTxt.scaleY = 0;
LK.gui.top.addChild(aiScoreTxt);
// Best Score display
var bestScore = storage.bestScore || 0;
var bestScoreTxt = new Text2('BEST: ' + bestScore, {
size: 32,
fill: 0xFFD700,
stroke: 0x2d3436,
strokeThickness: 3
});
bestScoreTxt.anchor.set(0.5, 0);
bestScoreTxt.x = 0;
bestScoreTxt.y = 180;
bestScoreTxt.alpha = 0;
bestScoreTxt.scaleX = 0;
bestScoreTxt.scaleY = 0;
LK.gui.top.addChild(bestScoreTxt);
var timeTxt = new Text2('60', {
size: 52,
fill: 0xfd79a8,
stroke: 0x2d3436,
strokeThickness: 4
});
timeTxt.anchor.set(1, 0);
timeTxt.x = -20;
timeTxt.y = 20;
timeTxt.alpha = 0;
timeTxt.scaleX = 0;
timeTxt.scaleY = 0;
LK.gui.topRight.addChild(timeTxt);
var difficultyTxt = new Text2(getText('level') + '1', {
size: 42,
fill: 0x74b9ff,
stroke: 0x2d3436,
strokeThickness: 3
});
difficultyTxt.anchor.set(0, 0);
difficultyTxt.x = -100;
difficultyTxt.y = 120;
difficultyTxt.alpha = 0;
LK.gui.topLeft.addChild(difficultyTxt);
// Game objects - initially hidden
var tapArea = game.attachAsset('tapArea', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
alpha: 0
});
var numberDisplay = game.addChild(new NumberDisplay());
numberDisplay.x = 1024;
numberDisplay.y = 800;
numberDisplay.alpha = 0;
numberDisplay.scaleX = 2.5;
numberDisplay.scaleY = 2.5;
// AI Competitor - positioned lower down
var aiCompetitor = game.addChild(new AICompetitor());
aiCompetitor.x = 1024;
aiCompetitor.y = 1900;
aiCompetitor.alpha = 0;
aiCompetitor.scaleX = 2.5;
aiCompetitor.scaleY = 2.5;
// Add visual line separator between player and AI
var separatorLine = game.attachAsset('targetPattern', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1350,
alpha: 0,
scaleX: 6.0,
scaleY: 0.2
});
separatorLine.tint = 0x74b9ff;
// Add breathing animation to separator line
var _breatheSeparator = function breatheSeparator() {
tween(separatorLine, {
scaleX: 6.5,
alpha: 0.8
}, {
duration: 1800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(separatorLine, {
scaleX: 6.0,
alpha: 0.6
}, {
duration: 1800,
easing: tween.easeInOut,
onFinish: _breatheSeparator
});
}
});
};
LK.setTimeout(_breatheSeparator, 2000);
var targetPattern = game.addChild(new TargetPattern());
targetPattern.x = 1024;
targetPattern.y = 450;
targetPattern.alpha = 0;
targetPattern.scaleX = 2.0;
targetPattern.scaleY = 2.0;
// Add continuous floating animation to target pattern
var _floatTargetPattern = function floatTargetPattern() {
tween(targetPattern, {
y: 470,
rotation: 0.05
}, {
duration: 2500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(targetPattern, {
y: 430,
rotation: -0.05
}, {
duration: 2500,
easing: tween.easeInOut,
onFinish: _floatTargetPattern
});
}
});
};
LK.setTimeout(_floatTargetPattern, 1500);
var streakDisplay = game.addChild(new StreakDisplay());
streakDisplay.x = 1024;
streakDisplay.y = 2200;
streakDisplay.alpha = 0;
streakDisplay.scaleX = 1.8;
streakDisplay.scaleY = 1.8;
// Instructions
var instructionText = new Text2(getText('tapToGenerate'), {
size: 72,
fill: 0xa29bfe,
stroke: 0x2d3436,
strokeThickness: 4
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 600;
instructionText.alpha = 0;
game.addChild(instructionText);
// Timer variables
var gameTimer;
var difficultyTimer;
// Touch handling
game.down = function (x, y, obj) {
if (!gameActive || gameState !== 'playing') return;
// Check cooldown
var currentTime = Date.now();
if (currentTime - lastRngTime < rngCooldown) {
return; // Still in cooldown, ignore tap
}
lastRngTime = currentTime;
numberDisplay.generateNumber();
LK.getSound('numberGenerate').play();
// Check for match
if (targetPattern.checkMatch(numberDisplay.currentNumber)) {
// Match found!
currentStreak++;
totalMatches++;
storage.totalMatches = totalMatches;
// Update best streak if needed
if (currentStreak > bestStreak) {
bestStreak = currentStreak;
storage.bestStreak = bestStreak;
}
multiplier = Math.min(5, 1 + Math.floor(currentStreak / 3));
var points = targetPattern.points * multiplier;
// Apply KEMALDEV 4x score multiplier if active
if (scoreMultiplierActive) {
points *= 4;
}
LK.setScore(LK.getScore() + points);
// Screen shake for big matches
if (multiplier > 2) {
shakeIntensity = Math.min(15, multiplier * 3);
}
// Particle burst for matches
var particleColor = multiplier > 3 ? 0xFFD700 : 0x00FF00;
var particleCount = Math.min(20, 5 + multiplier * 2);
particleSystem.burst(numberDisplay.x, numberDisplay.y, particleColor, particleCount);
// Update score text
scoreTxt.setText('PLAYER: ' + LK.getScore().toString());
// Check for new best score
var currentScore = LK.getScore();
if (currentScore > bestScore) {
bestScore = currentScore;
storage.bestScore = bestScore;
bestScoreTxt.setText('BEST: ' + bestScore);
// Special animation for new best score
tween(bestScoreTxt, {
scaleX: 1.5,
scaleY: 1.5,
rotation: 0.2
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(bestScoreTxt, {
scaleX: 1,
scaleY: 1,
rotation: 0
}, {
duration: 400,
easing: tween.bounceOut
});
}
});
// Golden glow effect for new best score
tween(bestScoreTxt, {
tint: 0xffffff
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(bestScoreTxt, {
tint: 0xFFD700
}, {
duration: 300,
easing: tween.easeIn
});
}
});
// Extra particles for new best score
particleSystem.burst(bestScoreTxt.x + 1024, bestScoreTxt.y + 200, 0xFFD700, 15);
}
// Score animation
tween(scoreTxt, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(scoreTxt, {
scaleX: 1,
scaleY: 1
}, {
duration: 300,
easing: tween.bounceOut
});
}
});
// Enhanced number display celebration
tween(numberDisplay, {
rotation: Math.PI * 2
}, {
duration: 600,
easing: tween.easeOut
});
streakDisplay.updateStreak(currentStreak);
// Visual feedback
LK.effects.flashObject(targetPattern, 0x00ff00, 500);
if (currentStreak > 1) {
LK.getSound('streak').play();
// Extra particles for streak
particleSystem.burst(streakDisplay.x, streakDisplay.y, 0xFFD700, 8);
} 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);
// Red particles for miss
particleSystem.burst(numberDisplay.x, numberDisplay.y, 0xFF0000, 5);
}
}
};
// Multiplier display
var multiplierTxt = new Text2('x1', {
size: 45,
fill: 0xfd79a8,
stroke: 0x2d3436,
strokeThickness: 4
});
multiplierTxt.anchor.set(0.5, 1);
multiplierTxt.alpha = 0;
multiplierTxt.y = 50;
LK.gui.bottom.addChild(multiplierTxt);
game.update = function () {
if (!gameActive) return;
// Screen shake effect
if (shakeIntensity > 0) {
game.x = (Math.random() - 0.5) * shakeIntensity;
game.y = (Math.random() - 0.5) * shakeIntensity;
shakeIntensity *= shakeDecay;
if (shakeIntensity < 0.5) {
shakeIntensity = 0;
game.x = 0;
game.y = 0;
}
}
// Update multiplier display
multiplierTxt.setText('x' + multiplier);
// Enhanced pulse multiplier when active
if (multiplier > 1) {
var pulse = Math.sin(LK.ticks * 0.15) * 0.15 + 1;
multiplierTxt.scaleX = pulse;
multiplierTxt.scaleY = pulse;
// Color shift for high multipliers
if (multiplier > 3) {
var colorShift = Math.sin(LK.ticks * 0.1) * 0.5 + 0.5;
multiplierTxt.tint = 0xFFFFFF * colorShift + 0xFF0000 * (1 - colorShift);
}
} else {
multiplierTxt.scaleX = 1;
multiplierTxt.scaleY = 1;
multiplierTxt.tint = 0xFFD700;
}
// AI Competitor logic
if (gameActive && gameState === 'playing' && aiCompetitor) {
// Update AI difficulty based on current game difficulty
aiCompetitor.setDifficulty(difficulty);
// AI attempts to match patterns
aiCompetitor.attemptMatch(targetPattern);
// AI score reduction logic removed - now handled in AI attemptMatch method
// Update AI score display
aiScoreTxt.setText('AI: ' + aiCompetitor.aiScore);
// AI score animation when it scores
if (aiCompetitor.aiScore > 0) {
var aiPulse = Math.sin(LK.ticks * 0.1) * 0.1 + 1;
aiScoreTxt.scaleX = aiPulse;
aiScoreTxt.scaleY = aiPulse;
}
// Competitive visual feedback with enhanced animations
if (aiCompetitor.aiScore > LK.getScore()) {
// AI is winning - make AI score more prominent
var aiWinGlow = Math.sin(LK.ticks * 0.15) * 0.3 + 0.7;
aiScoreTxt.tint = 0xffffff;
aiScoreTxt.alpha = aiWinGlow + 0.3;
scoreTxt.tint = 0x888888;
scoreTxt.alpha = 0.7;
// Add subtle shake to player score when losing
if (LK.ticks % 120 === 0) {
tween(scoreTxt, {
x: scoreTxt.x + 5
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(scoreTxt, {
x: 0
}, {
duration: 100,
easing: tween.easeOut
});
}
});
}
} else if (LK.getScore() > aiCompetitor.aiScore) {
// Player is winning
var playerWinGlow = Math.sin(LK.ticks * 0.12) * 0.2 + 0.8;
scoreTxt.tint = 0xffffff;
scoreTxt.alpha = playerWinGlow + 0.2;
aiScoreTxt.tint = 0x888888;
aiScoreTxt.alpha = 0.7;
} else {
// Tie - both pulsing
var tieGlow = Math.sin(LK.ticks * 0.1) * 0.2 + 0.8;
scoreTxt.tint = 0xfdcb6e;
scoreTxt.alpha = tieGlow;
aiScoreTxt.tint = 0xff6b6b;
aiScoreTxt.alpha = tieGlow;
}
}
// Subtle best score glow animation
if (bestScoreTxt.alpha > 0) {
var bestGlow = Math.sin(LK.ticks * 0.08) * 0.15 + 0.85;
bestScoreTxt.alpha = bestGlow;
// Gentle color shift for golden effect
var goldShift = Math.sin(LK.ticks * 0.06) * 0.2 + 0.8;
bestScoreTxt.tint = 0xFFD700 * goldShift + 0xFFF8DC * (1 - goldShift);
}
// Enhanced time warning effect
if (timeRemaining < 10000) {
var flash = Math.sin(LK.ticks * 0.3) * 0.3 + 0.7;
timeTxt.alpha = flash;
// Add color shift for urgency
var urgencyColor = Math.sin(LK.ticks * 0.25) * 0.5 + 0.5;
timeTxt.tint = 0xfd79a8 * (1 - urgencyColor) + 0xff0000 * urgencyColor;
// Pulse timer when very low
if (timeRemaining < 5000) {
var urgentPulse = Math.sin(LK.ticks * 0.2) * 0.2 + 1;
timeTxt.scaleX = urgentPulse;
timeTxt.scaleY = urgentPulse;
// Add screen edge glow effect
if (LK.ticks % 60 === 0) {
tween(game, {
tint: 0xff6666
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(game, {
tint: 0xffffff
}, {
duration: 300,
easing: tween.easeIn
});
}
});
}
}
}
// Subtle floating animation for number display
numberDisplay.y = 800 + Math.sin(LK.ticks * 0.05) * 20;
// AI floating animation
if (aiCompetitor) {
aiCompetitor.y = 1900 + Math.sin(LK.ticks * 0.03 + 1) * 18;
}
// Rainbow effect for high scores removed
};