User prompt
puedes acomodar las musicas en los assets en orden numerico
User prompt
revisa en los assets la musica y verifica cuales faltan y agregalas
User prompt
al entrar por la pare superior de la pantalla en decenso gana doble de puntos
User prompt
hala que suene en su nivel
User prompt
haz cambio de color a cada nivel
User prompt
asegurate de play musi2 en el nivel2, play music3 en el nivel3 y asi cada nicel segun su numero numero music
User prompt
play musica que corresponde a cada nivel
User prompt
nivel30 play musica30
User prompt
nivel2 play musica2, nivel3 play musica3, nivel5 play musica5 nivel6 play musica6, nivel7 play musica7, nivel8 play musica8, nivel9 play musica9, nivel10 play musica10, nivel11 play musica11, nivel2 play musica12, nivel13 play musica13, nivel14 play musica14, nivel15 play musica15, nivel16 play musica16, nivel17 play musica17, nivel18 play musica18 nivel19 play musica19, nivel20 play musica20, nivel21 play musica21, nivel22 play musica22, nivel24 play musica24, nivel25 play musica25, nivel26 play musica26, nivel27 play musica27, nivel28 play musica28, nivel29 play musica29
User prompt
dale un color diferente a cada cambio de nivel, nivel1 uncolor diferente a nivel2 y asi los demas hasta el ultimo, el ultimo ya no es el 30, sino el subnivel 30-8
User prompt
dale un color diferente a cada cambio de nivel, nivel1 uncolor diferente a nivel2 y asi los demas hasta el ultimo, el ultimo ya no es el 30, sino el subnivel 150-8
User prompt
cambia el color al con overlay add background lines 150 variantes de colores, desde morado, azul, azul claro, verde, amarillo, rojo, gradualmente en tonalidades un color a cada nivel
User prompt
al iniciar nivel1 has fadeout stop a musicainicio
User prompt
play musica nivel1 musica1, play nivel2 musica2, play nivel3 musica3, play nivel4 musica4, play nivel5 musica5, play nivel6 musica6 y asi progresivamente en todos los niveles
User prompt
en el nivel2 play musica2, en el nivel3 play musica3 en el nivel4 play musica4 y asi todos los demas niveles segun su numero
User prompt
asegurate de que cada nivel de play a su musica
User prompt
play musica nivel1 musica1, play nivel2 musica2, play nivel3 musica3, play nivel4 musica4, play nivel5 musica5, play nivel6 musica6 y asi progresivamente en todos los niveles
User prompt
play musica nivel1 musica1, nivel2 musica2, nivel3 musica3, nivel4 musica4, nivel5 musica5, nivel6 musica6 y asi progresivamente en todos los niveles
User prompt
play musica nivel1 musica1, nivel2 musica2, nivel3 musica3, nivel4 musica4, nivel5 musica5, nivel6 musica6 y asi progresivamente en todos los niveles excepto Musicainicio
User prompt
no play Musicainicio en todos los niveles
User prompt
play musica nivel1 musica1, nivel2 musica2, nivel3 musica3, nivel4 musica4, nivel5 musica5, nivel6 musica6 y asi progresivamente en todos los niveles
User prompt
coloca el background a todos los niveles
User prompt
background lines fos all stages
User prompt
play musica nivel1 musica1, nivel2 musica2, nivel3 musica3, nivel4 musica4, nivel5 musica5, nivel6 musica6 y asi progresivamente en todos los niveles
User prompt
colocale la musica correspondiente a cada nivel
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // Define Bonus class var Bonus = Container.expand(function () { var self = Container.call(this); // Attach a bonus asset (use a star-like color and ellipse shape for visibility) var bonusGraphics = self.attachAsset('bonus', { anchorX: 0.5, anchorY: 0.5 }); // Orbit parameters self.orbitRadius = 170; // Default closer to center, will be overridden in Game Code self.orbitAngle = Math.random() * Math.PI * 2; // Random start // self.orbitSpeed will be set per instance in Game Code // Update method for orbiting self.update = function () { self.orbitAngle += self.orbitSpeed; self.x = 1024 + self.orbitRadius * Math.cos(self.orbitAngle); self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle); }; return self; }); // Define Deco class var Deco = Container.expand(function () { var self = Container.call(this); // Use the 'deco' asset from Assets section var decoGraphics = self.attachAsset('deco', { anchorX: 0.5, anchorY: 0.5 }); // Optionally, scale for visual distinction decoGraphics.scaleX = 1.5; decoGraphics.scaleY = 1.5; // Deco does not move or update by default, but you can add animation here if needed self.orbitRadius = 170; // Default to match average bonus orbit, will be overridden in Game Code self.orbitAngle = Math.random() * Math.PI * 2; self.orbitSpeed = -0.03; // Slower by default, will be overridden in Game Code if needed self.update = function () { self.orbitAngle += self.orbitSpeed; self.x = 1024 + self.orbitRadius * Math.cos(self.orbitAngle); self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle); }; return self; }); // Position near the top // Define Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); // Attach default 'enemy' asset (restored to default color and shape) var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); // Orbit parameters (will be set per instance in Game Code) self.orbitRadius = 400; // Default, will be overridden self.orbitAngle = Math.random() * Math.PI * 2; self.orbitSpeed = -0.03; // Default, will be overridden // Elliptical orbit support (optional, set in Game Code) self.isElliptical = false; self.ellipseA = undefined; self.ellipseB = undefined; // Update method for orbiting and rotation (like Deco) self.update = function () { self.orbitAngle += self.orbitSpeed; if (self.isElliptical && typeof self.ellipseA === "number" && typeof self.ellipseB === "number") { self.x = 1024 + self.ellipseA * Math.cos(self.orbitAngle); self.y = 1366 + self.ellipseB * Math.sin(self.orbitAngle); } else { self.x = 1024 + self.orbitRadius * Math.cos(self.orbitAngle); self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle); } }; return self; }); // Define Player class var Player = Container.expand(function () { var self = Container.call(this); // Attach player asset var playerGraphics = self.attachAsset('Ballplayer', { anchorX: 0.5, anchorY: 0.5 }); // Set initial position and movement properties self.speed = 2.5; // Lowered for better perception // Update method for player movement self.update = function () { // Freeze player if gameplay is not enabled if (typeof gameplayEnabled !== "undefined" && !gameplayEnabled) { return; } // Movement handled by keyboard events }; }); /**** * Initialize Game ****/ // Reset Assets section to initial state // Reset Asteroid class definition //<Assets used in the game will automatically appear here> // Reset Planet class definition // Reset Star class definition // Reset Initialize Game section to initial state // Reset Game Code section to initial state var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // (Removed 'COSMIC ORBITS' title text from main screen) // State variable: true if main screen is active, false if gameplay is active // (musica1 is never played on main screen. Only MusicaInicio is played here.) // musica1 will only play when gameplay starts, never on main screen var mainScreenActive = true; // Main screen container (cover all game area) var mainScreenContainer = new Container(); mainScreenContainer.x = 0; mainScreenContainer.y = 0; // Add a background image for the main screen (Titulo-rectangulo) var portadaBg = LK.getAsset('Titulo-rectangulo', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366, scaleX: 2048 / 1800, scaleY: 2732 / 1062 }); mainScreenContainer.addChild(portadaBg); // Floating animation for portadaBg (Titulo-rectangulo) function animatePortadaBgFloat() { // Animate y up by 32px, then down by 32px, loop tween(portadaBg, { y: portadaBg.y - 32 }, { duration: 1200, easing: tween.sineInOut, onFinish: function onFinish() { tween(portadaBg, { y: portadaBg.y + 32 }, { duration: 1200, easing: tween.sineInOut, onFinish: animatePortadaBgFloat }); } }); } animatePortadaBgFloat(); // Move portadaBg to the very front of the entire game (above all objects/enemies/UI except LK.gui overlays) if (portadaBg.parent) { portadaBg.parent.removeChild(portadaBg); } game.addChild(portadaBg); // (Removed static decorative 'deco' asset from main screen) // (Removed 'COSMIC ORBITS' title text from main screen) // Nueva frase arriba del título principal (actualizada) var portadaSubtitle = new Text2('Eres un punto en la tormenta... todo lo demás te aplastará.', { size: 74, fill: 0xA020F0, font: "'Impact','Arial Black',Tahoma" }); portadaSubtitle.anchor.set(0.5, 0.5); portadaSubtitle.x = 1024; // Coloca la frase aún más arriba del título principal (portadaBg está centrado en y:1366, altura 500) portadaSubtitle.y = 1366 - 520; // 520px arriba del centro del título (más arriba) mainScreenContainer.addChild(portadaSubtitle); // Circular START button (purple, lower position, and larger) var startBtn = LK.getAsset('home', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 2000, // moved further down width: 480, // enlarged height: 480, // enlarged color: 0xA020F0 // purple }); if (typeof startBtn.tint !== "undefined") { startBtn.tint = 0xA020F0; } mainScreenContainer.addChild(startBtn); // "INICIAR" text on button, a bit larger font size var startBtnText = new Text2('INICIAR', { size: 110, // a bit larger text for the button fill: 0xFFFFFF, font: "'Impact','Arial Black',Tahoma" }); startBtnText.anchor.set(0.5, 0.5); startBtnText.x = 1024; startBtnText.y = 2000; // match button position mainScreenContainer.addChild(startBtnText); // Add Info1 asset to the main splash screen (mainScreenContainer) for animation start var infoIcon = LK.getAsset('Info', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 2035 // Moved up by 5px }); // Insert infoIcon as the first child so it is rendered behind startBtn and startBtnText mainScreenContainer.addChildAt(infoIcon, 0); // --- RECORD NUMBER ON MAIN SPLASH --- // Calculate record value from storage (same logic as in main game) var splashRecord = 0; var splashStoredRecord = storage.record; if (splashStoredRecord !== null && splashStoredRecord !== undefined) { splashStoredRecord = parseInt(splashStoredRecord); if (!isNaN(splashStoredRecord)) { splashRecord = splashStoredRecord; } } // Add 'Record' label above the record number var splashRecordLabel = new Text2('Record', { size: 120, fill: 0xA020F0, font: "'Impact','Arial Black',Tahoma" }); splashRecordLabel.anchor.set(0.5, 0); splashRecordLabel.x = 1024; splashRecordLabel.y = 340; // 80px above the number (adjust as needed) mainScreenContainer.addChild(splashRecordLabel); // Create a larger Text2 for the record number (no label, just the number) var splashRecordText = new Text2('' + splashRecord, { size: 320, // Increased size for more prominence fill: 0xA020F0, font: "'Impact','Arial Black',Tahoma" }); splashRecordText.anchor.set(0.5, 0); // Position: at the very top center, leaving a margin for the platform menu (100px) // Move it down by 300px (was 120px from the top) splashRecordText.x = 1024; splashRecordText.y = 420; // 120 + 300 = 420px from the top mainScreenContainer.addChild(splashRecordText); // Animate infoIcon from Info1 to Info2 using tween plugin, and loop the animation // Helper function to loop the Info <-> Info2 animation function loopInfoIconAnimation() { // Remove any previous infoIcon2 if present if (typeof infoIcon2 !== "undefined" && infoIcon2 && infoIcon2.parent) { infoIcon2.parent.removeChild(infoIcon2); } // Create Info2 asset at the same position, but invisible infoIcon2 = LK.getAsset('Info2', { anchorX: 0.5, anchorY: 0.5, x: infoIcon.x, y: infoIcon.y, alpha: 0 }); mainScreenContainer.addChildAt(infoIcon2, 0); // Animate crossfade: Info1 alpha 1->0, Info2 alpha 0->1 tween(infoIcon, { alpha: 0 }, { duration: 700, easing: tween.cubicInOut }); tween(infoIcon2, { alpha: 1 }, { duration: 700, easing: tween.cubicInOut, onFinish: function onFinish() { // After a short delay, crossfade back to Info1 LK.setTimeout(function () { // Animate crossfade: Info2 alpha 1->0, Info1 alpha 0->1 // Re-add infoIcon if it was removed if (!infoIcon.parent) { mainScreenContainer.addChildAt(infoIcon, 0); } tween(infoIcon2, { alpha: 0 }, { duration: 700, easing: tween.cubicInOut }); tween(infoIcon, { alpha: 1 }, { duration: 700, easing: tween.cubicInOut, onFinish: function onFinish() { // Remove Info2 after animation, keep Info1 if (infoIcon2.parent) infoIcon2.parent.removeChild(infoIcon2); // Loop again after a short delay LK.setTimeout(loopInfoIconAnimation, 600); } }); }, 600); } }); } // Start the animation loop after a short delay var infoIcon2; LK.setTimeout(loopInfoIconAnimation, 600); // Add main screen container to the game (on top of everything) game.addChild(mainScreenContainer); // Stop all music on main screen LK.stopMusic(); // Play MusicaInicio only on main screen (main menu/splash) LK.playMusic('MusicaInicio', { loop: true, volume: 1 }); // musica1 will only play when gameplay starts, never on main screen // (musica1 is never played on main screen. Only MusicaInicio is played here.) // Block gameplay until start is pressed var gameplayEnabled = false; // Helper to enable gameplay and remove main screen function startGameFromMainScreen() { if (!mainScreenActive) { return; } mainScreenActive = false; gameplayEnabled = true; // Set currentLevel to 1 and currentSubLevel to 1 when gameplay starts (main is not a level) currentLevel = 1; currentSubLevel = 1; // Hide the title, subtitle, and Titulo-rectangulo when starting the game if (typeof portadaSubtitle !== "undefined" && portadaSubtitle && portadaSubtitle.parent) { portadaSubtitle.parent.removeChild(portadaSubtitle); } if (typeof startBtnText !== "undefined" && startBtnText && startBtnText.parent) { startBtnText.parent.removeChild(startBtnText); } if (typeof portadaBg !== "undefined" && portadaBg && portadaBg.parent) { portadaBg.parent.removeChild(portadaBg); } if (mainScreenContainer && mainScreenContainer.parent) { mainScreenContainer.parent.removeChild(mainScreenContainer); } // Ensure only one music track plays at a time and prevent overlap when starting gameplay // Fade out MusicaInicio before stopping it LK.playMusic('MusicaInicio', { fade: { start: 1, end: 0, duration: 800 } }); LK.setTimeout(function () { LK.stopMusic(); // When gameplay starts, always stop MusicaInicio and play musica1 for level 1 if (typeof currentLevel !== "undefined" && currentLevel === 1) { LK.playMusic('musica1', { loop: true, volume: 1 }); game._lastMusicPlayed = 'musica1'; game._lastMusicLevel = 1; } }, 800); // (musica1 is only played here, never on main screen) // Move player to starting position at the bottom of the screen player.x = 1024; player.y = 2632; player.radius = Math.sqrt((player.x - centerX) * (player.x - centerX) + (player.y - centerY) * (player.y - centerY)); player.angle = Math.atan2(player.y - centerY, player.x - centerX); // Reset all gameplay variables to initial state // (Handled by LK/game reset, but you can reset here if needed) game._gameOverTriggered = false; } // Touch/click handler for main screen mainScreenContainer.down = function (x, y, obj) { // Only respond if tap/click is inside the start button area var dx = x - startBtn.x; var dy = y - startBtn.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist <= startBtn.width * 0.5) { startGameFromMainScreen(); } }; // Block all gameplay input until gameplayEnabled is true var originalGameDown = game.down; game.down = function (x, y, obj) { if (!gameplayEnabled) { return; } if (typeof originalGameDown === "function") { originalGameDown(x, y, obj); } }; var originalGameUp = game.up; game.up = function (x, y, obj) { if (!gameplayEnabled) { return; } if (typeof originalGameUp === "function") { originalGameUp(x, y, obj); } }; var originalGameUpdate = game.update; game.update = function () { if (!gameplayEnabled) { return; } if (typeof originalGameUpdate === "function") { originalGameUpdate(); } }; // Helper to generate a random pastel color // Add 'lines' asset as a background image, scaled to cover the game area function randomPastelColor() { var r = 180 + Math.floor(Math.random() * 75); var g = 180 + Math.floor(Math.random() * 75); var b = 180 + Math.floor(Math.random() * 75); return r << 16 | g << 8 | b; } // Store background asset and color for per-level colorization var bgLinesColor = randomPastelColor(); var bgLines = LK.getAsset('lines', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366, scaleX: 2048 / 573.44, scaleY: 2732 / 1019.45 }); bgLines.alpha = 0.2; bgLines.color = bgLinesColor; if (typeof bgLines.tint !== "undefined") { bgLines.tint = bgLinesColor; } game.addChildAt(bgLines, 0); // Add as the very first child (background) // Import tween plugin for color cycling // Reduced collision function: returns true if a and b are within a reduced collision range (scale < 1 for smaller hitbox) function reducedCollision(a, b, scale) { if (!a || !b || !a.children || !b.children || !a.children[0] || !b.children[0]) { return false; } var aw = a.children[0].width * scale, ah = a.children[0].height * scale; var bw = b.children[0].width * scale, bh = b.children[0].height * scale; var dx = a.x - b.x, dy = a.y - b.y; var dist = Math.sqrt(dx * dx + dy * dy); var minDist = (Math.max(aw, ah) + Math.max(bw, bh)) * 0.5 * 0.5; return dist < minDist; } // Stages configuration object var stages = {}; // --- Create 11 stage objects, each on its own outward orbit --- var stages = []; var stageCount = 11; var baseStageRadius = 200; var stageRadiusStep = 80; // Each stage is 80px further out for (var i = 0; i < stageCount; i++) { var stage = new Container(); var stageGraphics = stage.attachAsset('stage', { anchorX: 0.5, anchorY: 0.5 }); stage.orbitRadius = baseStageRadius + i * stageRadiusStep; stage.orbitSpeed = -3.5 * (0.24 + i * 0.024); // Increased speed: rotate opposite to bonuses stage.orbitAngle = Math.random() * Math.PI * 2; stage.isStage = true; // Mark for clarity // --- Multicolor cycling effect using tween --- (function (stageGraphics, i) { // Define a set of bright, vivid colors to cycle through var colorCycle = [0x7fff4f, // apple green 0xffa500, // orange 0xff5ef7, // pink 0xff3b3b, // red 0x00e0ff, // light blue 0x3b6cff, // blue 0xc54ce4, // purple 0xfff200 // yellow ]; var colorIndex = i % colorCycle.length; var nextColorIndex = (colorIndex + 1) % colorCycle.length; var tweenDuration = 900 + Math.floor(Math.random() * 600); // Vary duration for each stage function tweenToNextColor() { var fromColor = colorCycle[colorIndex]; var toColor = colorCycle[nextColorIndex]; // Animate color property using tween (correct API) tween(stageGraphics, { color: toColor }, { duration: tweenDuration, easing: tween.linear, onFinish: function onFinish() { colorIndex = nextColorIndex; nextColorIndex = (colorIndex + 1) % colorCycle.length; tweenToNextColor(); } }); } // Set initial color and start cycling stageGraphics.color = colorCycle[colorIndex]; if (typeof stageGraphics.tint !== "undefined") { stageGraphics.tint = stageGraphics.color; } tweenToNextColor(); })(stageGraphics, i); // --- End multicolor cycling effect --- stage.update = function () { this.orbitAngle += this.orbitSpeed; this.x = 1024 + this.orbitRadius * Math.cos(this.orbitAngle); this.y = 1366 + this.orbitRadius * Math.sin(this.orbitAngle); }; stage.setSize = function (newSize) { // Defensive: Only allow positive numbers if (typeof newSize === "number" && newSize > 0) { // The asset is always the first child if (this.children && this.children.length > 0 && this.children[0]) { var asset = this.children[0]; // Set both width and height to newSize (ellipse remains circular) asset.width = newSize; asset.height = newSize; } } }; game.addChild(stage); stages.push(stage); } // Add a player to the game var player = game.addChild(new Player()); // Add 12 deco objects, all sharing the same orbit (same radius, speed, and direction) var decos = []; var decoCount = 12; var sharedDecoOrbitRadius = 800; // Increased: All decos on a wider orbit var sharedDecoOrbitSpeed = -0.9; // Reduced deco orbit speed (was -1.2) for (var i = 0; i < decoCount; i++) { var deco = game.addChild(new Deco()); // Assign a random light color to the deco's graphics if (deco.children && deco.children.length > 0 && deco.children[0]) { var r = 200 + Math.floor(Math.random() * 56); var g = 200 + Math.floor(Math.random() * 56); var b = 200 + Math.floor(Math.random() * 56); var lightColor = r << 16 | g << 8 | b; deco.children[0].color = lightColor; if (typeof deco.children[0].tint !== "undefined") { deco.children[0].tint = lightColor; } } deco.orbitRadius = sharedDecoOrbitRadius; deco.orbitAngle = Math.PI * 2 / decoCount * i; deco.orbitSpeed = sharedDecoOrbitSpeed; decos.push(deco); } // Duplicate the outer deco orbit: add a second set of 12 decos on the same outer orbit, offset for visual separation var decosOuter2 = []; for (var i = 0; i < decoCount; i++) { var deco2 = game.addChild(new Deco()); // Assign a random light color to the deco's graphics if (deco2.children && deco2.children.length > 0 && deco2.children[0]) { var r = 200 + Math.floor(Math.random() * 56); var g = 200 + Math.floor(Math.random() * 56); var b = 200 + Math.floor(Math.random() * 56); var lightColor = r << 16 | g << 8 | b; deco2.children[0].color = lightColor; if (typeof deco2.children[0].tint !== "undefined") { deco2.children[0].tint = lightColor; } } deco2.orbitRadius = sharedDecoOrbitRadius; deco2.orbitAngle = Math.PI * 2 / decoCount * i + Math.PI / decoCount; // offset for separation deco2.orbitSpeed = sharedDecoOrbitSpeed; decosOuter2.push(deco2); } // Add a third deco orbit, now with a larger radius for a bigger outer deco ring var decosOuter3 = []; var sharedDecoOuter3OrbitRadius = sharedDecoOrbitRadius + 200; // Increased: much larger than outer orbits var sharedDecoOuter3OrbitSpeed = sharedDecoOrbitSpeed; // Same speed as other outer orbits for (var i = 0; i < decoCount; i++) { var deco3 = game.addChild(new Deco()); // Assign a random light color to the deco's graphics if (deco3.children && deco3.children.length > 0 && deco3.children[0]) { var r = 200 + Math.floor(Math.random() * 56); var g = 200 + Math.floor(Math.random() * 56); var b = 200 + Math.floor(Math.random() * 56); var lightColor = r << 16 | g << 8 | b; deco3.children[0].color = lightColor; if (typeof deco3.children[0].tint !== "undefined") { deco3.children[0].tint = lightColor; } } deco3.orbitRadius = sharedDecoOuter3OrbitRadius; deco3.orbitAngle = Math.PI * 2 / decoCount * i + Math.PI / (decoCount * 2); // offset for visual separation deco3.orbitSpeed = sharedDecoOuter3OrbitSpeed; decosOuter3.push(deco3); } // Duplicate the largest deco orbit: add a second set of 12 decos on the same largest orbit, offset for visual separation var decosOuter3b = []; for (var i = 0; i < decoCount; i++) { var deco3b = game.addChild(new Deco()); // Assign a random light color to the deco's graphics if (deco3b.children && deco3b.children.length > 0 && deco3b.children[0]) { var r = 200 + Math.floor(Math.random() * 56); var g = 200 + Math.floor(Math.random() * 56); var b = 200 + Math.floor(Math.random() * 56); var lightColor = r << 16 | g << 8 | b; deco3b.children[0].color = lightColor; if (typeof deco3b.children[0].tint !== "undefined") { deco3b.children[0].tint = lightColor; } } deco3b.orbitRadius = sharedDecoOuter3OrbitRadius; deco3b.orbitAngle = Math.PI * 2 / decoCount * i + Math.PI / decoCount; // further offset for separation deco3b.orbitSpeed = sharedDecoOuter3OrbitSpeed; decosOuter3b.push(deco3b); } // Add a second deco orbit with half the radius and same count var decosInner = []; var sharedDecoInnerOrbitRadius = sharedDecoOrbitRadius / 2; for (var i = 0; i < decoCount; i++) { var decoInner = game.addChild(new Deco()); // Assign a random light color to the deco's graphics if (decoInner.children && decoInner.children.length > 0 && decoInner.children[0]) { var r = 200 + Math.floor(Math.random() * 56); var g = 200 + Math.floor(Math.random() * 56); var b = 200 + Math.floor(Math.random() * 56); var lightColor = r << 16 | g << 8 | b; decoInner.children[0].color = lightColor; if (typeof decoInner.children[0].tint !== "undefined") { decoInner.children[0].tint = lightColor; } decoInner.children[0].scaleX = 0.7; decoInner.children[0].scaleY = 0.7; } decoInner.orbitRadius = sharedDecoInnerOrbitRadius; decoInner.orbitAngle = Math.PI * 2 / decoCount * i + Math.PI / decoCount; // offset for visual separation decoInner.orbitSpeed = sharedDecoOrbitSpeed; decosInner.push(decoInner); } // Add 6 new enemies in a close orbit near the center var closeEnemyCount = 6; var closeEnemyOrbitRadius = 400; // Ampliado: más lejos del centro, pero aún dentro de la órbita de deco var closeEnemyOrbitSpeed = -0.003; // Reduced to 25% speed for enemy2 (slower) var closeEnemies = []; // Use the original first colors for close enemies, and assign each a unique color // Cambia el color rojo (0xe60000) por un verde brillante (0x00ff90) var originalColors = [0x00ff90, // bright green (antes era rojo) // strong red (reemplazado) // blue 0x484de8, // magenta 0xf30cdc, // cyan 0x00e0ff, // yellow 0xffeb5e, // blueish 0x4c7fb9]; var usedColors = []; var _loop = function _loop() { closeEnemy = game.addChild(new Enemy()); // Assign a random multicolor to the close enemy's graphics if (closeEnemy.children && closeEnemy.children.length > 0 && closeEnemy.children[0]) { var _tweenToNextColorEnemy2 = function tweenToNextColorEnemy2() { var fromColor = colorCycle[colorIndex]; var toColor = colorCycle[nextColorIndex]; tween(enemyGraphics, { color: toColor }, { duration: tweenDuration, easing: tween.linear, onFinish: function onFinish() { colorIndex = nextColorIndex; nextColorIndex = (colorIndex + 1) % colorCycle.length; _tweenToNextColorEnemy2(); } }); }; // Multicolor cycling effect for close enemies (enemy2) colorCycle = [0x7fff4f, // apple green 0xffa500, // orange 0xff5ef7, // pink 0xff3b3b, // red 0x00e0ff, // light blue 0x3b6cff, // blue 0xc54ce4, // purple 0xfff200 // yellow ]; colorIndex = Math.floor(Math.random() * colorCycle.length); nextColorIndex = (colorIndex + 1) % colorCycle.length; tweenDuration = 900 + Math.floor(Math.random() * 600); enemyGraphics = closeEnemy.children[0]; enemyGraphics.color = colorCycle[colorIndex]; if (typeof enemyGraphics.tint !== "undefined") { enemyGraphics.tint = enemyGraphics.color; } _tweenToNextColorEnemy2(); } closeEnemy.orbitRadius = closeEnemyOrbitRadius; closeEnemy.orbitAngle = Math.PI * 2 / closeEnemyCount * i; closeEnemy.orbitSpeed = closeEnemyOrbitSpeed; closeEnemies.push(closeEnemy); }, closeEnemy, colorCycle, colorIndex, nextColorIndex, tweenDuration, enemyGraphics; for (var i = 0; i < closeEnemyCount; i++) { _loop(); } // Removed orbitingEnemy from the deco orbit var orbitingEnemy = undefined; // Define orbits so that all 3 are separated by at least 600px (radius difference) // Minimum separation between orbits: 600px var orbits = [170, 770, 1100]; // Reduced the outermost orbit radius from 1370 to 1100 // Create more bonus objects, each occupying a unique orbit and distributed evenly var bonuses = []; var numBonuses = 8; // Increased from 3 to 8 for 'mas' for (var i = 0; i < numBonuses; i++) { var b = game.addChild(new Bonus()); b.orbitIndex = i; // Distribute bonuses across available orbits, cycling if more bonuses than orbits var orbitIdx = i % orbits.length; b.orbitRadius = orbits[orbitIdx]; // Increase bonus speed a little per level var bonusSpeedIncrease = typeof currentLevel !== "undefined" ? (currentLevel - 1) * 0.002 : 0; // Make outer bonuses orbit more slowly, inner ones faster var baseSpeed = 0.025; var minSpeed = 0.005; // Spread t from 0 (innermost) to 1 (outermost) based on orbit index var t = orbitIdx / (orbits.length - 1); var speed = baseSpeed * (1 - t) + minSpeed * t; b.orbitSpeed = speed + Math.random() * 0.007 + bonusSpeedIncrease * (0.5 + 0.5 * (1 - t)); // Distribute bonuses evenly around the circle b.orbitAngle = Math.PI * 2 / numBonuses * i; bonuses.push(b); } // Add a new fast-orbiting object (superBonus) that orbits faster than all bonuses var superBonus = game.addChild(new Bonus()); superBonus.orbitIndex = 3; // Not on the same orbits as bonuses, but can use a new or existing radius superBonus.orbitRadius = 320; // Reduced radius to keep inside screen // Increase superBonus speed a little per level var superBonusSpeedIncrease = typeof currentLevel !== "undefined" ? (currentLevel - 1) * 0.003 : 0; // 0.003 per level (was 0.006) superBonus.orbitSpeed = 0.18 + Math.random() * 0.04 + superBonusSpeedIncrease; // Much faster than normal bonuses superBonus.orbitAngle = Math.random() * Math.PI * 2; // (Removed unnecessary update of deco.orbitRadius) // Add level number display at the top center of the screen var levelText = new Text2('Nivel 1', { size: 100, fill: 0xFFFFFF, font: "'Impact','Arial Black',Tahoma" }); levelText.anchor.set(0.5, 0); // Center horizontally, top edge LK.gui.top.addChild(levelText); // Add record display below the level display at the top center, with "Record" label smaller and number larger, stacked vertically and centered var recordLabelText = new Text2('Record', { size: 90, fill: 0xA020F0, font: "'Impact','Arial Black',Tahoma" }); recordLabelText.anchor.set(0.5, 0); // Center horizontally, top edge recordLabelText.y = levelText.height + 10; // 10px below levelText recordLabelText.visible = false; recordLabelText.alpha = 0.75; LK.gui.top.addChild(recordLabelText); var recordTopText = new Text2('0', { size: 260, fill: 0xA020F0, font: "'Impact','Arial Black',Tahoma" }); recordTopText.anchor.set(0.5, 0); // Center horizontally, top edge recordTopText.y = recordLabelText.y + recordLabelText.height - 10; // Stack number below label, slight overlap for tightness recordTopText.visible = false; recordTopText.alpha = 0.75; LK.gui.top.addChild(recordTopText); // Hide record display by default (already set above), will show on game over // Update levelText to show the current level at game start if (typeof currentLevel !== "undefined" && typeof levelText !== "undefined" && levelText.setText) { levelText.setText('Nivel ' + currentLevel); } // Update recordTopText to show the current record at game start if (typeof record !== "undefined" && typeof recordTopText !== "undefined" && recordTopText.setText) { recordTopText.setText('' + record); } // Add score display at the bottom center in purple, only the number and centered var score = 0; var scoreText = new Text2('0', { size: 100, fill: 0xA020F0, // purple font: "'Impact','Arial Black',Tahoma" }); scoreText.anchor.set(0.5, 1); // Centered horizontally, bottom edge LK.gui.bottom.addChild(scoreText); // Record is persisted using storage plugin var record = 0; var storedRecord = storage.record; if (storedRecord !== null && storedRecord !== undefined) { storedRecord = parseInt(storedRecord); if (!isNaN(storedRecord)) { record = storedRecord; } } // --- LIVES SYSTEM --- // Number of lives (default 9) var lives = 9; var maxLives = 9; // Display lives (hearts) below the 'Nivel' text at the top center (GUI coordinates) var livesHearts = []; var heartSpacing = 70; // px between hearts var heartSize = 64; // asset size // Remove old livesText if present if (typeof livesText !== "undefined" && livesText && livesText.parent) { livesText.parent.removeChild(livesText); } var livesText = undefined; // Create a container for hearts and add to LK.gui.top var livesContainer = new Container(); LK.gui.top.addChild(livesContainer); // Position livesContainer below the levelText // levelText is anchored at (0.5, 0), so its y is 0 livesContainer.x = 0; // Will be centered by anchor livesContainer.y = levelText.height + 90; // Much further below 'Nivel' (was 10) // Center the container horizontally at the top center livesContainer.anchorX = 0.5; livesContainer.anchorY = 0; // Create and add heart assets for each life, positioned in the container for (var i = 0; i < maxLives; i++) { var heart = LK.getAsset('heart8bit', { anchorX: 0.5, anchorY: 0.5, x: (i - (maxLives - 1) / 2) * heartSpacing, y: 0, width: heartSize, height: heartSize }); livesContainer.addChild(heart); livesHearts.push(heart); } // Helper to update lives display (show/hide hearts) function updateLivesText() { for (var i = 0; i < maxLives; i++) { if (livesHearts[i]) { livesHearts[i].visible = i < lives; // Optionally, fade out lost hearts livesHearts[i].alpha = i < lives ? 1 : 0.25; } } } updateLivesText(); // Hide record display at the start of the game if (typeof recordTopText !== "undefined") { recordTopText.visible = false; } if (typeof recordLabelText !== "undefined") { recordLabelText.visible = false; } // Set initial position of the player // If main screen is active, retain player below the screen until start if (mainScreenActive) { player.x = 1024; // Center horizontally player.y = 2832; // 200px below the bottom edge (off screen) } else { player.x = 1024; // Center horizontally player.y = 2632; // Always at the bottom (100px from bottom edge) } // Store the center of the screen for easy reference var centerX = 1024; var centerY = 1366; // Define orbits var orbits = [110, 170, 230]; // Track the player's current angle and radius from the center player.angle = Math.atan2(player.y - centerY, player.x - centerX); player.radius = Math.sqrt((player.x - centerX) * (player.x - centerX) + (player.y - centerY) * (player.y - centerY)); // Keyboard controls removed for compatibility; player movement is now handled by other means. // Function to find the next closest orbit function getNextOrbit(currentY) { var currentOrbit = 2732 - currentY; for (var i = 0; i < orbits.length; i++) { if (orbits[i] > currentOrbit) { return 2732 - orbits[i]; } ; // --- Super Bonus object update and collision (fastest orbiting object) --- if (typeof superBonus !== "undefined" && superBonus) { superBonus.update(); if (superBonus.lastWasIntersecting === undefined) { superBonus.lastWasIntersecting = false; } var sbIntersecting = reducedCollision(superBonus, player, 1.0); if (!superBonus.lastWasIntersecting && sbIntersecting) { // Player just collected the super bonus! score += 200; if (typeof scoreText !== "undefined" && scoreText.setText) { scoreText.setText('' + score); } // Update record if needed if (score > record) { record = score; storage.record = record; } if (typeof pointsText !== "undefined" && pointsText.setText) { pointsText.setText('Record: ' + record); } // Update recordTopText at the top center as well if (typeof recordTopText !== "undefined" && recordTopText.setText) { recordTopText.setText('' + record); } // Move superBonus to a new random angle and randomize its speed (always fast) superBonus.orbitAngle = Math.random() * Math.PI * 2; var superBonusSpeedIncrease = typeof currentLevel !== "undefined" ? (currentLevel - 1) * 0.003 : 0; // 0.003 per level (was 0.006) superBonus.orbitSpeed = 0.18 + Math.random() * 0.04 + superBonusSpeedIncrease; } superBonus.lastWasIntersecting = sbIntersecting; } ; // --- Deco fast counter-orbit update for all decos --- if (typeof decos !== "undefined" && decos.length) { for (var i = 0; i < decos.length; i++) { var deco = decos[i]; deco.orbitAngle += deco.orbitSpeed; deco.x = centerX + deco.orbitRadius * Math.cos(deco.orbitAngle); deco.y = centerY + deco.orbitRadius * Math.sin(deco.orbitAngle); // --- Collision detection: player initiates collision with deco --- if (player.lastWasIntersectingDeco === undefined) { player.lastWasIntersectingDeco = []; } if (player.lastWasIntersectingDeco[i] === undefined) { player.lastWasIntersectingDeco[i] = false; } var playerHitsDeco = reducedCollision(player, deco, 1.0); if (!player.lastWasIntersectingDeco[i] && playerHitsDeco) { // Player collides with deco: flash blue and handle lives/game over LK.effects.flashScreen(0x00e0ff, 1000); LK.getSound('Dead').play(); lives--; updateLivesText(); if (lives <= 0) { if (!game._gameOverTriggered) { game._gameOverTriggered = true; if (typeof recordTopText !== "undefined") { recordTopText.visible = true; } if (typeof recordLabelText !== "undefined") { recordLabelText.visible = true; } // Show score on game over if (typeof scoreText !== "undefined") { scoreText.visible = true; } LK.stopMusic(); // Delay game over to allow player to see the record LK.setTimeout(function () { LK.showGameOver(); }, 1500); } } else { // Respawn player at start position, restore visibility, reset radius/angle player.x = 1024; player.y = 2632; player.radius = Math.sqrt((player.x - centerX) * (player.x - centerX) + (player.y - centerY) * (player.y - centerY)); player.angle = Math.atan2(player.y - centerY, player.x - centerX); player.visible = true; } } player.lastWasIntersectingDeco[i] = playerHitsDeco; // --- Deco's own collision detection for legacy/compatibility --- if (deco.lastWasIntersecting === undefined) { deco.lastWasIntersecting = false; } var decoIntersecting = reducedCollision(deco, player, 1.0); if (!deco.lastWasIntersecting && decoIntersecting) { // Deco kills the player: flash blue and trigger game over LK.effects.flashScreen(0x00e0ff, 1000); // Play dead sound LK.getSound('Dead').play(); if (typeof recordTopText !== "undefined") { recordTopText.visible = true; } if (typeof recordLabelText !== "undefined") { recordLabelText.visible = true; } // Show score on game over if (typeof scoreText !== "undefined") { scoreText.visible = true; } // Delay game over to allow player to see the record LK.setTimeout(function () { LK.showGameOver(); }, 1500); } deco.lastWasIntersecting = decoIntersecting; // --- Deco kills playerball as well (if playerball is a different object) --- if (typeof playerball !== "undefined" && playerball) { if (deco.lastWasIntersectingPlayerball === undefined) { deco.lastWasIntersectingPlayerball = false; } var decoHitsPlayerball = reducedCollision(deco, playerball, 1.0); if (!deco.lastWasIntersectingPlayerball && decoHitsPlayerball) { LK.effects.flashScreen(0x00e0ff, 1000); // Play dead sound LK.getSound('Dead').play(); if (typeof recordTopText !== "undefined") { recordTopText.visible = true; } if (typeof recordLabelText !== "undefined") { recordLabelText.visible = true; } // Show score on game over if (typeof scoreText !== "undefined") { scoreText.visible = true; } // Delay game over to allow player to see the record LK.setTimeout(function () { LK.showGameOver(); }, 1500); } deco.lastWasIntersectingPlayerball = decoHitsPlayerball; } // --- Deco collides with playerball or player (combined logic) --- if (typeof playerball !== "undefined" && playerball) { if (deco.lastWasIntersectingPlayerOrBall === undefined) { deco.lastWasIntersectingPlayerOrBall = false; } var decoHitsPlayerOrBall = reducedCollision(deco, player, 1.0) || reducedCollision(deco, playerball, 1.0); if (!deco.lastWasIntersectingPlayerOrBall && decoHitsPlayerOrBall) { LK.effects.flashScreen(0x00e0ff, 1000); // Play dead sound LK.getSound('Dead').play(); if (typeof recordTopText !== "undefined") { recordTopText.visible = true; } if (typeof recordLabelText !== "undefined") { recordLabelText.visible = true; } // Show score on game over if (typeof scoreText !== "undefined") { scoreText.visible = true; } // Delay game over to allow player to see the record LK.setTimeout(function () { LK.showGameOver(); }, 1500); } deco.lastWasIntersectingPlayerOrBall = decoHitsPlayerOrBall; } else { // Only player exists if (deco.lastWasIntersectingPlayerOrBall === undefined) { deco.lastWasIntersectingPlayerOrBall = false; } var decoHitsPlayer = reducedCollision(deco, player, 1.0); if (!deco.lastWasIntersectingPlayerOrBall && decoHitsPlayer) { LK.effects.flashScreen(0x00e0ff, 1000); // Play dead sound LK.getSound('Dead').play(); if (typeof recordTopText !== "undefined") { recordTopText.visible = true; } if (typeof recordLabelText !== "undefined") { recordLabelText.visible = true; } // Show score on game over if (typeof scoreText !== "undefined") { scoreText.visible = true; } // Delay game over to allow player to see the record LK.setTimeout(function () { LK.showGameOver(); }, 1500); } deco.lastWasIntersectingPlayerOrBall = decoHitsPlayer; } } } } ; ; // Add a new orbit to the end of the array to create an infinite loop var newOrbit = orbits[orbits.length - 1] + 400; orbits.push(newOrbit); return 2732 - newOrbit; } // Track if right mouse button is held down var rightMouseDown = false; // Track if left mouse button is held down var leftMouseDown = false; // Track which direction the player should move: -1 for left, 1 for right, 0 for none var playerMoveDirection = 0; // Add event listener for mouse/touch down game.down = function (x, y, obj) { // x is in game coordinates (0 to 2048) if (x < 1024) { // Pressed on left half: move player right (clockwise) playerMoveDirection = 1; } else { // Pressed on right half: move player left (counterclockwise) playerMoveDirection = -1; } }; // Add event listener for mouse/touch up to stop moving game.up = function (x, y, obj) { playerMoveDirection = 0; }; // Set initial number of enemies for level 1 (3 enemies), and increase by 1 per level up to 30 levels // currentLevel is only set when gameplay starts, not on main screen if (typeof currentLevel === "undefined" || currentLevel === null) { var currentLevel = null; // Not set until gameplay starts } var maxLevels = 30; var enemies = []; function spawnEnemiesForLevel(level) { // Remove existing enemies from game for (var i = 0; i < enemies.length; i++) { if (enemies[i].parent) { enemies[i].parent.removeChild(enemies[i]); } } enemies = []; // Number of enemies increases by 1 per level, starting at 3, max 32 at level 30 var numEnemies = Math.min(3 + (level - 1), 3 + (maxLevels - 1)); // Amplified enemy orbits: increase all base radii for even wider orbits // Limit max enemy orbit to the outermost deco orbit var maxEnemyOrbitRadius = sharedDecoOuter3OrbitRadius; var baseRadii = [370, 540, 710, 880, 1050, 1220, 1390, 1560]; var _loop2 = function _loop2() { enemy = game.addChild(new Enemy()); // Assign a random multicolor to the enemy's graphics if (enemy.children && enemy.children.length > 0 && enemy.children[0]) { var _tweenToNextColorEnemy = function tweenToNextColorEnemy() { var fromColor = colorCycle[colorIndex]; var toColor = colorCycle[nextColorIndex]; tween(enemyGraphics, { color: toColor }, { duration: tweenDuration, easing: tween.linear, onFinish: function onFinish() { colorIndex = nextColorIndex; nextColorIndex = (colorIndex + 1) % colorCycle.length; _tweenToNextColorEnemy(); } }); }; // Multicolor cycling effect for main enemies (enemy) colorCycle = [0x7fff4f, // apple green 0xffa500, // orange 0xff5ef7, // pink 0xff3b3b, // red 0x00e0ff, // light blue 0x3b6cff, // blue 0xc54ce4, // purple 0xfff200 // yellow ]; colorIndex = Math.floor(Math.random() * colorCycle.length); nextColorIndex = (colorIndex + 1) % colorCycle.length; tweenDuration = 900 + Math.floor(Math.random() * 600); enemyGraphics = enemy.children[0]; enemyGraphics.color = colorCycle[colorIndex]; if (typeof enemyGraphics.tint !== "undefined") { enemyGraphics.tint = enemyGraphics.color; } _tweenToNextColorEnemy(); } enemy.x = 1024; enemy.y = 1366; // Distribute orbits and angles for variety baseRadius = baseRadii[i % baseRadii.length]; enemy.orbitRadius = baseRadius + Math.floor(Math.random() * 120); // Clamp to max deco orbit radius if (enemy.orbitRadius > maxEnemyOrbitRadius) { enemy.orbitRadius = maxEnemyOrbitRadius; } enemy.orbitAngle = Math.random() * Math.PI * 2; // Increase base orbit speed a little per level, but with much less noticeable increment (0.002% per level) var baseSpeed = 0.004 + Math.random() * 0.003; // New: 0.002% increment per level (0.00002 per level) var speedIncrease = typeof level !== "undefined" ? (level - 1) * 0.00002 : 0; enemy.orbitSpeed = baseSpeed + speedIncrease; // Alternate direction: odd = counterclockwise, even = clockwise if (i % 2 === 1) { enemy.orbitSpeed *= -1; enemy.isCounterClockwise = true; } else { enemy.isCounterClockwise = false; } enemy.speed = 1.2 + Math.random() * 1.5; // Add random direction change timer for some enemies enemy.canChangeDirection = Math.random() < 0.5; // 50% chance if (enemy.canChangeDirection) { enemy.directionChangeInterval = 60 + Math.floor(Math.random() * 120); // 1-3 seconds enemy.directionChangeTick = 0; } enemies.push(enemy); }, enemy, colorCycle, colorIndex, nextColorIndex, tweenDuration, enemyGraphics, baseRadius; for (var i = 0; i < numEnemies; i++) { _loop2(); } } // Spawn initial enemies for level 1 spawnEnemiesForLevel(currentLevel); // musica1 will play only when gameplay starts, never on main screen // (Removed Vertigo music at the start of the game, music stopped) if (typeof LK !== "undefined" && typeof LK.on === "function") { LK.on('gameover', function () { game._gameOverTriggered = false; }); } // Update method for orbiting game.update = function () { // Gravity: each frame, pull the player a bit toward the center if (typeof gameplayEnabled !== "undefined" && !gameplayEnabled) { // Gravity is paralyzed if the game has not started } else { if (typeof currentLevel === "undefined") { var gravityStrength = 2.2; } else { // Incrementa la gravedad de manera equitativa entre niveles (del 1 al 12, por ejemplo) var minGravity = 2.2; var maxGravity = 4.0; var totalLevels = 12; var levelClamped = Math.max(1, Math.min(currentLevel, totalLevels)); var gravityStrength = minGravity + (maxGravity - minGravity) * (levelClamped - 1) / (totalLevels - 1); } // Calculate vector from player to center var dx = centerX - player.x; var dy = centerY - player.y; var dist = Math.sqrt(dx * dx + dy * dy); // Only apply gravity if not already at center if (dist > 0.1) { // Normalize direction var nx = dx / dist; var ny = dy / dist; // Move player toward center by gravityStrength, but don't overshoot var moveDist = Math.min(gravityStrength, dist); player.x += nx * moveDist; player.y += ny * moveDist; // Update angle and radius for consistency with orbit logic player.angle = Math.atan2(player.y - centerY, player.x - centerX); player.radius = Math.sqrt((player.x - centerX) * (player.x - centerX) + (player.y - centerY) * (player.y - centerY)); } else { // Snap to center if extremely close player.x = centerX; player.y = centerY; player.angle = 0; player.radius = 0; } // --- Reduce player size by 30% as it approaches the center (70% at center) --- if (player && player.children && player.children.length > 0 && player.children[0]) { // At the outermost, player is 100% size; at the center, 70% size var minScale = 0.7; // 70% at the very center var maxScale = 1.0; // 100% at the outermost var maxRadius = 1200; // Approximate outermost orbit var minRadius = 0; // Center var r = Math.max(minRadius, Math.min(maxRadius, player.radius)); var scale = minScale + (maxScale - minScale) * (r / maxRadius); player.children[0].scaleX = scale; player.children[0].scaleY = scale; } } // Smooth and continuous player movement (rotation/orbit) if (typeof playerMoveDirection !== "undefined" && playerMoveDirection !== 0) { // Player rotation speed increases with level, similar to enemy speed scaling // Base moveSpeed is 0.012, increase by 0.0007 per level (same as enemy speedIncrease) var moveSpeed = 0.012 + (typeof currentLevel !== "undefined" ? currentLevel - 1 : 0) * 0.0007; player.angle += playerMoveDirection * moveSpeed; // Recalculate position based on new angle, keep radius player.x = centerX + player.radius * Math.cos(player.angle); player.y = centerY + player.radius * Math.sin(player.angle); } // --- LEVEL SYSTEM: Track and progress levels up to 30, with 5 sub-levels per level --- if (typeof currentLevel === "undefined" || currentLevel === null) { currentLevel = 1; var maxLevels = 30; } if (typeof currentSubLevel === "undefined" || currentSubLevel === null) { currentSubLevel = 1; } var maxSubLevels = 8; // Ensure only the correct stage music plays per main level, stopping all others and preventing overlap // Play musicaN for each main level N, but only for the levels listed in the goal if (typeof game._lastMusicLevel === "undefined") { game._lastMusicLevel = currentLevel; } if (typeof game._lastMusicPlayed === "undefined") { game._lastMusicPlayed = null; } // Play musicaN for each level, using the level number directly (e.g. level 2 = musica2, level 3 = musica3, etc.) if (game._lastMusicLevel !== currentLevel) { // Stop previous music (if any) if (typeof game._lastMusicPlayed !== "undefined" && game._lastMusicPlayed !== null) { LK.stopMusic(); game._lastMusicPlayed = null; } // Compose music id for this level var musicToPlay = "musica" + currentLevel; // Only play if the asset exists (defensive: check LK.assets.music) if (LK.assets && LK.assets.music && LK.assets.music[musicToPlay]) { LK.playMusic(musicToPlay, { loop: true, volume: 1 }); game._lastMusicPlayed = musicToPlay; game._lastMusicLevel = currentLevel; } } if (typeof levelText !== "undefined" && levelText.setText) { if (currentSubLevel === 1) { levelText.setText('Nivel ' + currentLevel); } else { levelText.setText('Nivel ' + currentLevel + '-' + (currentSubLevel - 1)); } } if (player.lastRadius === undefined) { player.lastRadius = player.radius; } // Check if player is within the center range (radius <= 30) and only advance when crossing into the center (from outside to inside) if (player.lastRadius === undefined) { player.lastRadius = player.radius; } if (!game._alreadyAdvancedLevel && player.lastRadius > 30 && player.radius <= 30) { // Player just reached the center, advance sub-level or main level game._alreadyAdvancedLevel = true; if (currentSubLevel < maxSubLevels) { currentSubLevel++; } else { // Advance main level if (currentLevel < 30) { // Helper to get color for current level/sublevel var _getBgColorForLevelSub = function _getBgColorForLevelSub(level, sub) { // Clamp to max 30-8 var l = Math.max(1, Math.min(30, level)); var s = Math.max(1, Math.min(8, sub)); var idx = (l - 1) * 8 + (s - 1); return levelBgColors[idx % levelBgColors.length]; }; currentLevel++; currentSubLevel = 1; // Music changes are now handled globally on main level transitions only // Define a unique color for each level and sublevel up to 30-8 if (typeof levelBgColors === "undefined") { var levelBgColors = []; // Use a palette of 40+ visually distinct colors (cycled if needed) var palette = [0x7fff4f, 0xffa500, 0xff5ef7, 0xff3b3b, 0x00e0ff, 0x3b6cff, 0xc54ce4, 0xfff200, 0x00ff90, 0x484de8, 0xf30cdc, 0x4c7fb9, 0x00ffea, 0xffb347, 0x8aff00, 0xff007f, 0x00ffb3, 0xffb3ff, 0x7f00ff, 0xffb300, 0x00b3ff, 0xb3ff00, 0xff003b, 0x3bff00, 0x003bff, 0xff00b3, 0xb300ff, 0x00ff3b, 0x3b00ff, 0xff3b00, 0x00b3b3, 0xb3b300, 0x3bb3ff, 0xffb33b, 0xb33bff, 0x3bffb3, 0xb3ff3b, 0xff3bb3, 0x3bb3b3, 0xb33bb3]; // There are 30 levels, each with 8 sublevels (1-8) for (var lvl = 1; lvl <= 30; lvl++) { for (var sub = 1; sub <= 8; sub++) { // For each sublevel, assign a color from the palette, cycling if needed var idx = ((lvl - 1) * 8 + (sub - 1)) % palette.length; levelBgColors.push(palette[idx]); } } // Add a color for the final sublevel 30-8 (if not already included) if (levelBgColors.length < 240) { levelBgColors.push(palette[239 % palette.length]); } } var prevBgLinesColor = bgLinesColor; bgLinesColor = _getBgColorForLevelSub(currentLevel, currentSubLevel); // Animate color transition using tween plugin if (typeof bgLines.tint !== "undefined") { tween(bgLines, { alpha: 0.05 }, { duration: 250, easing: tween.cubicIn, onFinish: function onFinish() { // Instantly set new color at lowest alpha bgLines.color = bgLinesColor; bgLines.tint = bgLinesColor; // Fade in strongly tween(bgLines, { alpha: 0.32 }, { duration: 650, easing: tween.cubicOut }); } }); } else { bgLines.color = bgLinesColor; } // Do NOT reset lives on new level updateLivesText(); // Hide record display at the start of a new level if (typeof recordTopText !== "undefined") { recordTopText.visible = false; } if (typeof recordLabelText !== "undefined") { recordLabelText.visible = false; } // Update level number display if (typeof levelText !== "undefined" && levelText.setText) { levelText.setText('Nivel ' + currentLevel + '-' + currentSubLevel); } // Always set number of enemies to 3 + (currentLevel - 1), up to 22 at level 30 spawnEnemiesForLevel(currentLevel); // Add rotation/orbit variants: some reverse, some elliptical for (var k = 0; k < enemies.length; k++) { // Every 3rd enemy or at higher levels, make elliptical orbits if ((k + currentLevel) % 3 === 0 && currentLevel > 4) { enemies[k].ellipseA = enemies[k].orbitRadius; enemies[k].ellipseB = Math.max(120, enemies[k].orbitRadius - 60 - Math.random() * 80); enemies[k].isElliptical = true; } else { enemies[k].isElliptical = false; } // Alternate direction for more chaos if (currentLevel > 6 && k % 2 === 0) { enemies[k].orbitSpeed = -Math.abs(enemies[k].orbitSpeed); } else { enemies[k].orbitSpeed = Math.abs(enemies[k].orbitSpeed); } // Apply much less noticeable increment to enemy speed on level up as well (0.002% per level) var baseSpeed = Math.abs(enemies[k].orbitSpeed); var speedIncrease = (currentLevel - 1) * 0.00002; enemies[k].orbitSpeed = (enemies[k].orbitSpeed < 0 ? -1 : 1) * (baseSpeed + speedIncrease); } // Reset player to starting position for next level (center bottom of the screen) player.x = 1024; // Center horizontally player.y = 2632; // 100px from bottom edge player.radius = Math.sqrt((player.x - centerX) * (player.x - centerX) + (player.y - centerY) * (player.y - centerY)); player.angle = Math.atan2(player.y - centerY, player.x - centerX); // Optionally, randomize enemy orbits a bit for variety for (var j = 0; j < enemies.length; j++) { enemies[j].orbitAngle = Math.random() * Math.PI * 2; } // --- Update bonuses and superBonus speed for new level --- for (var i = 0; i < bonuses.length; i++) { var bonusSpeedIncrease = (currentLevel - 1) * 0.002; // Make outer bonuses orbit more slowly, inner ones faster // REDUCED SPEED: Lowered all bonus orbit speeds for a much slower effect // For 3 orbits: 0=center, 1=extra inner, 2=outermost var baseSpeed = 0.025; // was 0.045, now even slower for innermost var minSpeed = 0.005; // was 0.01, now even slower for outermost var t = i / (bonuses.length - 1); // 0 for center, 0.5 for extra inner, 1 for outermost var speed = baseSpeed * (1 - t) + minSpeed * t; bonuses[i].orbitSpeed = speed + Math.random() * 0.007 + bonusSpeedIncrease * (0.5 + 0.5 * (1 - t)); // random range halved } var superBonusSpeedIncrease = (currentLevel - 1) * 0.003; // was 0.006 superBonus.orbitSpeed = 0.18 + Math.random() * 0.04 + superBonusSpeedIncrease; // --- End update bonuses and superBonus speed --- if (currentLevel === 30) { LK.showYouWin(); } } } // Always update levelText if (typeof levelText !== "undefined" && levelText.setText) { if (currentSubLevel === 1) { levelText.setText('Nivel ' + currentLevel); } else { levelText.setText('Nivel ' + currentLevel + '-' + (currentSubLevel - 1)); } } // Always set number of enemies to 3 + (currentLevel - 1), up to 22 at level 30 spawnEnemiesForLevel(currentLevel); // Reset player to starting position for next sub-level (center bottom of the screen) player.x = 1024; player.y = 2632; player.radius = Math.sqrt((player.x - centerX) * (player.x - centerX) + (player.y - centerY) * (player.y - centerY)); player.angle = Math.atan2(player.y - centerY, player.x - centerX); // Always update levelText for new sub-level if (typeof levelText !== "undefined" && levelText.setText) { if (currentSubLevel === 1) { levelText.setText('Nivel ' + currentLevel); } else { levelText.setText('Nivel ' + currentLevel + '-' + (currentSubLevel - 1)); } } // Update background color for every sublevel, including 30-8 if (typeof getBgColorForLevelSub === "function") { var prevBgLinesColor = bgLinesColor; bgLinesColor = getBgColorForLevelSub(currentLevel, currentSubLevel); if (typeof bgLines.tint !== "undefined") { tween(bgLines, { alpha: 0.05 }, { duration: 250, easing: tween.cubicIn, onFinish: function onFinish() { bgLines.color = bgLinesColor; bgLines.tint = bgLinesColor; tween(bgLines, { alpha: 0.32 }, { duration: 650, easing: tween.cubicOut }); } }); } else { bgLines.color = bgLinesColor; } } } // Allow level advance again only after player leaves the center if (player.radius > 30) { game._alreadyAdvancedLevel = false; } player.lastRadius = player.radius; // Move player towards the center if right mouse button is held down (extra boost) if (typeof rightMouseDown !== "undefined" && rightMouseDown) { // Each frame, move the player 3.5px closer to the center, but not below a minimum radius of 80 player.radius = Math.max(80, player.radius - 3.5); player.x = centerX + player.radius * Math.cos(player.angle); player.y = centerY + player.radius * Math.sin(player.angle); } // Rotate player if left mouse button is held down if (typeof leftMouseDown !== "undefined" && leftMouseDown) { player.angle += 0.035; // Slower, smoother rotation for perception // When rotating, accelerate gravity (move faster to center) player.radius = Math.max(80, player.radius - gravityStrength * 2.5); player.x = centerX + player.radius * Math.cos(player.angle); player.y = centerY + player.radius * Math.sin(player.angle); } // Update all miniparticles (if any) if (game.children && game.children.length) { for (var i = game.children.length - 1; i >= 0; i--) { var c = game.children[i]; if (c && typeof c.update === "function" && c.vx !== undefined && c.vy !== undefined && c.life !== undefined) { c.update(); } } } enemies.forEach(function (enemy) { // Randomly change direction if enabled, but only after 3 full orbits in one direction if (enemy.canChangeDirection) { if (enemy.directionChangeTick === undefined) { enemy.directionChangeTick = 0; } if (enemy.orbitDirectionStartAngle === undefined) { enemy.orbitDirectionStartAngle = enemy.orbitAngle; } if (enemy.orbitsInCurrentDirection === undefined) { enemy.orbitsInCurrentDirection = 0; } enemy.directionChangeTick++; // Calculate how many full orbits have been completed in the current direction var angleDiff = enemy.orbitAngle - enemy.orbitDirectionStartAngle; // Normalize to [0, 2PI) var fullOrbits = Math.abs(angleDiff) / (Math.PI * 2); // Only increment if we passed a full orbit since last check if (enemy.lastFullOrbits === undefined) { enemy.lastFullOrbits = 0; } if (Math.floor(fullOrbits) > enemy.lastFullOrbits) { enemy.orbitsInCurrentDirection += Math.floor(fullOrbits) - enemy.lastFullOrbits; enemy.lastFullOrbits = Math.floor(fullOrbits); } if (enemy.directionChangeTick >= enemy.directionChangeInterval && enemy.orbitsInCurrentDirection >= 3) { // Flip direction enemy.orbitSpeed *= -1; enemy.directionChangeTick = 0; // Reset orbit tracking for new direction enemy.orbitDirectionStartAngle = enemy.orbitAngle; enemy.orbitsInCurrentDirection = 0; enemy.lastFullOrbits = 0; // Optionally, randomize next interval enemy.directionChangeInterval = 60 + Math.floor(Math.random() * 120); } } enemy.orbitAngle += enemy.orbitSpeed; if (enemy.isElliptical) { // Elliptical orbit var a = enemy.ellipseA || enemy.orbitRadius; var b = enemy.ellipseB || enemy.orbitRadius - 60; enemy.x = centerX + a * Math.cos(enemy.orbitAngle); enemy.y = centerY + b * Math.sin(enemy.orbitAngle); } else { // Circular orbit enemy.x = centerX + enemy.orbitRadius * Math.cos(enemy.orbitAngle); enemy.y = centerY + enemy.orbitRadius * Math.sin(enemy.orbitAngle); } // --- Collision detection with player --- if (enemy.lastWasIntersecting === undefined) { enemy.lastWasIntersecting = false; } // Custom collision: reduce hitbox to 70% of asset size // Defined globally so it is available everywhere // This function is now defined globally at the top of Game Code for universal access function reducedCollision(a, b, scale) { if (!a || !b || !a.children || !b.children || !a.children[0] || !b.children[0]) { return false; } var aw = a.children[0].width * scale, ah = a.children[0].height * scale; var bw = b.children[0].width * scale, bh = b.children[0].height * scale; var dx = a.x - b.x, dy = a.y - b.y; var dist = Math.sqrt(dx * dx + dy * dy); var minDist = (Math.max(aw, ah) + Math.max(bw, bh)) * 0.5 * 0.5; return dist < minDist; } var isIntersecting = reducedCollision(enemy, player, 1.0); if (!enemy.lastWasIntersecting && isIntersecting) { // Collision just started, trigger miniparticle explosion and then handle lives/game over LK.effects.flashScreen(0xff0000, 1000); LK.getSound('Dead').play(); // Miniparticle explosion effect if (player && player.parent) { var miniparticleCount = 18; var miniparticleSpeed = 12; var miniparticleLifetime = 700; for (var mp = 0; mp < miniparticleCount; mp++) { var angle = Math.PI * 2 / miniparticleCount * mp + Math.random() * 0.2; var p = new Container(); var g = p.attachAsset('Ballplayer', { anchorX: 0.5, anchorY: 0.5 }); g.width = player.children[0].width * 0.22; g.height = player.children[0].height * 0.22; g.alpha = 0.85; p.x = player.x; p.y = player.y; p.vx = Math.cos(angle) * (miniparticleSpeed + Math.random() * 2); p.vy = Math.sin(angle) * (miniparticleSpeed + Math.random() * 2); p.life = miniparticleLifetime; p.update = function () { this.x += this.vx; this.y += this.vy; this.vx *= 0.96; this.vy *= 0.96; this.life -= 16; if (this.children[0]) { this.children[0].alpha = Math.max(0, this.children[0].alpha - 0.045); } if (this.life <= 0 && this.parent) { this.parent.removeChild(this); } }; game.addChild(p); } // Hide player immediately player.visible = false; // After miniparticleLifetime, handle lives/game over LK.setTimeout(function () { lives--; updateLivesText(); if (lives <= 0) { if (!game._gameOverTriggered) { game._gameOverTriggered = true; if (typeof recordTopText !== "undefined") { recordTopText.visible = true; } if (typeof recordLabelText !== "undefined") { recordLabelText.visible = true; } // Show score on game over if (typeof scoreText !== "undefined") { scoreText.visible = true; } // Delay game over to allow player to see the record LK.setTimeout(function () { LK.showGameOver(); }, 1500); } } else { // Respawn player at start position, restore visibility, reset radius/angle player.x = 1024; player.y = 2632; player.radius = Math.sqrt((player.x - centerX) * (player.x - centerX) + (player.y - centerY) * (player.y - centerY)); player.angle = Math.atan2(player.y - centerY, player.x - centerX); player.visible = true; } }, miniparticleLifetime); } else { lives--; updateLivesText(); if (lives <= 0) { if (!game._gameOverTriggered) { game._gameOverTriggered = true; if (typeof recordTopText !== "undefined") { recordTopText.visible = true; } if (typeof recordLabelText !== "undefined") { recordLabelText.visible = true; } // Show score on game over if (typeof scoreText !== "undefined") { scoreText.visible = true; } // Delay game over to allow player to see the record LK.setTimeout(function () { LK.showGameOver(); }, 1500); } } else { // Respawn player at start position, restore visibility, reset radius/angle player.x = 1024; player.y = 2632; player.radius = Math.sqrt((player.x - centerX) * (player.x - centerX) + (player.y - centerY) * (player.y - centerY)); player.angle = Math.atan2(player.y - centerY, player.x - centerX); player.visible = true; } } } enemy.lastWasIntersecting = isIntersecting; }); // --- enemy2 (closeEnemies and orbitingEnemy) kill the player on collision --- if (typeof closeEnemies !== "undefined" && closeEnemies.length) { for (var i = 0; i < closeEnemies.length; i++) { var cEnemy = closeEnemies[i]; if (cEnemy.lastWasIntersecting === undefined) { cEnemy.lastWasIntersecting = false; } var cEnemyIntersecting = reducedCollision(cEnemy, player, 1.0); if (!cEnemy.lastWasIntersecting && cEnemyIntersecting) { // enemy2 kills the player: flash red and handle lives/game over LK.effects.flashScreen(0xff0000, 1000); LK.getSound('Dead').play(); lives--; updateLivesText(); if (lives <= 0) { if (typeof recordTopText !== "undefined") { recordTopText.visible = true; } if (typeof recordLabelText !== "undefined") { recordLabelText.visible = true; } // Show score on game over if (typeof scoreText !== "undefined") { scoreText.visible = true; } // Delay game over to allow player to see the record LK.setTimeout(function () { LK.showGameOver(); }, 1500); } else { // Respawn player at start position, restore visibility, reset radius/angle player.x = 1024; player.y = 2632; player.radius = Math.sqrt((player.x - centerX) * (player.x - centerX) + (player.y - centerY) * (player.y - centerY)); player.angle = Math.atan2(player.y - centerY, player.x - centerX); player.visible = true; } } cEnemy.lastWasIntersecting = cEnemyIntersecting; } } if (typeof orbitingEnemy !== "undefined" && orbitingEnemy) { if (orbitingEnemy.lastWasIntersecting === undefined) { orbitingEnemy.lastWasIntersecting = false; } var oEnemyIntersecting = reducedCollision(orbitingEnemy, player, 1.0); if (!orbitingEnemy.lastWasIntersecting && oEnemyIntersecting) { LK.effects.flashScreen(0xff0000, 1000); LK.getSound('Dead').play(); lives--; updateLivesText(); if (lives <= 0) { if (typeof recordTopText !== "undefined") { recordTopText.visible = true; } if (typeof recordLabelText !== "undefined") { recordLabelText.visible = true; } // Show score on game over if (typeof scoreText !== "undefined") { scoreText.visible = true; } // Delay game over to allow player to see the record LK.setTimeout(function () { LK.showGameOver(); }, 1500); } else { // Respawn player at start position, restore visibility, reset radius/angle player.x = 1024; player.y = 2632; player.radius = Math.sqrt((player.x - centerX) * (player.x - centerX) + (player.y - centerY) * (player.y - centerY)); player.angle = Math.atan2(player.y - centerY, player.x - centerX); player.visible = true; } } orbitingEnemy.lastWasIntersecting = oEnemyIntersecting; } // --- Stage object update (orbiting) --- if (typeof stage !== "undefined" && stage) { stage.update(); } // --- Bonus objects update and collision (four bonuses, including superBonus) --- if (bonuses && bonuses.length) { for (var i = 0; i < bonuses.length; i++) { var bonus = bonuses[i]; bonus.update(); if (bonus.lastWasIntersecting === undefined) { bonus.lastWasIntersecting = false; } var bIntersecting = reducedCollision(bonus, player, 1.0); // --- Give 10 points each time the player enters/intersects the bonus (not continuously) --- if (!bonus.lastWasIntersecting && bIntersecting) { score += 10; // Give 10 points per entry/intersection if (typeof scoreText !== "undefined" && scoreText.setText) { scoreText.setText('' + score); } // Update record if needed if (score > record) { record = score; storage.record = record; } if (typeof pointsText !== "undefined" && pointsText.setText) { pointsText.setText('Record: ' + record); } // Update recordTopText at the top center as well if (typeof recordTopText !== "undefined" && recordTopText.setText) { recordTopText.setText('' + record); } } // --- End entry points --- // --- Always keep bonuses moving at higher speed --- // Increase bonus speed a lot for all orbits var bonusSpeedIncrease = typeof currentLevel !== "undefined" ? (currentLevel - 1) * 0.004 : 0; // double previous per-level increase // All bonuses are now much faster, even outermost var baseSpeed = 0.09; // was 0.025, now much faster for innermost var minSpeed = 0.045; // was 0.005, now much faster for outermost var t = bonus.orbitIndex / 2; // 0 for center, 0.5 for extra inner, 1 for outermost var speed = baseSpeed * (1 - t) + minSpeed * t; bonus.orbitSpeed = speed + Math.random() * 0.02 + bonusSpeedIncrease * (0.5 + 0.5 * (1 - t)); // random range increased bonus.lastWasIntersecting = bIntersecting; } } // --- Super Bonus (4th orbit) update and collision --- if (typeof superBonus !== "undefined" && superBonus) { superBonus.update(); if (superBonus.lastWasIntersecting === undefined) { superBonus.lastWasIntersecting = false; } var sbIntersecting = reducedCollision(superBonus, player, 1.0); // --- Give points CONTINUOUSLY while player is in superBonus area --- if (sbIntersecting) { score += 30; // Give 30 points per frame while in area (adjust as needed) if (typeof scoreText !== "undefined" && scoreText.setText) { scoreText.setText('' + score); } // Update record if needed if (score > record) { record = score; storage.record = record; } if (typeof pointsText !== "undefined" && pointsText.setText) { pointsText.setText('Record: ' + record); } // Update recordTopText at the top center as well if (typeof recordTopText !== "undefined" && recordTopText.setText) { recordTopText.setText('' + record); } } // --- End continuous points --- // --- Always keep superBonus moving at much higher speed --- var superBonusSpeedIncrease = typeof currentLevel !== "undefined" ? (currentLevel - 1) * 0.006 : 0; // double previous per-level increase superBonus.orbitSpeed = 0.36 + Math.random() * 0.08 + superBonusSpeedIncrease; // much faster than before superBonus.lastWasIntersecting = sbIntersecting; } // --- Heart-in-orbit for extra life, more frequent and in different orbits, only one at a time --- if (typeof heartOrbits === "undefined") { heartOrbits = []; } if (typeof lastHeartScore === "undefined") { lastHeartScore = 0; } if (typeof heartInOrbitActive === "undefined") { heartInOrbitActive = false; } if (typeof heartInOrbitObj === "undefined") { heartInOrbitObj = null; } if (typeof heartInOrbitTimeout === "undefined") { heartInOrbitTimeout = null; } if (typeof heartInOrbitNextScore === "undefined") { heartInOrbitNextScore = 250; // Start at 250 for first heart } // Appear every 250 points, but only one at a time if (!heartInOrbitActive && score >= heartInOrbitNextScore) { // Pick a random orbit from a wider set, including inner, mid, and outer deco orbits var possibleHeartOrbits = [sharedDecoInnerOrbitRadius, // inner deco sharedDecoInnerOrbitRadius + 60, sharedDecoInnerOrbitRadius - 30, sharedDecoOrbitRadius, // main deco sharedDecoOrbitRadius + 60, sharedDecoOrbitRadius - 30, sharedDecoOuter3OrbitRadius, // outermost deco sharedDecoOuter3OrbitRadius - 60]; // Only one heart at a time var heartOrbitRadius = possibleHeartOrbits[Math.floor(Math.random() * possibleHeartOrbits.length)]; // Randomize speed and direction var heartOrbitSpeed = (0.018 + Math.random() * 0.022) * (Math.random() < 0.5 ? 1 : -1); var heartOrbitAngle = Math.random() * Math.PI * 2; heartInOrbitObj = new Container(); var heartAsset = heartInOrbitObj.attachAsset('heart8bit', { anchorX: 0.5, anchorY: 0.5, width: 64, height: 64 }); heartInOrbitObj.orbitRadius = heartOrbitRadius; heartInOrbitObj.orbitSpeed = heartOrbitSpeed; heartInOrbitObj.orbitAngle = heartOrbitAngle; heartInOrbitObj.update = function () { this.orbitAngle += this.orbitSpeed; this.x = centerX + this.orbitRadius * Math.cos(this.orbitAngle); this.y = centerY + this.orbitRadius * Math.sin(this.orbitAngle); }; game.addChild(heartInOrbitObj); heartInOrbitActive = true; lastHeartScore = score; // Next heart at next 250 points heartInOrbitNextScore = score + 250; // Set a timeout to remove the heart after 10 seconds if not collected if (heartInOrbitTimeout) { LK.clearTimeout(heartInOrbitTimeout); heartInOrbitTimeout = null; } heartInOrbitTimeout = LK.setTimeout(function () { if (heartInOrbitActive && heartInOrbitObj) { if (heartInOrbitObj.parent) { heartInOrbitObj.parent.removeChild(heartInOrbitObj); } heartInOrbitActive = false; heartInOrbitObj = null; } heartInOrbitTimeout = null; }, 10000); } // If heart is active, update and check collision if (heartInOrbitActive && heartInOrbitObj) { heartInOrbitObj.update(); if (heartInOrbitObj.lastWasIntersecting === undefined) { heartInOrbitObj.lastWasIntersecting = false; } var heartIntersecting = reducedCollision(heartInOrbitObj, player, 1.0); if (!heartInOrbitObj.lastWasIntersecting && heartIntersecting) { // Player collects the heart: gain a life (up to max) if (lives < maxLives) { lives++; updateLivesText(); } // Remove heart from game if (heartInOrbitObj.parent) { heartInOrbitObj.parent.removeChild(heartInOrbitObj); } heartInOrbitActive = false; heartInOrbitObj = null; // Cancel the timeout if still pending if (heartInOrbitTimeout) { LK.clearTimeout(heartInOrbitTimeout); heartInOrbitTimeout = null; } } if (heartInOrbitObj) { heartInOrbitObj.lastWasIntersecting = heartIntersecting; } } // Remove heart if player dies (game over handled elsewhere) if (heartInOrbitActive && lives <= 0 && heartInOrbitObj) { if (heartInOrbitObj.parent) { heartInOrbitObj.parent.removeChild(heartInOrbitObj); } heartInOrbitActive = false; heartInOrbitObj = null; // Cancel the timeout if still pending if (heartInOrbitTimeout) { LK.clearTimeout(heartInOrbitTimeout); heartInOrbitTimeout = null; } } };
===================================================================
--- original.js
+++ change.js
@@ -1310,49 +1310,19 @@
}
if (typeof game._lastMusicPlayed === "undefined") {
game._lastMusicPlayed = null;
}
- // List of levels with music (as per the goal)
- var musicLevels = {
- 2: "musica2",
- 3: "musica3",
- 4: "musica4",
- 5: "musica5",
- 6: "musica6",
- 7: "musica7",
- 8: "musica8",
- 9: "musica9",
- 10: "musica10",
- 11: "musica11",
- 12: "musica12",
- 13: "musica13",
- 14: "musica14",
- 15: "musica15",
- 16: "musica16",
- 17: "musica17",
- 18: "musica18",
- 19: "musica19",
- 20: "musica20",
- 21: "musica21",
- 22: "musica22",
- 24: "musica24",
- 25: "musica25",
- 26: "musica26",
- 27: "musica27",
- 28: "musica28",
- 29: "musica29",
- 30: "musica30"
- };
- // Only change music if main level changed
+ // Play musicaN for each level, using the level number directly (e.g. level 2 = musica2, level 3 = musica3, etc.)
if (game._lastMusicLevel !== currentLevel) {
// Stop previous music (if any)
if (typeof game._lastMusicPlayed !== "undefined" && game._lastMusicPlayed !== null) {
LK.stopMusic();
game._lastMusicPlayed = null;
}
- // Play new music for this level, if available
- var musicToPlay = musicLevels[currentLevel];
- if (musicToPlay) {
+ // Compose music id for this level
+ var musicToPlay = "musica" + currentLevel;
+ // Only play if the asset exists (defensive: check LK.assets.music)
+ if (LK.assets && LK.assets.music && LK.assets.music[musicToPlay]) {
LK.playMusic(musicToPlay, {
loop: true,
volume: 1
});
Dead
Sound effect
MusicaInicio
Music
musica4
Music
musica1
Music
musica7
Music
musica10
Music
musica13
Music
musica16
Music
musica19
Music
musica22
Music
musica25
Music
musica28
Music
musica2
Music
musica3
Music
musica5
Music
musica6
Music
musica8
Music
musica9
Music
musica11
Music
musica12
Music
musica14
Music
musica15
Music
musica17
Music
musica18
Music
musica20
Music
musica21
Music
musica23
Music
musica24
Music
musica26
Music
musica27
Music
musica29
Music
musica30
Music