Code edit (1 edits merged)
Please save this source code
User prompt
La segunda etapa de Frutas debe inicar 8 segundos despues de que inicia la primera, son tres frutas con .5 segundos de delay entre cada una. Quita la revisión de waitingFruits, porque ya no depende de si hya o no frutas de la etapa anterior.
User prompt
Aplicalo en el codigo.
Code edit (1 edits merged)
Please save this source code
User prompt
No esta ejecutando la segunda etapa en ningún momento.
User prompt
Si, porque estan saliendo las frutas o siendo cortadas y la segunda etapa nunca inicia, ignora los contadores 1 2 y go!, despues de haber trigueado la primera etapa espera 8 segundos y ejecuta la segunda, que no dependa si desaparecieron las frutas o no.
User prompt
Me refiero a que no esta iniciando la segunda etapa y debria iniciar despues de que termine la primera.
User prompt
Nunca inicia la segunda etapa.
User prompt
La segunda etapa de Frutas debe inicar despues de la primera, son tres frutas con .5 segundos de delay entre cada una.
User prompt
Quita toda la logica de mover el cañon hacia abajo cuando termina la ronda, cuando sale la ultima fruta de la etapa 1 y no es cortada la desaparece antes dellagar a la parte superior, esto no deberia pasar, no debe haber ninguna revisión por el momento ni de frutas cortadas ni nada, igual si la corto por alguna razon se queda el circulo blanco, pero solo es con esta ultima fruta especificamente.
User prompt
Quita toda la logica de spawn despues de que termina la primera ronda. Que no exista bucle ni se genern nuevas frutas por el momento.
User prompt
Listo! La primer etapa esta funcionando correctamente, la segunda etapa inicia 2 segundos despues de que acaba la primera y son tres frutas .5 segundos entre cada disparo.
Code edit (5 edits merged)
Please save this source code
User prompt
Modifica el tiempo de 3 a 2.5 segundos
Code edit (3 edits merged)
Please save this source code
User prompt
Siguen pasando 7 segundos entre que desaparece la fruta en la parte inferior y aparece arriba. Debemos bajar ese tiempo a 3 segundos.
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Ahora reduce la espera desde que la fruta entra al humbral del medio hata que sale a la parte superior, esta espera era como de 7 segundos, baja a 4 segundos.
User prompt
La espera entre el GO! y la primera fruta baja a 1.3 segundos.
User prompt
No tenias que modificar el tiempo entre disparos de 1,2 y Go! solo entre las frutas.
User prompt
Baja el tiempo a 1.5 segundos de espera, e incrementa el tiempo entre que se disparan las frutas a 1 segundo.
User prompt
Haber despues de disparar el GO! debes esperar dos segundos antes de lanzar la fruta y deben ser 4
User prompt
Ahumenta e tiempo para inicar la primera etapa a dos segundos.
User prompt
Ahora, la primera etapa iniciara 1 segundo depsues de lanzar el GO! Sera de 4 frutas con 1 segundo de delay entre acda una.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Clase Cannon para mostrar el cañón y animar disparo var Cannon = Container.expand(function () { var self = Container.call(this); // Asset del cañón (ahora usa la imagen personalizada) self.cannonAsset = self.attachAsset('cannon', { anchorX: 0.5, anchorY: 1 }); // Efecto de fogonazo al disparar self.flash = null; // Estado self.isVisible = true; self.isShooting = false; // Posición base (centrado horizontal, abajo) self.baseX = 2048 / 2; // Coloca el cañón pegado a la parte baja del juego (anchorY:1, así que baseY es exactamente el borde inferior) self.baseY = 2732; self.x = self.baseX; self.y = self.baseY; // Mostrar cañón self.show = function () { self.visible = true; self.isVisible = true; // Animar subida si estaba oculto tween(self, { y: self.baseY }, { duration: 350, easing: tween.cubicOut }); }; // Ocultar cañón (bajarlo fuera de pantalla) self.hide = function () { self.isVisible = false; tween(self, { y: 2732 + 400 }, { duration: 400, easing: tween.cubicIn, onFinish: function onFinish() { self.visible = false; } }); }; // Animar disparo (pequeño retroceso y fogonazo) self.shoot = function () { if (self.isShooting) { return; } self.isShooting = true; // Retroceso rápido tween(self, { y: self.baseY - 60 }, { duration: 80, easing: tween.cubicOut, onFinish: function onFinish() { // Regresa a posición base tween(self, { y: self.baseY }, { duration: 120, easing: tween.cubicIn, onFinish: function onFinish() { self.isShooting = false; } }); } }); // Fogonazo visual if (!self.flash) { self.flash = self.attachAsset('cut_zone', { anchorX: 0.5, anchorY: 1, x: 0, y: -self.cannonAsset.height + 30, scaleX: 0.5, scaleY: 0.3, alpha: 0.0, color: 0xffffcc }); } self.flash.alpha = 0.7; self.flash.scaleX = 0.5; self.flash.scaleY = 0.3; tween(self.flash, { alpha: 0, scaleX: 1.2, scaleY: 0.7 }, { duration: 120, easing: tween.linear }); }; return self; }); // Clase para el objeto de cuenta regresiva "Go" var CountdownGo = Container.expand(function () { var self = Container.call(this); self.asset = self.attachAsset('Go', { anchorX: 0.5, anchorY: 0.5 }); self.radius = self.asset.width / 2; self.isActive = true; self.state = 'countdown'; self.destroyCountdown = function () { self.isActive = false; self.visible = false; self.destroy(); }; return self; }); // Clase para el objeto de cuenta regresiva "1" var CountdownOne = Container.expand(function () { var self = Container.call(this); self.asset = self.attachAsset('1', { anchorX: 0.5, anchorY: 0.5 }); self.radius = self.asset.width / 2; self.isActive = true; self.state = 'countdown'; self.destroyCountdown = function () { self.isActive = false; self.visible = false; self.destroy(); }; return self; }); // Clase para el objeto de cuenta regresiva "2" var CountdownTwo = Container.expand(function () { var self = Container.call(this); self.asset = self.attachAsset('2', { anchorX: 0.5, anchorY: 0.5 }); self.radius = self.asset.width / 2; self.isActive = true; self.state = 'countdown'; self.destroyCountdown = function () { self.isActive = false; self.visible = false; self.destroy(); }; return self; }); // Clase para la fruta entera var Fruit = Container.expand(function () { var self = Container.call(this); // Selección aleatoria de tipo de fruta var fruitTypes = ['fruit_apple', 'fruit_lemon', 'fruit_orange', 'fruit_kiwi', 'fruit_plum']; self.fruitType = fruitTypes[Math.floor(Math.random() * fruitTypes.length)]; // Asset de la fruta self.fruitAsset = self.attachAsset(self.fruitType, { anchorX: 0.5, anchorY: 0.5 }); self.radius = self.fruitAsset.width / 2; // Estado self.isCut = false; self.isActive = true; // Si está en juego // Para saber si ya fue cortada self.cut = function () { if (self.isCut) { return; } self.isCut = true; self.isActive = false; self.visible = false; }; return self; }); // Clase para la fruta cortada (dos mitades) var FruitCut = Container.expand(function () { var self = Container.call(this); // Recibe tipo de fruta, posición base, rotación y escala self.init = function (fruitType, x, y, rotation, scale) { if (typeof rotation === "undefined") { rotation = 0; } if (typeof scale === "undefined") { scale = 1; } // Para las frutas, usar assets de mitades cortadas específicos por tipo de fruta var leftAssetId = 'fruit_apple_cut_left'; var rightAssetId = 'fruit_apple_cut_right'; if (fruitType === 'fruit_apple') { leftAssetId = 'fruit_apple_cut_left'; rightAssetId = 'fruit_apple_cut_right'; } else if (fruitType === 'fruit_lemon') { leftAssetId = 'fruit_lemon_cut_left'; rightAssetId = 'fruit_lemon_cut_right'; } else if (fruitType === 'fruit_orange') { leftAssetId = 'fruit_orange_cut_left'; rightAssetId = 'fruit_orange_cut_right'; } else if (fruitType === 'fruit_plum') { leftAssetId = 'fruit_plum_cut_left'; rightAssetId = 'fruit_plum_cut_right'; } else if (fruitType === 'fruit_kiwi') { leftAssetId = 'fruit_kiwi_cut_left'; rightAssetId = 'fruit_kiwi_cut_right'; } // Mitad izquierda reflejada horizontalmente (flipX: 1) self.left = self.attachAsset(leftAssetId, { anchorX: 1, anchorY: 0.5, scaleX: scale, scaleY: scale, x: 0, y: 0, flipX: 1 }); // Mitad derecha normal self.right = self.attachAsset(rightAssetId, { anchorX: 0, anchorY: 0.5, scaleX: scale, scaleY: scale, x: 0, y: 0 }); self.x = x; self.y = y; self.left.rotation = rotation; self.right.rotation = rotation; self.rotation = rotation; }; // Animación de separación self.animate = function (_onFinish) { // Reduce size to 80% immediately tween(self.left, { x: -80, rotation: self.left.rotation + 0.7, scaleX: self.left.scaleX * 0.8, scaleY: self.left.scaleY * 0.8 }, { duration: 500, easing: tween.cubicOut }); tween(self.right, { x: 80, rotation: self.right.rotation - 0.7, scaleX: self.right.scaleX * 0.8, scaleY: self.right.scaleY * 0.8 }, { duration: 500, easing: tween.cubicOut, onFinish: function onFinish() { // Fade out both halves after movement/scaling tween(self.left, { alpha: 0 }, { duration: 350, easing: tween.linear }); tween(self.right, { alpha: 0 }, { duration: 350, easing: tween.linear, onFinish: function onFinish() { if (_onFinish) { _onFinish(); } } }); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222222 }); /**** * Game Code ****/ // Inicia la música de fondo en loop al iniciar el juego LK.playMusic('bgmusic', { loop: true }); // Fondo superior azul // Fondo inferior café // Fondo inferior (parte baja de la pantalla) - café var bottomBg = LK.getAsset('bottom_bg', { anchorX: 0, anchorY: 1, x: 0, y: 2732 }); game.addChild(bottomBg); // Fondo superior (parte alta de la pantalla) - azul var topBg = LK.getAsset('top_bg', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); game.addChild(topBg); // Asset personalizado para el cañón (reemplaza el cut_line por una imagen de cañón) // scoreTxt oculto para evitar error de referencia y mantener compatibilidad con updateScore var scoreTxt = new Text2('', { size: 1, fill: "#222", alpha: 0 // completamente invisible }); scoreTxt.visible = false; // Línea negra horizontal de izquierda a derecha, aún más gruesa y un poco más abajo en el eje Y var horizontalLine = LK.getAsset('vertical_line', { anchorX: 0, anchorY: 0.5, x: 0, // Baja la línea: ahora 540px respecto al centro vertical y: 2732 / 2 + 540, width: 2048, height: 120, // mucho más gruesa color: 0x000000, shape: 'box' }); // Instancia y agrega el cañón var cannon = new Cannon(); game.addChild(horizontalLine); // Asegura que la línea esté sobre el fondo pero debajo de frutas y cañón game.addChild(cannon); cannon.show(); var frutasGeneradas = 0; var frutasFalladas = 0; var fruits = []; var fallingFruits = []; var cutFruits = []; var frutasFalladasTimeout = null; var roundBullets = 5; var fruitSpeed = 22; var cutZoneAsset = LK.getAsset('cut_zone', { anchorX: 0.5, anchorY: 0.5 }); var cutZoneRadius = cutZoneAsset.width / 2; cutZoneAsset.destroy(); var canCut = true; var lastTouchTick = -100; function updateScore(val) { LK.setScore(val); scoreTxt.setText(val); } function tryCutFruit(x, y) { if (!canCut) { return; } canCut = false; lastTouchTick = LK.ticks; for (var i = 0; i < fallingFruits.length; i++) { var fruit = fallingFruits[i]; if (!fruit.isActive) { continue; } if (fruit.state === 'cuttable') { var dx = x - fruit.x; var dy = y - fruit.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist <= fruit.radius * fruit.scaleX) { fruit.cut(); if (fruit.cutZoneCircle) { fruit.cutZoneCircle.destroy(); fruit.cutZoneCircle = null; } LK.getSound('cut').play(); // Animación de corte para todas las frutas: mostrar sprite partido, NO el círculo blanco var fruitCut = new FruitCut(); fruitCut.init(fruit.fruitType, fruit.x, fruit.y, fruit.rotation, fruit.scaleX); game.addChild(fruitCut); // Asegura que la línea negra esté sobre las frutas cortadas pero debajo del cañón if (horizontalLine && horizontalLine.parent) { horizontalLine.parent.removeChild(horizontalLine); game.addChild(horizontalLine); } // Asegura que el cañón siempre esté al frente if (cannon && cannon.parent) { cannon.parent.removeChild(cannon); game.addChild(cannon); } fruitCut.animate(function () { fruitCut.destroy(); }); cutFruits.push(fruitCut); frutasGeneradas++; updateScore(LK.getScore() + 1); return; } } } } game.down = function (x, y, obj) { tryCutFruit(x, y); }; // Main update game.update = function () { // Permitir corte nuevamente tras 6 ticks (~100ms) if (!canCut && LK.ticks - lastTouchTick > 6) { canCut = true; } // --- SISTEMA DE BALAS POR RONDA (5 balas, 1s entre cada una, 7s delay antes de mostrar en pantalla superior) --- if (typeof roundState === "undefined") { // Estados posibles: 'waiting', 'spawning', 'waitingFruits' roundState = 'waiting'; roundBullets = 7; // 3 countdown + 4 fruits roundFruitsQueue = []; roundFruitsActive = []; roundNextBulletTick = LK.ticks + 30; // primer disparo tras 0.5s roundBulletsFired = 0; roundDelayBetweenRounds = 120; // 2s entre rondas roundDelayTicks = 0; } if (roundState === 'waiting') { // Limpiar arrays de frutas y mitades cortadas de la ronda anterior for (var i = fruits.length - 1; i >= 0; i--) { if (fruits[i]) { fruits[i].destroy(); } } fruits = []; for (var i = fallingFruits.length - 1; i >= 0; i--) { if (fallingFruits[i]) { fallingFruits[i].destroy(); } } fallingFruits = []; for (var i = cutFruits.length - 1; i >= 0; i--) { if (cutFruits[i]) { cutFruits[i].destroy(); } } cutFruits = []; // Limpiar arrays de control de ronda if (typeof roundFruitsQueue !== "undefined") { for (var i = roundFruitsQueue.length - 1; i >= 0; i--) { if (roundFruitsQueue[i] && roundFruitsQueue[i].destroy) { roundFruitsQueue[i].destroy(); } } } roundFruitsQueue = []; if (typeof roundFruitsActive !== "undefined") { for (var i = roundFruitsActive.length - 1; i >= 0; i--) { if (roundFruitsActive[i] && roundFruitsActive[i].destroy) { roundFruitsActive[i].destroy(); } } } roundFruitsActive = []; // Reset meta de ronda roundBulletsFired = 0; roundNextBulletTick = LK.ticks; roundDelayTicks = 0; countdownObjectsFired = 0; // Reset countdown counter // Esperar un frame antes de permitir el spawn para evitar generación múltiple if (typeof roundJustReset === "undefined" || !roundJustReset) { roundJustReset = true; return; } else { roundJustReset = false; roundState = 'spawning'; } } if (roundState === 'spawning') { // Disparar los objetos de cuenta regresiva "1", "2", "Go" en los primeros tres disparos if (typeof countdownObjectsFired === "undefined") { countdownObjectsFired = 0; } if (roundBulletsFired < roundBullets && LK.ticks >= roundNextBulletTick) { var margin = 180; var fruitX = margin + Math.random() * (2048 - 2 * margin); cannon.x = fruitX; cannon.show(); cannon.shoot(); // Dispara "1", "2", "Go" en los primeros tres disparos if (countdownObjectsFired === 0) { var obj1 = new CountdownOne(); obj1.x = fruitX; obj1.y = 2732 + obj1.radius - 120; obj1.startY = obj1.y; obj1.targetY = 2732 / 2 + 600; obj1.state = 'rising'; obj1.ticks = 0; obj1.roundMeta = { hasCrossed: false, crossedTick: null, showScheduled: false, showTimeout: null, destroyed: false }; fruits.push(obj1); roundFruitsQueue.push(obj1); game.addChild(obj1); // Mostrar "1" centrado y gigante con fade out var centerObj1 = new CountdownOne(); centerObj1.x = 2048 / 2; centerObj1.y = 2732 / 2; centerObj1.scaleX = centerObj1.scaleY = 5; // Gigante centerObj1.alpha = 1; game.addChild(centerObj1); // Fade out después de 0.5 segundos LK.setTimeout(function () { tween(centerObj1, { alpha: 0 }, { duration: 300, easing: tween.linear, onFinish: function onFinish() { centerObj1.destroy(); } }); }, 500); countdownObjectsFired++; } else if (countdownObjectsFired === 1) { var obj2 = new CountdownTwo(); obj2.x = fruitX; obj2.y = 2732 + obj2.radius - 120; obj2.startY = obj2.y; obj2.targetY = 2732 / 2 + 600; obj2.state = 'rising'; obj2.ticks = 0; obj2.roundMeta = { hasCrossed: false, crossedTick: null, showScheduled: false, showTimeout: null, destroyed: false }; fruits.push(obj2); roundFruitsQueue.push(obj2); game.addChild(obj2); // Mostrar "2" centrado y gigante con fade out var centerObj2 = new CountdownTwo(); centerObj2.x = 2048 / 2; centerObj2.y = 2732 / 2; centerObj2.scaleX = centerObj2.scaleY = 5; // Gigante centerObj2.alpha = 1; game.addChild(centerObj2); // Fade out después de 0.5 segundos LK.setTimeout(function () { tween(centerObj2, { alpha: 0 }, { duration: 300, easing: tween.linear, onFinish: function onFinish() { centerObj2.destroy(); } }); }, 500); countdownObjectsFired++; } else if (countdownObjectsFired === 2) { var objGo = new CountdownGo(); objGo.x = fruitX; objGo.y = 2732 + objGo.radius - 120; objGo.startY = objGo.y; objGo.targetY = 2732 / 2 + 600; objGo.state = 'rising'; objGo.ticks = 0; objGo.roundMeta = { hasCrossed: false, crossedTick: null, showScheduled: false, showTimeout: null, destroyed: false }; fruits.push(objGo); roundFruitsQueue.push(objGo); game.addChild(objGo); // Mostrar "Go!" centrado y gigante con fade out var centerObjGo = new CountdownGo(); centerObjGo.x = 2048 / 2; centerObjGo.y = 2732 / 2; centerObjGo.scaleX = centerObjGo.scaleY = 5; // Gigante centerObjGo.alpha = 1; game.addChild(centerObjGo); // Fade out después de 0.5 segundos LK.setTimeout(function () { tween(centerObjGo, { alpha: 0 }, { duration: 300, easing: tween.linear, onFinish: function onFinish() { centerObjGo.destroy(); } }); }, 500); countdownObjectsFired++; // Set next bullet time to 1 second after GO! roundNextBulletTick = LK.ticks + 60; // 1 second delay } else if (countdownObjectsFired >= 3) { // Spawn fruits after countdown var fruit = new Fruit(); fruit.x = fruitX; fruit.y = 2732 + fruit.radius - 120; fruit.startY = fruit.y; fruit.targetY = 2732 / 2 + 600; fruit.state = 'rising'; fruit.ticks = 0; fruit.roundMeta = { hasCrossed: false, crossedTick: null, showScheduled: false, showTimeout: null, destroyed: false }; fruits.push(fruit); roundFruitsQueue.push(fruit); game.addChild(fruit); // Set next bullet time to 1 second later roundNextBulletTick = LK.ticks + 60; // 1 second between fruits } // Asegura que el cañón siempre esté al frente if (cannon && cannon.parent) { cannon.parent.removeChild(cannon); game.addChild(cannon); } roundBulletsFired++; roundNextBulletTick = LK.ticks + 30; // 0.5s entre balas (120 BPM) } // Cuando todas las balas han sido disparadas y ya no quedan frutas activas, pasar a siguiente estado // (pero solo cuando todas las frutas hayan sido destruidas o salidas de pantalla) var allGone = true; for (var i = 0; i < roundFruitsQueue.length; i++) { if (!roundFruitsQueue[i].roundMeta.destroyed) { allGone = false; break; } } for (var i = 0; i < roundFruitsActive.length; i++) { if (!roundFruitsActive[i].roundMeta.destroyed) { allGone = false; break; } } if (roundBulletsFired >= roundBullets && allGone) { // Oculta el cañón al terminar la ronda if (cannon) { cannon.hide(); } roundState = 'waitingFruits'; roundDelayTicks = 0; } } if (roundState === 'waitingFruits') { // Espera 2s antes de reiniciar la ronda roundDelayTicks++; if (roundDelayTicks >= roundDelayBetweenRounds) { // Limpiar arrays de frutas activas y en cola antes de reiniciar la ronda for (var i = fruits.length - 1; i >= 0; i--) { if (fruits[i]) { fruits[i].destroy(); } } fruits = []; for (var i = fallingFruits.length - 1; i >= 0; i--) { if (fallingFruits[i]) { fallingFruits[i].destroy(); } } fallingFruits = []; for (var i = cutFruits.length - 1; i >= 0; i--) { if (cutFruits[i]) { cutFruits[i].destroy(); } } cutFruits = []; roundFruitsQueue = []; roundFruitsActive = []; roundState = 'waiting'; } } // Mover frutas que suben desde abajo hasta el centro for (var i = fruits.length - 1; i >= 0; i--) { var fruit = fruits[i]; if (fruit.state === 'rising') { fruit.y -= fruitSpeed; fruit.ticks++; // Escalado según altura (más arriba, más grande) var minScale = 1.0; var maxScale = 1.25; var y0 = 2732 + fruit.radius + 10; var y1 = 2732 / 2 + 420; var t = (fruit.y - y1) / (y0 - y1); if (t < 0) { t = 0; } if (t > 1) { t = 1; } var scale = minScale + (maxScale - minScale) * (1 - t); fruit.scaleX = fruit.scaleY = scale; // Rotación en la parte de abajo (solo mientras sube) if (typeof fruit.rotation === "undefined") { fruit.rotation = Math.random() * Math.PI * 2; } if (typeof fruit.rotationSpeed === "undefined") { fruit.rotationSpeed = (Math.random() - 0.5) * 0.08; } fruit.rotation += fruit.rotationSpeed; if (fruit.fruitAsset) { fruit.fruitAsset.rotation = fruit.rotation; } // Cuando cruza la altura objetivo (centro), programar aparición en pantalla superior tras un tiempo proporcional al número de frutas lanzadas if (!fruit.roundMeta.hasCrossed && fruit.y <= fruit.targetY) { fruit.roundMeta.hasCrossed = true; fruit.roundMeta.crossedTick = LK.ticks; fruit.visible = false; // Only schedule top appearance for fruits, not countdown objects if (fruit.fruitType && fruit.fruitAsset) { // El tiempo de espera es igual a 1s * cantidad de frutas lanzadas en la ronda var fruitsInRound = 4; // Solo las 4 frutas var appearDelayMs = fruitsInRound * 1000; // 1s por fruta lanzada fruit.roundMeta.showScheduled = true; fruit.roundMeta.showTimeout = LK.setTimeout(function () { if (!fruit.roundMeta.destroyed && fruit.isActive) { // Create falling fruit from top var fallingFruit = new Fruit(); fallingFruit.x = Math.random() * (2048 - 200) + 100; fallingFruit.y = 420; fallingFruit.fruitType = fruit.fruitType; // Re-create the asset with the same type fallingFruit.fruitAsset.destroy(); fallingFruit.fruitAsset = fallingFruit.attachAsset(fruit.fruitType, { anchorX: 0.5, anchorY: 0.5 }); fallingFruit.state = 'cuttable'; fallingFruit.roundMeta = { hasCrossed: false, crossedTick: null, showScheduled: false, showTimeout: null, destroyed: false }; fallingFruits.push(fallingFruit); roundFruitsActive.push(fallingFruit); game.addChild(fallingFruit); } // Mark original fruit as destroyed fruit.roundMeta.destroyed = true; fruit.destroy(); }, appearDelayMs); } } // Si la fruta está oculta y esperando, no hacer nada más if (fruit.roundMeta.hasCrossed && fruit.roundMeta.showScheduled) { // Si la fruta fue destruida antes de los 7s, cancelar timeout y limpiar if (fruit.roundMeta.destroyed) { if (fruit.roundMeta.showTimeout) { LK.clearTimeout(fruit.roundMeta.showTimeout); fruit.roundMeta.showTimeout = null; } // Eliminar de roundFruitsQueue si está presente if (typeof roundFruitsQueue !== "undefined") { for (var j = roundFruitsQueue.length - 1; j >= 0; j--) { if (roundFruitsQueue[j] === fruit) { roundFruitsQueue.splice(j, 1); break; } } } fruits.splice(i, 1); } continue; } // Si la fruta sale de pantalla antes de cruzar, eliminar y marcar como destruida if (fruit.y < -fruit.radius) { // BAJA MUCHO MÁS el umbral de desaparición inferior fruit.roundMeta.destroyed = true; if (fruit.roundMeta.showTimeout) { LK.clearTimeout(fruit.roundMeta.showTimeout); fruit.roundMeta.showTimeout = null; } // Eliminar de roundFruitsQueue si está presente if (typeof roundFruitsQueue !== "undefined") { for (var j = roundFruitsQueue.length - 1; j >= 0; j--) { if (roundFruitsQueue[j] === fruit) { roundFruitsQueue.splice(j, 1); break; } } } // Aumentar frutasFalladas si la fruta se perdió antes de aparecer frutasFalladas++; frutasGeneradas++; fruit.destroy(); fruits.splice(i, 1); } } } // Mover frutas que suben de nuevo y gestionar zona de corte visual // --- Asegura que la línea negra esté sobre los sprites de las frutas en cada frame --- if (horizontalLine && horizontalLine.parent) { horizontalLine.parent.removeChild(horizontalLine); game.addChild(horizontalLine); } for (var i = fallingFruits.length - 1; i >= 0; i--) { var fruit = fallingFruits[i]; if (!fruit.isActive) { continue; } // Escalado según altura (más arriba, más grande) var minScale = 1.0; var maxScale = 1.25 * 1.3 * 1.3; //{45} // 60% más grande en la parte superior var y0 = 2732 / 2 + 420; var y1 = 420; var t = (fruit.y - y1) / (y0 - y1); if (t < 0) { t = 0; } if (t > 1) { t = 1; } var scale = minScale + (maxScale - minScale) * (1 - t); fruit.scaleX = fruit.scaleY = scale; // Rotación suave if (typeof fruit.rotationSpeed !== "undefined") { fruit.rotation += fruit.rotationSpeed; if (fruit.fruitAsset) { fruit.fruitAsset.rotation = fruit.rotation; } } // Movimiento hacia arriba mientras sea cortable o volando hacia arriba if (fruit.state === 'cuttable' || fruit.state === 'flyingup') { fruit.y -= fruitSpeed; } // --- Animación progresiva del círculo de corte --- // El círculo aparece desde el inicio de la subida (cuttable), crece y se difumina progresivamente if (fruit.state === 'cuttable') { // Si no existe el círculo, crearlo if (!fruit.cutZoneCircle) { fruit.cutZoneCircle = LK.getAsset('cut_zone', { anchorX: 0.5, anchorY: 0.5, x: fruit.x, y: fruit.y, alpha: 0.0, scaleX: 0.1, scaleY: 0.1 }); game.addChild(fruit.cutZoneCircle); // Asegura que la línea negra esté sobre el círculo de corte pero debajo del cañón if (horizontalLine && horizontalLine.parent) { horizontalLine.parent.removeChild(horizontalLine); game.addChild(horizontalLine); } // Asegura que el cañón siempre esté al frente if (cannon && cannon.parent) { cannon.parent.removeChild(cannon); game.addChild(cannon); } } // Progresión del círculo: desde que inicia la subida hasta que llega cerca de la parte superior var appearT = (y0 - fruit.y) / (y0 - y1); if (appearT < 0) { appearT = 0; } if (appearT > 1) { appearT = 1; } var maxScaleZone = 0.85; // Más pequeño, para que quede dentro de la fruta var minScaleZone = 0.15; var maxAlpha = 0.38; // Más difuminado var minAlpha = 0.08; var scaleZone = minScaleZone + (maxScaleZone - minScaleZone) * appearT; var alphaZone = minAlpha + (maxAlpha - minAlpha) * appearT; fruit.cutZoneCircle.scaleX = fruit.cutZoneCircle.scaleY = scaleZone; fruit.cutZoneCircle.alpha = alphaZone; fruit.cutZoneCircle.x = fruit.x; fruit.cutZoneCircle.y = fruit.y; // Si la fruta sale por arriba, eliminar círculo y pasar a flyingup if (fruit.y < y1) { // Si el círculo de corte existe y la fruta no fue cortada, contar como fallada if (fruit.cutZoneCircle) { fruit.cutZoneCircle.destroy(); fruit.cutZoneCircle = null; if (fruit.isActive && !fruit.isCut) { frutasFalladas++; frutasGeneradas++; } } fruit.state = 'flyingup'; } } else { // Si no está en estado cortable y existe el círculo, destruirlo if (fruit.cutZoneCircle) { fruit.cutZoneCircle.destroy(); fruit.cutZoneCircle = null; } } // Si fue cortada, eliminar círculo visual inmediatamente pero mantener la fruta visible if (!fruit.isActive && fruit.cutZoneCircle) { fruit.cutZoneCircle.destroy(); fruit.cutZoneCircle = null; } // Si está cayendo, animar caída if (fruit.state === 'dropping') { fruit.dropSpeed += 2.5; // gravedad fruit.y += fruit.dropSpeed; // Escalado decreciente al caer fruit.scaleX = fruit.scaleY = Math.max(0.7, fruit.scaleX - 0.01); if (fruit.cutZoneCircle) { fruit.cutZoneCircle.x = fruit.x; fruit.cutZoneCircle.y = fruit.y; } // Si sale de pantalla, marcar como inactivo pero mantener visible if (fruit.y > 2732 + fruit.radius + 20) { if (fruit.cutZoneCircle) { fruit.cutZoneCircle.destroy(); fruit.cutZoneCircle = null; } fruit.isActive = false; } } // Si la fruta sigue subiendo después de la zona de corte y no fue cortada if (fruit.state === 'flyingup') { // Al entrar por primera vez en flyingup, inicia temporizador de espera if (typeof fruit.waitTicks === "undefined") { fruit.waitTicks = 0; } fruit.waitTicks++; // Mantener la fruta visible y estática durante 7 segundos (420 ticks) if (fruit.waitTicks < 420) { // Mantener posición (opcional: podrías hacer que siga subiendo lentamente) // fruit.y -= fruitSpeed * 0.1; } else { // Después de 7 segundos, hacer que suba y desaparezca fruit.y -= fruitSpeed; // Escalado sigue creciendo un poco fruit.scaleX = fruit.scaleY = Math.min(maxScale, fruit.scaleX + 0.01); // Si sale de pantalla por arriba, marcar como inactiva y eliminar círculo de corte si existe if (fruit.y < -fruit.radius - 20) { if (fruit.cutZoneCircle) { fruit.cutZoneCircle.destroy(); fruit.cutZoneCircle = null; } fruit.isActive = false; // Marcar como destruida para el sistema de ronda if (fruit.roundMeta) { fruit.roundMeta.destroyed = true; } // Eliminar de roundFruitsActive si está presente if (typeof roundFruitsActive !== "undefined") { for (var j = roundFruitsActive.length - 1; j >= 0; j--) { if (roundFruitsActive[j] === fruit) { roundFruitsActive.splice(j, 1); break; } } } // Aumentar frutasFalladas y frutasGeneradas solo si la fruta no fue cortada if (!fruit.isCut) { frutasFalladas++; frutasGeneradas++; } } } } // Si la fruta ya fue cortada o salió de pantalla, eliminar if (!fruit.isActive || fruit.y > 2732 + fruit.radius + 20 || fruit.y < -fruit.radius - 20) { if (fruit.cutZoneCircle) { fruit.cutZoneCircle.destroy(); fruit.cutZoneCircle = null; } // Marcar como destruida para el sistema de ronda if (fruit.roundMeta) { fruit.roundMeta.destroyed = true; } // Eliminar de roundFruitsActive si está presente if (typeof roundFruitsActive !== "undefined") { for (var j = roundFruitsActive.length - 1; j >= 0; j--) { if (roundFruitsActive[j] === fruit) { roundFruitsActive.splice(j, 1); break; } } } fruit.destroy(); fallingFruits.splice(i, 1); } } // Limpiar mitades cortadas que ya terminaron animación for (var i = cutFruits.length - 1; i >= 0; i--) { var fc = cutFruits[i]; if (!fc.left || !fc.right) { if (fc.destroy) { fc.destroy(); } cutFruits.splice(i, 1); } } // Variable para controlar el timeout (debe estar fuera de la función que chequea frutasFalladas) if (roundBulletsFired >= 3 && roundState === 'waitingFruits') { // Mostrar los sprites 1, 2, Go en el centro con fade in/fade out rápido solo una vez, SOLO al inicio del juego if ((typeof showCountdownInMiddleDone === "undefined" || !showCountdownInMiddleDone) && LK.ticks < 120) { showCountdownInMiddleDone = true; var centerX = 2048 / 2; var centerY = 2732 / 2; var countdownSprites = [{ cls: CountdownOne, delay: 0 }, { cls: CountdownTwo, delay: 350 }, { cls: CountdownGo, delay: 700 }]; for (var idx = 0; idx < countdownSprites.length; idx++) { (function (idx) { var conf = countdownSprites[idx]; LK.setTimeout(function () { var obj = new conf.cls(); obj.x = centerX; obj.y = centerY; obj.alpha = 0; game.addChild(obj); // Fade in rápido tween(obj, { alpha: 1 }, { duration: 180, easing: tween.cubicOut, onFinish: function onFinish() { // Fade out rápido tween(obj, { alpha: 0 }, { duration: 180, delay: 180, easing: tween.cubicIn, onFinish: function onFinish() { obj.destroy(); } }); } }); }, conf.delay); })(idx); } } if (!frutasFalladasTimeout) { frutasFalladasTimeout = LK.setTimeout(function () { for (var i = fruits.length - 1; i >= 0; i--) { if (fruits[i]) { fruits[i].destroy(); } } fruits = []; for (var i = fallingFruits.length - 1; i >= 0; i--) { if (fallingFruits[i]) { fallingFruits[i].destroy(); } } fallingFruits = []; for (var i = cutFruits.length - 1; i >= 0; i--) { if (cutFruits[i]) { cutFruits[i].destroy(); } } cutFruits = []; if (typeof roundFruitsQueue !== "undefined") { for (var i = roundFruitsQueue.length - 1; i >= 0; i--) { if (roundFruitsQueue[i] && roundFruitsQueue[i].destroy) { roundFruitsQueue[i].destroy(); } } } roundFruitsQueue = []; if (typeof roundFruitsActive !== "undefined") { for (var i = roundFruitsActive.length - 1; i >= 0; i--) { if (roundFruitsActive[i] && roundFruitsActive[i].destroy) { roundFruitsActive[i].destroy(); } } } roundFruitsActive = []; // No reiniciar el estado, terminar el juego después de los countdown LK.showGameOver(); }, 2000); } return; } }; updateScore(0);
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Clase Cannon para mostrar el cañón y animar disparo
var Cannon = Container.expand(function () {
var self = Container.call(this);
// Asset del cañón (ahora usa la imagen personalizada)
self.cannonAsset = self.attachAsset('cannon', {
anchorX: 0.5,
anchorY: 1
});
// Efecto de fogonazo al disparar
self.flash = null;
// Estado
self.isVisible = true;
self.isShooting = false;
// Posición base (centrado horizontal, abajo)
self.baseX = 2048 / 2;
// Coloca el cañón pegado a la parte baja del juego (anchorY:1, así que baseY es exactamente el borde inferior)
self.baseY = 2732;
self.x = self.baseX;
self.y = self.baseY;
// Mostrar cañón
self.show = function () {
self.visible = true;
self.isVisible = true;
// Animar subida si estaba oculto
tween(self, {
y: self.baseY
}, {
duration: 350,
easing: tween.cubicOut
});
};
// Ocultar cañón (bajarlo fuera de pantalla)
self.hide = function () {
self.isVisible = false;
tween(self, {
y: 2732 + 400
}, {
duration: 400,
easing: tween.cubicIn,
onFinish: function onFinish() {
self.visible = false;
}
});
};
// Animar disparo (pequeño retroceso y fogonazo)
self.shoot = function () {
if (self.isShooting) {
return;
}
self.isShooting = true;
// Retroceso rápido
tween(self, {
y: self.baseY - 60
}, {
duration: 80,
easing: tween.cubicOut,
onFinish: function onFinish() {
// Regresa a posición base
tween(self, {
y: self.baseY
}, {
duration: 120,
easing: tween.cubicIn,
onFinish: function onFinish() {
self.isShooting = false;
}
});
}
});
// Fogonazo visual
if (!self.flash) {
self.flash = self.attachAsset('cut_zone', {
anchorX: 0.5,
anchorY: 1,
x: 0,
y: -self.cannonAsset.height + 30,
scaleX: 0.5,
scaleY: 0.3,
alpha: 0.0,
color: 0xffffcc
});
}
self.flash.alpha = 0.7;
self.flash.scaleX = 0.5;
self.flash.scaleY = 0.3;
tween(self.flash, {
alpha: 0,
scaleX: 1.2,
scaleY: 0.7
}, {
duration: 120,
easing: tween.linear
});
};
return self;
});
// Clase para el objeto de cuenta regresiva "Go"
var CountdownGo = Container.expand(function () {
var self = Container.call(this);
self.asset = self.attachAsset('Go', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = self.asset.width / 2;
self.isActive = true;
self.state = 'countdown';
self.destroyCountdown = function () {
self.isActive = false;
self.visible = false;
self.destroy();
};
return self;
});
// Clase para el objeto de cuenta regresiva "1"
var CountdownOne = Container.expand(function () {
var self = Container.call(this);
self.asset = self.attachAsset('1', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = self.asset.width / 2;
self.isActive = true;
self.state = 'countdown';
self.destroyCountdown = function () {
self.isActive = false;
self.visible = false;
self.destroy();
};
return self;
});
// Clase para el objeto de cuenta regresiva "2"
var CountdownTwo = Container.expand(function () {
var self = Container.call(this);
self.asset = self.attachAsset('2', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = self.asset.width / 2;
self.isActive = true;
self.state = 'countdown';
self.destroyCountdown = function () {
self.isActive = false;
self.visible = false;
self.destroy();
};
return self;
});
// Clase para la fruta entera
var Fruit = Container.expand(function () {
var self = Container.call(this);
// Selección aleatoria de tipo de fruta
var fruitTypes = ['fruit_apple', 'fruit_lemon', 'fruit_orange', 'fruit_kiwi', 'fruit_plum'];
self.fruitType = fruitTypes[Math.floor(Math.random() * fruitTypes.length)];
// Asset de la fruta
self.fruitAsset = self.attachAsset(self.fruitType, {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = self.fruitAsset.width / 2;
// Estado
self.isCut = false;
self.isActive = true; // Si está en juego
// Para saber si ya fue cortada
self.cut = function () {
if (self.isCut) {
return;
}
self.isCut = true;
self.isActive = false;
self.visible = false;
};
return self;
});
// Clase para la fruta cortada (dos mitades)
var FruitCut = Container.expand(function () {
var self = Container.call(this);
// Recibe tipo de fruta, posición base, rotación y escala
self.init = function (fruitType, x, y, rotation, scale) {
if (typeof rotation === "undefined") {
rotation = 0;
}
if (typeof scale === "undefined") {
scale = 1;
}
// Para las frutas, usar assets de mitades cortadas específicos por tipo de fruta
var leftAssetId = 'fruit_apple_cut_left';
var rightAssetId = 'fruit_apple_cut_right';
if (fruitType === 'fruit_apple') {
leftAssetId = 'fruit_apple_cut_left';
rightAssetId = 'fruit_apple_cut_right';
} else if (fruitType === 'fruit_lemon') {
leftAssetId = 'fruit_lemon_cut_left';
rightAssetId = 'fruit_lemon_cut_right';
} else if (fruitType === 'fruit_orange') {
leftAssetId = 'fruit_orange_cut_left';
rightAssetId = 'fruit_orange_cut_right';
} else if (fruitType === 'fruit_plum') {
leftAssetId = 'fruit_plum_cut_left';
rightAssetId = 'fruit_plum_cut_right';
} else if (fruitType === 'fruit_kiwi') {
leftAssetId = 'fruit_kiwi_cut_left';
rightAssetId = 'fruit_kiwi_cut_right';
}
// Mitad izquierda reflejada horizontalmente (flipX: 1)
self.left = self.attachAsset(leftAssetId, {
anchorX: 1,
anchorY: 0.5,
scaleX: scale,
scaleY: scale,
x: 0,
y: 0,
flipX: 1
});
// Mitad derecha normal
self.right = self.attachAsset(rightAssetId, {
anchorX: 0,
anchorY: 0.5,
scaleX: scale,
scaleY: scale,
x: 0,
y: 0
});
self.x = x;
self.y = y;
self.left.rotation = rotation;
self.right.rotation = rotation;
self.rotation = rotation;
};
// Animación de separación
self.animate = function (_onFinish) {
// Reduce size to 80% immediately
tween(self.left, {
x: -80,
rotation: self.left.rotation + 0.7,
scaleX: self.left.scaleX * 0.8,
scaleY: self.left.scaleY * 0.8
}, {
duration: 500,
easing: tween.cubicOut
});
tween(self.right, {
x: 80,
rotation: self.right.rotation - 0.7,
scaleX: self.right.scaleX * 0.8,
scaleY: self.right.scaleY * 0.8
}, {
duration: 500,
easing: tween.cubicOut,
onFinish: function onFinish() {
// Fade out both halves after movement/scaling
tween(self.left, {
alpha: 0
}, {
duration: 350,
easing: tween.linear
});
tween(self.right, {
alpha: 0
}, {
duration: 350,
easing: tween.linear,
onFinish: function onFinish() {
if (_onFinish) {
_onFinish();
}
}
});
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222222
});
/****
* Game Code
****/
// Inicia la música de fondo en loop al iniciar el juego
LK.playMusic('bgmusic', {
loop: true
});
// Fondo superior azul
// Fondo inferior café
// Fondo inferior (parte baja de la pantalla) - café
var bottomBg = LK.getAsset('bottom_bg', {
anchorX: 0,
anchorY: 1,
x: 0,
y: 2732
});
game.addChild(bottomBg);
// Fondo superior (parte alta de la pantalla) - azul
var topBg = LK.getAsset('top_bg', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChild(topBg);
// Asset personalizado para el cañón (reemplaza el cut_line por una imagen de cañón)
// scoreTxt oculto para evitar error de referencia y mantener compatibilidad con updateScore
var scoreTxt = new Text2('', {
size: 1,
fill: "#222",
alpha: 0 // completamente invisible
});
scoreTxt.visible = false;
// Línea negra horizontal de izquierda a derecha, aún más gruesa y un poco más abajo en el eje Y
var horizontalLine = LK.getAsset('vertical_line', {
anchorX: 0,
anchorY: 0.5,
x: 0,
// Baja la línea: ahora 540px respecto al centro vertical
y: 2732 / 2 + 540,
width: 2048,
height: 120,
// mucho más gruesa
color: 0x000000,
shape: 'box'
});
// Instancia y agrega el cañón
var cannon = new Cannon();
game.addChild(horizontalLine); // Asegura que la línea esté sobre el fondo pero debajo de frutas y cañón
game.addChild(cannon);
cannon.show();
var frutasGeneradas = 0;
var frutasFalladas = 0;
var fruits = [];
var fallingFruits = [];
var cutFruits = [];
var frutasFalladasTimeout = null;
var roundBullets = 5;
var fruitSpeed = 22;
var cutZoneAsset = LK.getAsset('cut_zone', {
anchorX: 0.5,
anchorY: 0.5
});
var cutZoneRadius = cutZoneAsset.width / 2;
cutZoneAsset.destroy();
var canCut = true;
var lastTouchTick = -100;
function updateScore(val) {
LK.setScore(val);
scoreTxt.setText(val);
}
function tryCutFruit(x, y) {
if (!canCut) {
return;
}
canCut = false;
lastTouchTick = LK.ticks;
for (var i = 0; i < fallingFruits.length; i++) {
var fruit = fallingFruits[i];
if (!fruit.isActive) {
continue;
}
if (fruit.state === 'cuttable') {
var dx = x - fruit.x;
var dy = y - fruit.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist <= fruit.radius * fruit.scaleX) {
fruit.cut();
if (fruit.cutZoneCircle) {
fruit.cutZoneCircle.destroy();
fruit.cutZoneCircle = null;
}
LK.getSound('cut').play();
// Animación de corte para todas las frutas: mostrar sprite partido, NO el círculo blanco
var fruitCut = new FruitCut();
fruitCut.init(fruit.fruitType, fruit.x, fruit.y, fruit.rotation, fruit.scaleX);
game.addChild(fruitCut);
// Asegura que la línea negra esté sobre las frutas cortadas pero debajo del cañón
if (horizontalLine && horizontalLine.parent) {
horizontalLine.parent.removeChild(horizontalLine);
game.addChild(horizontalLine);
}
// Asegura que el cañón siempre esté al frente
if (cannon && cannon.parent) {
cannon.parent.removeChild(cannon);
game.addChild(cannon);
}
fruitCut.animate(function () {
fruitCut.destroy();
});
cutFruits.push(fruitCut);
frutasGeneradas++;
updateScore(LK.getScore() + 1);
return;
}
}
}
}
game.down = function (x, y, obj) {
tryCutFruit(x, y);
};
// Main update
game.update = function () {
// Permitir corte nuevamente tras 6 ticks (~100ms)
if (!canCut && LK.ticks - lastTouchTick > 6) {
canCut = true;
}
// --- SISTEMA DE BALAS POR RONDA (5 balas, 1s entre cada una, 7s delay antes de mostrar en pantalla superior) ---
if (typeof roundState === "undefined") {
// Estados posibles: 'waiting', 'spawning', 'waitingFruits'
roundState = 'waiting';
roundBullets = 7; // 3 countdown + 4 fruits
roundFruitsQueue = [];
roundFruitsActive = [];
roundNextBulletTick = LK.ticks + 30; // primer disparo tras 0.5s
roundBulletsFired = 0;
roundDelayBetweenRounds = 120; // 2s entre rondas
roundDelayTicks = 0;
}
if (roundState === 'waiting') {
// Limpiar arrays de frutas y mitades cortadas de la ronda anterior
for (var i = fruits.length - 1; i >= 0; i--) {
if (fruits[i]) {
fruits[i].destroy();
}
}
fruits = [];
for (var i = fallingFruits.length - 1; i >= 0; i--) {
if (fallingFruits[i]) {
fallingFruits[i].destroy();
}
}
fallingFruits = [];
for (var i = cutFruits.length - 1; i >= 0; i--) {
if (cutFruits[i]) {
cutFruits[i].destroy();
}
}
cutFruits = [];
// Limpiar arrays de control de ronda
if (typeof roundFruitsQueue !== "undefined") {
for (var i = roundFruitsQueue.length - 1; i >= 0; i--) {
if (roundFruitsQueue[i] && roundFruitsQueue[i].destroy) {
roundFruitsQueue[i].destroy();
}
}
}
roundFruitsQueue = [];
if (typeof roundFruitsActive !== "undefined") {
for (var i = roundFruitsActive.length - 1; i >= 0; i--) {
if (roundFruitsActive[i] && roundFruitsActive[i].destroy) {
roundFruitsActive[i].destroy();
}
}
}
roundFruitsActive = [];
// Reset meta de ronda
roundBulletsFired = 0;
roundNextBulletTick = LK.ticks;
roundDelayTicks = 0;
countdownObjectsFired = 0; // Reset countdown counter
// Esperar un frame antes de permitir el spawn para evitar generación múltiple
if (typeof roundJustReset === "undefined" || !roundJustReset) {
roundJustReset = true;
return;
} else {
roundJustReset = false;
roundState = 'spawning';
}
}
if (roundState === 'spawning') {
// Disparar los objetos de cuenta regresiva "1", "2", "Go" en los primeros tres disparos
if (typeof countdownObjectsFired === "undefined") {
countdownObjectsFired = 0;
}
if (roundBulletsFired < roundBullets && LK.ticks >= roundNextBulletTick) {
var margin = 180;
var fruitX = margin + Math.random() * (2048 - 2 * margin);
cannon.x = fruitX;
cannon.show();
cannon.shoot();
// Dispara "1", "2", "Go" en los primeros tres disparos
if (countdownObjectsFired === 0) {
var obj1 = new CountdownOne();
obj1.x = fruitX;
obj1.y = 2732 + obj1.radius - 120;
obj1.startY = obj1.y;
obj1.targetY = 2732 / 2 + 600;
obj1.state = 'rising';
obj1.ticks = 0;
obj1.roundMeta = {
hasCrossed: false,
crossedTick: null,
showScheduled: false,
showTimeout: null,
destroyed: false
};
fruits.push(obj1);
roundFruitsQueue.push(obj1);
game.addChild(obj1);
// Mostrar "1" centrado y gigante con fade out
var centerObj1 = new CountdownOne();
centerObj1.x = 2048 / 2;
centerObj1.y = 2732 / 2;
centerObj1.scaleX = centerObj1.scaleY = 5; // Gigante
centerObj1.alpha = 1;
game.addChild(centerObj1);
// Fade out después de 0.5 segundos
LK.setTimeout(function () {
tween(centerObj1, {
alpha: 0
}, {
duration: 300,
easing: tween.linear,
onFinish: function onFinish() {
centerObj1.destroy();
}
});
}, 500);
countdownObjectsFired++;
} else if (countdownObjectsFired === 1) {
var obj2 = new CountdownTwo();
obj2.x = fruitX;
obj2.y = 2732 + obj2.radius - 120;
obj2.startY = obj2.y;
obj2.targetY = 2732 / 2 + 600;
obj2.state = 'rising';
obj2.ticks = 0;
obj2.roundMeta = {
hasCrossed: false,
crossedTick: null,
showScheduled: false,
showTimeout: null,
destroyed: false
};
fruits.push(obj2);
roundFruitsQueue.push(obj2);
game.addChild(obj2);
// Mostrar "2" centrado y gigante con fade out
var centerObj2 = new CountdownTwo();
centerObj2.x = 2048 / 2;
centerObj2.y = 2732 / 2;
centerObj2.scaleX = centerObj2.scaleY = 5; // Gigante
centerObj2.alpha = 1;
game.addChild(centerObj2);
// Fade out después de 0.5 segundos
LK.setTimeout(function () {
tween(centerObj2, {
alpha: 0
}, {
duration: 300,
easing: tween.linear,
onFinish: function onFinish() {
centerObj2.destroy();
}
});
}, 500);
countdownObjectsFired++;
} else if (countdownObjectsFired === 2) {
var objGo = new CountdownGo();
objGo.x = fruitX;
objGo.y = 2732 + objGo.radius - 120;
objGo.startY = objGo.y;
objGo.targetY = 2732 / 2 + 600;
objGo.state = 'rising';
objGo.ticks = 0;
objGo.roundMeta = {
hasCrossed: false,
crossedTick: null,
showScheduled: false,
showTimeout: null,
destroyed: false
};
fruits.push(objGo);
roundFruitsQueue.push(objGo);
game.addChild(objGo);
// Mostrar "Go!" centrado y gigante con fade out
var centerObjGo = new CountdownGo();
centerObjGo.x = 2048 / 2;
centerObjGo.y = 2732 / 2;
centerObjGo.scaleX = centerObjGo.scaleY = 5; // Gigante
centerObjGo.alpha = 1;
game.addChild(centerObjGo);
// Fade out después de 0.5 segundos
LK.setTimeout(function () {
tween(centerObjGo, {
alpha: 0
}, {
duration: 300,
easing: tween.linear,
onFinish: function onFinish() {
centerObjGo.destroy();
}
});
}, 500);
countdownObjectsFired++;
// Set next bullet time to 1 second after GO!
roundNextBulletTick = LK.ticks + 60; // 1 second delay
} else if (countdownObjectsFired >= 3) {
// Spawn fruits after countdown
var fruit = new Fruit();
fruit.x = fruitX;
fruit.y = 2732 + fruit.radius - 120;
fruit.startY = fruit.y;
fruit.targetY = 2732 / 2 + 600;
fruit.state = 'rising';
fruit.ticks = 0;
fruit.roundMeta = {
hasCrossed: false,
crossedTick: null,
showScheduled: false,
showTimeout: null,
destroyed: false
};
fruits.push(fruit);
roundFruitsQueue.push(fruit);
game.addChild(fruit);
// Set next bullet time to 1 second later
roundNextBulletTick = LK.ticks + 60; // 1 second between fruits
}
// Asegura que el cañón siempre esté al frente
if (cannon && cannon.parent) {
cannon.parent.removeChild(cannon);
game.addChild(cannon);
}
roundBulletsFired++;
roundNextBulletTick = LK.ticks + 30; // 0.5s entre balas (120 BPM)
}
// Cuando todas las balas han sido disparadas y ya no quedan frutas activas, pasar a siguiente estado
// (pero solo cuando todas las frutas hayan sido destruidas o salidas de pantalla)
var allGone = true;
for (var i = 0; i < roundFruitsQueue.length; i++) {
if (!roundFruitsQueue[i].roundMeta.destroyed) {
allGone = false;
break;
}
}
for (var i = 0; i < roundFruitsActive.length; i++) {
if (!roundFruitsActive[i].roundMeta.destroyed) {
allGone = false;
break;
}
}
if (roundBulletsFired >= roundBullets && allGone) {
// Oculta el cañón al terminar la ronda
if (cannon) {
cannon.hide();
}
roundState = 'waitingFruits';
roundDelayTicks = 0;
}
}
if (roundState === 'waitingFruits') {
// Espera 2s antes de reiniciar la ronda
roundDelayTicks++;
if (roundDelayTicks >= roundDelayBetweenRounds) {
// Limpiar arrays de frutas activas y en cola antes de reiniciar la ronda
for (var i = fruits.length - 1; i >= 0; i--) {
if (fruits[i]) {
fruits[i].destroy();
}
}
fruits = [];
for (var i = fallingFruits.length - 1; i >= 0; i--) {
if (fallingFruits[i]) {
fallingFruits[i].destroy();
}
}
fallingFruits = [];
for (var i = cutFruits.length - 1; i >= 0; i--) {
if (cutFruits[i]) {
cutFruits[i].destroy();
}
}
cutFruits = [];
roundFruitsQueue = [];
roundFruitsActive = [];
roundState = 'waiting';
}
}
// Mover frutas que suben desde abajo hasta el centro
for (var i = fruits.length - 1; i >= 0; i--) {
var fruit = fruits[i];
if (fruit.state === 'rising') {
fruit.y -= fruitSpeed;
fruit.ticks++;
// Escalado según altura (más arriba, más grande)
var minScale = 1.0;
var maxScale = 1.25;
var y0 = 2732 + fruit.radius + 10;
var y1 = 2732 / 2 + 420;
var t = (fruit.y - y1) / (y0 - y1);
if (t < 0) {
t = 0;
}
if (t > 1) {
t = 1;
}
var scale = minScale + (maxScale - minScale) * (1 - t);
fruit.scaleX = fruit.scaleY = scale;
// Rotación en la parte de abajo (solo mientras sube)
if (typeof fruit.rotation === "undefined") {
fruit.rotation = Math.random() * Math.PI * 2;
}
if (typeof fruit.rotationSpeed === "undefined") {
fruit.rotationSpeed = (Math.random() - 0.5) * 0.08;
}
fruit.rotation += fruit.rotationSpeed;
if (fruit.fruitAsset) {
fruit.fruitAsset.rotation = fruit.rotation;
}
// Cuando cruza la altura objetivo (centro), programar aparición en pantalla superior tras un tiempo proporcional al número de frutas lanzadas
if (!fruit.roundMeta.hasCrossed && fruit.y <= fruit.targetY) {
fruit.roundMeta.hasCrossed = true;
fruit.roundMeta.crossedTick = LK.ticks;
fruit.visible = false;
// Only schedule top appearance for fruits, not countdown objects
if (fruit.fruitType && fruit.fruitAsset) {
// El tiempo de espera es igual a 1s * cantidad de frutas lanzadas en la ronda
var fruitsInRound = 4; // Solo las 4 frutas
var appearDelayMs = fruitsInRound * 1000; // 1s por fruta lanzada
fruit.roundMeta.showScheduled = true;
fruit.roundMeta.showTimeout = LK.setTimeout(function () {
if (!fruit.roundMeta.destroyed && fruit.isActive) {
// Create falling fruit from top
var fallingFruit = new Fruit();
fallingFruit.x = Math.random() * (2048 - 200) + 100;
fallingFruit.y = 420;
fallingFruit.fruitType = fruit.fruitType;
// Re-create the asset with the same type
fallingFruit.fruitAsset.destroy();
fallingFruit.fruitAsset = fallingFruit.attachAsset(fruit.fruitType, {
anchorX: 0.5,
anchorY: 0.5
});
fallingFruit.state = 'cuttable';
fallingFruit.roundMeta = {
hasCrossed: false,
crossedTick: null,
showScheduled: false,
showTimeout: null,
destroyed: false
};
fallingFruits.push(fallingFruit);
roundFruitsActive.push(fallingFruit);
game.addChild(fallingFruit);
}
// Mark original fruit as destroyed
fruit.roundMeta.destroyed = true;
fruit.destroy();
}, appearDelayMs);
}
}
// Si la fruta está oculta y esperando, no hacer nada más
if (fruit.roundMeta.hasCrossed && fruit.roundMeta.showScheduled) {
// Si la fruta fue destruida antes de los 7s, cancelar timeout y limpiar
if (fruit.roundMeta.destroyed) {
if (fruit.roundMeta.showTimeout) {
LK.clearTimeout(fruit.roundMeta.showTimeout);
fruit.roundMeta.showTimeout = null;
}
// Eliminar de roundFruitsQueue si está presente
if (typeof roundFruitsQueue !== "undefined") {
for (var j = roundFruitsQueue.length - 1; j >= 0; j--) {
if (roundFruitsQueue[j] === fruit) {
roundFruitsQueue.splice(j, 1);
break;
}
}
}
fruits.splice(i, 1);
}
continue;
}
// Si la fruta sale de pantalla antes de cruzar, eliminar y marcar como destruida
if (fruit.y < -fruit.radius) {
// BAJA MUCHO MÁS el umbral de desaparición inferior
fruit.roundMeta.destroyed = true;
if (fruit.roundMeta.showTimeout) {
LK.clearTimeout(fruit.roundMeta.showTimeout);
fruit.roundMeta.showTimeout = null;
}
// Eliminar de roundFruitsQueue si está presente
if (typeof roundFruitsQueue !== "undefined") {
for (var j = roundFruitsQueue.length - 1; j >= 0; j--) {
if (roundFruitsQueue[j] === fruit) {
roundFruitsQueue.splice(j, 1);
break;
}
}
}
// Aumentar frutasFalladas si la fruta se perdió antes de aparecer
frutasFalladas++;
frutasGeneradas++;
fruit.destroy();
fruits.splice(i, 1);
}
}
}
// Mover frutas que suben de nuevo y gestionar zona de corte visual
// --- Asegura que la línea negra esté sobre los sprites de las frutas en cada frame ---
if (horizontalLine && horizontalLine.parent) {
horizontalLine.parent.removeChild(horizontalLine);
game.addChild(horizontalLine);
}
for (var i = fallingFruits.length - 1; i >= 0; i--) {
var fruit = fallingFruits[i];
if (!fruit.isActive) {
continue;
}
// Escalado según altura (más arriba, más grande)
var minScale = 1.0;
var maxScale = 1.25 * 1.3 * 1.3; //{45} // 60% más grande en la parte superior
var y0 = 2732 / 2 + 420;
var y1 = 420;
var t = (fruit.y - y1) / (y0 - y1);
if (t < 0) {
t = 0;
}
if (t > 1) {
t = 1;
}
var scale = minScale + (maxScale - minScale) * (1 - t);
fruit.scaleX = fruit.scaleY = scale;
// Rotación suave
if (typeof fruit.rotationSpeed !== "undefined") {
fruit.rotation += fruit.rotationSpeed;
if (fruit.fruitAsset) {
fruit.fruitAsset.rotation = fruit.rotation;
}
}
// Movimiento hacia arriba mientras sea cortable o volando hacia arriba
if (fruit.state === 'cuttable' || fruit.state === 'flyingup') {
fruit.y -= fruitSpeed;
}
// --- Animación progresiva del círculo de corte ---
// El círculo aparece desde el inicio de la subida (cuttable), crece y se difumina progresivamente
if (fruit.state === 'cuttable') {
// Si no existe el círculo, crearlo
if (!fruit.cutZoneCircle) {
fruit.cutZoneCircle = LK.getAsset('cut_zone', {
anchorX: 0.5,
anchorY: 0.5,
x: fruit.x,
y: fruit.y,
alpha: 0.0,
scaleX: 0.1,
scaleY: 0.1
});
game.addChild(fruit.cutZoneCircle);
// Asegura que la línea negra esté sobre el círculo de corte pero debajo del cañón
if (horizontalLine && horizontalLine.parent) {
horizontalLine.parent.removeChild(horizontalLine);
game.addChild(horizontalLine);
}
// Asegura que el cañón siempre esté al frente
if (cannon && cannon.parent) {
cannon.parent.removeChild(cannon);
game.addChild(cannon);
}
}
// Progresión del círculo: desde que inicia la subida hasta que llega cerca de la parte superior
var appearT = (y0 - fruit.y) / (y0 - y1);
if (appearT < 0) {
appearT = 0;
}
if (appearT > 1) {
appearT = 1;
}
var maxScaleZone = 0.85; // Más pequeño, para que quede dentro de la fruta
var minScaleZone = 0.15;
var maxAlpha = 0.38; // Más difuminado
var minAlpha = 0.08;
var scaleZone = minScaleZone + (maxScaleZone - minScaleZone) * appearT;
var alphaZone = minAlpha + (maxAlpha - minAlpha) * appearT;
fruit.cutZoneCircle.scaleX = fruit.cutZoneCircle.scaleY = scaleZone;
fruit.cutZoneCircle.alpha = alphaZone;
fruit.cutZoneCircle.x = fruit.x;
fruit.cutZoneCircle.y = fruit.y;
// Si la fruta sale por arriba, eliminar círculo y pasar a flyingup
if (fruit.y < y1) {
// Si el círculo de corte existe y la fruta no fue cortada, contar como fallada
if (fruit.cutZoneCircle) {
fruit.cutZoneCircle.destroy();
fruit.cutZoneCircle = null;
if (fruit.isActive && !fruit.isCut) {
frutasFalladas++;
frutasGeneradas++;
}
}
fruit.state = 'flyingup';
}
} else {
// Si no está en estado cortable y existe el círculo, destruirlo
if (fruit.cutZoneCircle) {
fruit.cutZoneCircle.destroy();
fruit.cutZoneCircle = null;
}
}
// Si fue cortada, eliminar círculo visual inmediatamente pero mantener la fruta visible
if (!fruit.isActive && fruit.cutZoneCircle) {
fruit.cutZoneCircle.destroy();
fruit.cutZoneCircle = null;
}
// Si está cayendo, animar caída
if (fruit.state === 'dropping') {
fruit.dropSpeed += 2.5; // gravedad
fruit.y += fruit.dropSpeed;
// Escalado decreciente al caer
fruit.scaleX = fruit.scaleY = Math.max(0.7, fruit.scaleX - 0.01);
if (fruit.cutZoneCircle) {
fruit.cutZoneCircle.x = fruit.x;
fruit.cutZoneCircle.y = fruit.y;
}
// Si sale de pantalla, marcar como inactivo pero mantener visible
if (fruit.y > 2732 + fruit.radius + 20) {
if (fruit.cutZoneCircle) {
fruit.cutZoneCircle.destroy();
fruit.cutZoneCircle = null;
}
fruit.isActive = false;
}
}
// Si la fruta sigue subiendo después de la zona de corte y no fue cortada
if (fruit.state === 'flyingup') {
// Al entrar por primera vez en flyingup, inicia temporizador de espera
if (typeof fruit.waitTicks === "undefined") {
fruit.waitTicks = 0;
}
fruit.waitTicks++;
// Mantener la fruta visible y estática durante 7 segundos (420 ticks)
if (fruit.waitTicks < 420) {
// Mantener posición (opcional: podrías hacer que siga subiendo lentamente)
// fruit.y -= fruitSpeed * 0.1;
} else {
// Después de 7 segundos, hacer que suba y desaparezca
fruit.y -= fruitSpeed;
// Escalado sigue creciendo un poco
fruit.scaleX = fruit.scaleY = Math.min(maxScale, fruit.scaleX + 0.01);
// Si sale de pantalla por arriba, marcar como inactiva y eliminar círculo de corte si existe
if (fruit.y < -fruit.radius - 20) {
if (fruit.cutZoneCircle) {
fruit.cutZoneCircle.destroy();
fruit.cutZoneCircle = null;
}
fruit.isActive = false;
// Marcar como destruida para el sistema de ronda
if (fruit.roundMeta) {
fruit.roundMeta.destroyed = true;
}
// Eliminar de roundFruitsActive si está presente
if (typeof roundFruitsActive !== "undefined") {
for (var j = roundFruitsActive.length - 1; j >= 0; j--) {
if (roundFruitsActive[j] === fruit) {
roundFruitsActive.splice(j, 1);
break;
}
}
}
// Aumentar frutasFalladas y frutasGeneradas solo si la fruta no fue cortada
if (!fruit.isCut) {
frutasFalladas++;
frutasGeneradas++;
}
}
}
}
// Si la fruta ya fue cortada o salió de pantalla, eliminar
if (!fruit.isActive || fruit.y > 2732 + fruit.radius + 20 || fruit.y < -fruit.radius - 20) {
if (fruit.cutZoneCircle) {
fruit.cutZoneCircle.destroy();
fruit.cutZoneCircle = null;
}
// Marcar como destruida para el sistema de ronda
if (fruit.roundMeta) {
fruit.roundMeta.destroyed = true;
}
// Eliminar de roundFruitsActive si está presente
if (typeof roundFruitsActive !== "undefined") {
for (var j = roundFruitsActive.length - 1; j >= 0; j--) {
if (roundFruitsActive[j] === fruit) {
roundFruitsActive.splice(j, 1);
break;
}
}
}
fruit.destroy();
fallingFruits.splice(i, 1);
}
}
// Limpiar mitades cortadas que ya terminaron animación
for (var i = cutFruits.length - 1; i >= 0; i--) {
var fc = cutFruits[i];
if (!fc.left || !fc.right) {
if (fc.destroy) {
fc.destroy();
}
cutFruits.splice(i, 1);
}
}
// Variable para controlar el timeout (debe estar fuera de la función que chequea frutasFalladas)
if (roundBulletsFired >= 3 && roundState === 'waitingFruits') {
// Mostrar los sprites 1, 2, Go en el centro con fade in/fade out rápido solo una vez, SOLO al inicio del juego
if ((typeof showCountdownInMiddleDone === "undefined" || !showCountdownInMiddleDone) && LK.ticks < 120) {
showCountdownInMiddleDone = true;
var centerX = 2048 / 2;
var centerY = 2732 / 2;
var countdownSprites = [{
cls: CountdownOne,
delay: 0
}, {
cls: CountdownTwo,
delay: 350
}, {
cls: CountdownGo,
delay: 700
}];
for (var idx = 0; idx < countdownSprites.length; idx++) {
(function (idx) {
var conf = countdownSprites[idx];
LK.setTimeout(function () {
var obj = new conf.cls();
obj.x = centerX;
obj.y = centerY;
obj.alpha = 0;
game.addChild(obj);
// Fade in rápido
tween(obj, {
alpha: 1
}, {
duration: 180,
easing: tween.cubicOut,
onFinish: function onFinish() {
// Fade out rápido
tween(obj, {
alpha: 0
}, {
duration: 180,
delay: 180,
easing: tween.cubicIn,
onFinish: function onFinish() {
obj.destroy();
}
});
}
});
}, conf.delay);
})(idx);
}
}
if (!frutasFalladasTimeout) {
frutasFalladasTimeout = LK.setTimeout(function () {
for (var i = fruits.length - 1; i >= 0; i--) {
if (fruits[i]) {
fruits[i].destroy();
}
}
fruits = [];
for (var i = fallingFruits.length - 1; i >= 0; i--) {
if (fallingFruits[i]) {
fallingFruits[i].destroy();
}
}
fallingFruits = [];
for (var i = cutFruits.length - 1; i >= 0; i--) {
if (cutFruits[i]) {
cutFruits[i].destroy();
}
}
cutFruits = [];
if (typeof roundFruitsQueue !== "undefined") {
for (var i = roundFruitsQueue.length - 1; i >= 0; i--) {
if (roundFruitsQueue[i] && roundFruitsQueue[i].destroy) {
roundFruitsQueue[i].destroy();
}
}
}
roundFruitsQueue = [];
if (typeof roundFruitsActive !== "undefined") {
for (var i = roundFruitsActive.length - 1; i >= 0; i--) {
if (roundFruitsActive[i] && roundFruitsActive[i].destroy) {
roundFruitsActive[i].destroy();
}
}
}
roundFruitsActive = [];
// No reiniciar el estado, terminar el juego después de los countdown
LK.showGameOver();
}, 2000);
}
return;
}
};
updateScore(0);
Kiwi Fruta con ojos lindos. In-Game asset. 2d. High contrast. No shadows. Cartoon.
Limon Circular Fruta con ojos lindos. In-Game asset. 2d. High contrast. No shadows. Cartoon.
Naranja Circular Fruta con ojos lindos. In-Game asset. 2d. High contrast. No shadows. Cartoon.
Manzana Fruta con ojos lindos. In-Game asset. 2d. High contrast. No shadows. Cartoon.
Ciruela Fruta con ojos lindos. In-Game asset. 2d. High contrast. No shadows. Cartoon.
Manzana Fruta cortada a la mitad. In-Game asset. 2d. High contrast. No shadows. Cartoon.
Kiwi Fruta cortado por la mitad. In-Game asset. 2d. High contrast. No shadows. Cartoon.
Limon Circular Cortado por la mitad. In-Game asset. 2d. High contrast. No shadows. Cartoon.
Naranja Circular Cortada por la mitad. In-Game asset. 2d. High contrast. No shadows. Cartoon.
Ciruela Fruta cortada por la mitad. In-Game asset. 2d. High contrast. No shadows. Cartoon.
Agrega una rueda en la parte trasera del cañon.
En lugar del numero 2 un numero 1
Letars GO! dentro del circulo.
Red cicle thiner but maintan the image size
En lugar del numero 1 un numero 2
Puedes hacer varias imagenes reemplazando el numero 2 por los numeros 3, 4, 5, 6, 7 y 8? Solo debe haber un numero en cada imagen.
En lugar del numero 3 un numero 4
En lugar del numero 4 un numero 5
En lugar del numero 5 un numero 6
En lugar del numero 6 un numero 7
En lugar del numero 1 un numero 8
En lugar del numero 1 un numero 9
En lugar del numero 9 un numero 10
En lugar del numero 1 un numero 11
Boton de juego que diga "START". In-Game asset. 2d. High contrast. No shadows
Boton de juego que diga "RESTART". In-Game asset. 2d. High contrast. No shadows
Boton de juego Azul que diga "MENU". In-Game asset. 2d. High contrast. No shadows
Un fondo colorido y brillante estilo caricatura. La escena es un bosque abierto alegre con colores pastel vibrantes, formas suaves y redondeadas, y un cielo azul claro con nubes esponjosas. El estilo es kawaii, juguetón y fantástico, con líneas suaves y una atmósfera feliz y amigable, perfecto para una introducción divertida y cute de un juego. In-Game asset. 2d. High contrast. No shadows
"Beat the Fruit" titulo para el juego, muestra las letras en grande blancas con un borde negro y sin fondo, con algunas frutitas felices junto a las letras. In-Game asset. 2d. High contrast. No shadows
Barra verde horizontal estilo caricatura.. In-Game asset. 2d. High contrast. No shadows