User prompt
Cuando el jugador llega al centro o a home pasa de nivel next
User prompt
Que la gravedad jale al jugador había el centro
User prompt
Suavisa el desplazamiento izquierdo y derecha y más lento
User prompt
Restaura el movimiento izquierda y derecha en la aorbita
User prompt
Que la gravedad atraiga al jugador hasta el centro total
User prompt
El overlay del fondo cambia de color por stage o nivel, en 10 tonalidades
User prompt
Solapa playera sobre home
User prompt
Que playera o jugador no colisiones con home
User prompt
Dije cuadrado
User prompt
Que el fondo tenga un overlay rectangular que titilea a 3 milisegundos en modo
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 260
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 250
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 240
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 230
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 220
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 210
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 200
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 190
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 180
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 180
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 180
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 170
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 170
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 160
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y = 1366 + self.orbitRadius * Math.sin(self.orbitAngle);' Line Number: 150
/**** * 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 Home class var Home = Container.expand(function () { var self = Container.call(this); // Attach the 'home' asset from Assets section (ensure we use the asset named 'home') var homeGraphics = self.attachAsset('home', { anchorX: 0.5, anchorY: 0.5 }); // Center position self.x = 1024; self.y = 1366; // No update needed (static) 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 () { // 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: 0x001f3f }); /**** * Game Code ****/ // --- Fullscreen flashing overlay (rectangular, titilea a 3ms) --- var flashingOverlay = new Container(); var overlayAsset = LK.getAsset('stage', { anchorX: 0, anchorY: 0 }); // Make overlay a perfect square, centered overlayAsset.width = 2048; overlayAsset.height = 2048; overlayAsset.color = 0x0074D9; // blue overlayAsset.shape = 'box'; overlayAsset.alpha = 0; // Center the square vertically overlayAsset.y = (2732 - 2048) / 2; flashingOverlay.addChild(overlayAsset); flashingOverlay.zIndex = 99999; game.addChild(flashingOverlay); // Animate alpha from 0 to 0.25 and back every 3ms function flashOverlay() { tween(overlayAsset, { alpha: 0.25 }, { duration: 3, easing: tween.linear, onFinish: function onFinish() { tween(overlayAsset, { alpha: 0 }, { duration: 3, easing: tween.linear, onFinish: flashOverlay }); } }); } flashOverlay(); // --- Splash Screen Overlay --- var splashOverlay = new Container(); splashOverlay.zIndex = 9999; // Ensure on top // Game Title var splashTitle = new Text2('ORBIT', { size: 480, fill: 0xFFFFFF, font: "'Impact','Arial Black',Tahoma", fontWeight: "bold" }); splashTitle.anchor.set(0.5, 0.5); splashTitle.x = 1024; splashTitle.y = 600; splashOverlay.addChild(splashTitle); // Subtitle var splashSubtitle = new Text2('Un universo hostil donde el más grande se traga al más pequeño', { size: 56, fill: 0xE0E0E0, font: "'Arial Rounded MT Bold','Arial Rounded MT','Arial Rounded','Arial','Arial Black',Tahoma" }); splashSubtitle.anchor.set(0.5, 0.5); splashSubtitle.x = 1024; splashSubtitle.y = 900; splashOverlay.addChild(splashSubtitle); // --- Add a single navy blue square to splash --- var splashNavySquare = LK.getAsset('stage', { anchorX: 0.5, anchorY: 0.5 }); splashNavySquare.x = 1024; splashNavySquare.y = 1700; splashNavySquare.width = 180; splashNavySquare.height = 180; splashNavySquare.color = 0x001f3f; // navy blue splashNavySquare.shape = 'box'; splashOverlay.addChild(splashNavySquare); // --- Level Select Buttons (1-10) --- // Place buttons in two horizontal rows of 5, centered horizontally, near the bottom var splashLevelBtns = []; var splashLevelBtnSize = 90; var splashLevelBtnRowSpacing = 120; var splashLevelBtnY1 = 2100; // First row Y var splashLevelBtnY2 = splashLevelBtnY1 + splashLevelBtnRowSpacing; // Second row Y // Calculate perfectly equidistant X positions for 5 buttons per row, centered horizontally, near the bottom var numBtnsPerRow = 5; var totalBtnWidth = numBtnsPerRow * splashLevelBtnSize; var centerMargin = 320; // Increase margin to bring buttons closer to center var availableWidth = 2048 - 2 * centerMargin; var btnSpacing = (availableWidth - totalBtnWidth) / (numBtnsPerRow - 1); var btnStartX = centerMargin + splashLevelBtnSize / 2; for (var i = 1; i <= 10; i++) { var btn = new Text2('Nivel ' + i, { size: 60, fill: 0xFFFFFF, font: "'Arial Rounded MT Bold','Arial Rounded MT','Arial Rounded','Arial','Arial Black',Tahoma" }); btn.anchor.set(0.5, 0.5); // Row 1: i=1..5, Row 2: i=6..10 if (i <= 5) { btn.x = btnStartX + (i - 1) * (splashLevelBtnSize + btnSpacing); btn.y = splashLevelBtnY1; } else { btn.x = btnStartX + (i - 6) * (splashLevelBtnSize + btnSpacing); btn.y = splashLevelBtnY2; } btn.interactive = true; btn.buttonMode = true; btn.alpha = 0.93; // Closure for correct level (function (levelNum) { btn.down = function (x, y, obj) { // Remove splash, show UI, start at selected level if (splashOverlay && splashOverlay.parent) splashOverlay.parent.removeChild(splashOverlay); if (typeof levelText !== "undefined") levelText.visible = true; if (typeof recordLabelText !== "undefined") recordLabelText.visible = false; if (typeof recordTopText !== "undefined") recordTopText.visible = false; if (typeof scoreText !== "undefined") scoreText.visible = true; if (typeof gotoLevel4Btn !== "undefined") gotoLevel4Btn.visible = true; if (typeof gotoLevel3Btn !== "undefined") gotoLevel3Btn.visible = true; if (typeof currentLevel !== "undefined") currentLevel = levelNum; if (typeof levelText !== "undefined" && levelText.setText) levelText.setText('Nivel ' + levelNum); if (typeof spawnEnemiesForLevel === "function") spawnEnemiesForLevel(levelNum); // Add rotation/orbit variants: some reverse, some elliptical for (var k = 0; typeof enemies !== "undefined" && k < enemies.length; k++) { if ((k + levelNum) % 3 === 0 && levelNum > 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; } if (levelNum > 6 && k % 2 === 0) { enemies[k].orbitSpeed = -Math.abs(enemies[k].orbitSpeed); } else { enemies[k].orbitSpeed = Math.abs(enemies[k].orbitSpeed); } } // Reset player to starting position for next level (center bottom of the screen) if (typeof player !== "undefined") { player.x = 1024; player.y = 2632; if (typeof centerX !== "undefined" && typeof centerY !== "undefined") { 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); } for (var j = 0; typeof enemies !== "undefined" && j < enemies.length; j++) { enemies[j].orbitAngle = Math.random() * Math.PI * 2; } player.lastRadius = player.radius + 1; } }; })(i); splashOverlay.addChild(btn); splashLevelBtns.push(btn); } // Start Button var splashBtn = new Text2('JUGAR', { size: 160, fill: 0xFFFFFF, font: "'Impact','Arial Black',Tahoma", fontWeight: "bold" }); splashBtn.anchor.set(0.5, 0.5); splashBtn.x = 1024; splashBtn.y = 1400; splashBtn.interactive = true; splashBtn.buttonMode = true; splashBtn.alpha = 0.97; splashOverlay.addChild(splashBtn); // Add overlay to game game.addChild(splashOverlay); // Hide all gameplay UI while splash is visible if (typeof levelText !== "undefined") levelText.visible = false; if (typeof scoreText !== "undefined") scoreText.visible = false; if (typeof recordLabelText !== "undefined") recordLabelText.visible = false; if (typeof recordTopText !== "undefined") recordTopText.visible = false; if (typeof gotoLevel4Btn !== "undefined") gotoLevel4Btn.visible = false; if (typeof gotoLevel3Btn !== "undefined") gotoLevel3Btn.visible = false; // --- Add a single navy blue square to splash --- var splashNavySquare = LK.getAsset('stage', { anchorX: 0.5, anchorY: 0.5 }); splashNavySquare.x = 1024; splashNavySquare.y = 1700; splashNavySquare.width = 180; splashNavySquare.height = 180; splashNavySquare.color = 0x001f3f; // navy blue splashNavySquare.shape = 'box'; splashOverlay.addChild(splashNavySquare); // Start button event: remove splash, show UI, start game splashBtn.down = function (x, y, obj) { if (splashOverlay && splashOverlay.parent) splashOverlay.parent.removeChild(splashOverlay); if (typeof levelText !== "undefined") levelText.visible = true; if (typeof scoreText !== "undefined") scoreText.visible = true; if (typeof recordLabelText !== "undefined") recordLabelText.visible = false; if (typeof recordTopText !== "undefined") recordTopText.visible = false; if (typeof gotoLevel4Btn !== "undefined") gotoLevel4Btn.visible = true; if (typeof gotoLevel3Btn !== "undefined") gotoLevel3Btn.visible = true; }; // Stages configuration object // Import tween plugin for color cycling 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 = [0xff3b3b, // bright red 0xfff200, // yellow 0x00ff90, // bright green 0x00e0ff, // cyan 0x3b6cff, // blue 0xc54ce4, // purple 0xff5ef7, // pink 0xffa500 // orange ]; 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 the home object at the center var home = game.addChild(new Home()); // Add the player to the game (after home, so player is above home) var player = game.addChild(new Player()); // Ensure player is always above home in the display list if (home && player && home.parent && player.parent && home.parent === player.parent) { var parent = home.parent; // Remove and re-add player to ensure it's above home parent.removeChild(player); parent.addChild(player); } // Make the home object flash its alpha from 0 to 1 in a blinking effect per 1ms if (home && home.children && home.children.length > 0 && home.children[0]) { // Use tween to animate alpha from 0 to 1 and back, repeating forever, with 1ms duration for each fade var _blinkHomeAlpha = function blinkHomeAlpha() { // Fade out to alpha 0 tween(homeGraphics, { alpha: 0 }, { duration: 1, easing: tween.linear, onFinish: function onFinish() { // Fade in to alpha 1 tween(homeGraphics, { alpha: 1 }, { duration: 1, easing: tween.linear, onFinish: _blinkHomeAlpha }); } }); }; var homeGraphics = home.children[0]; // Defensive: clear any previous alpha homeGraphics.alpha = 1; _blinkHomeAlpha(); } // Hide the home object while splashOverlay is visible if (typeof splashOverlay !== "undefined" && splashOverlay && splashOverlay.parent) { home.visible = false; } // Hide the player object while splashOverlay is visible if (typeof splashOverlay !== "undefined" && splashOverlay && splashOverlay.parent) { if (typeof player !== "undefined") player.visible = false; } // When splashOverlay is removed (game starts), show the home object if (typeof splashBtn !== "undefined" && splashBtn && splashBtn.down) { var originalSplashBtnDown = splashBtn.down; splashBtn.down = function (x, y, obj) { if (home) home.visible = true; if (player) player.visible = true; originalSplashBtnDown.call(this, x, y, obj); }; } // Also for level select buttons if (typeof splashLevelBtns !== "undefined" && splashLevelBtns.length) { for (var i = 0; i < splashLevelBtns.length; i++) { if (splashLevelBtns[i] && splashLevelBtns[i].down) { (function (btn) { var originalDown = btn.down; btn.down = function (x, y, obj) { if (home) home.visible = true; if (player) player.visible = true; originalDown.call(this, x, y, obj); }; })(splashLevelBtns[i]); } } } // Add a player to the game // (moved above, after home, to ensure correct z-order) // 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 = [0xff3b3b, // bright red 0xfff200, // yellow 0x00ff90, // bright green 0x00e0ff, // cyan 0x3b6cff, // blue 0xc54ce4, // purple 0xff5ef7, // pink 0xffa500 // orange ]; 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 three bonus objects, each occupying a unique orbit var bonuses = []; for (var i = 0; i < 3; i++) { var b = game.addChild(new Bonus()); b.orbitIndex = i; b.orbitRadius = orbits[i]; b.orbitSpeed = 0.04 + Math.random() * 0.09; // Distribute bonuses evenly around the circle b.orbitAngle = Math.PI * 2 / 3 * 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 superBonus.orbitSpeed = 0.18 + Math.random() * 0.04; // 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); // 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); // --- Add a button to jump to level 4 --- var gotoLevel4Btn = new Text2('Ir a Nivel 4', { size: 80, fill: 0xFFFFFF, font: "'Impact','Arial Black',Tahoma" }); gotoLevel4Btn.anchor.set(0.5, 0.5); // Place the button at the bottom right, but not in the very corner (avoid overlap with system UI) gotoLevel4Btn.x = LK.gui.width - 300; gotoLevel4Btn.y = LK.gui.height - 180; gotoLevel4Btn.interactive = true; gotoLevel4Btn.buttonMode = true; gotoLevel4Btn.alpha = 0.92; LK.gui.bottom.addChild(gotoLevel4Btn); // Button event: jump to level 4 gotoLevel4Btn.down = function (x, y, obj) { if (typeof currentLevel !== "undefined" && currentLevel !== 4) { currentLevel = 4; if (typeof levelText !== "undefined" && levelText.setText) { levelText.setText('Nivel ' + currentLevel); } spawnEnemiesForLevel(currentLevel); // Add rotation/orbit variants: some reverse, some elliptical for (var k = 0; k < enemies.length; k++) { 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; } if (currentLevel > 6 && k % 2 === 0) { enemies[k].orbitSpeed = -Math.abs(enemies[k].orbitSpeed); } else { enemies[k].orbitSpeed = Math.abs(enemies[k].orbitSpeed); } } // Reset player to starting position for next 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); for (var j = 0; j < enemies.length; j++) { enemies[j].orbitAngle = Math.random() * Math.PI * 2; } player.lastRadius = player.radius + 1; } }; // --- Add a button to jump to level 3 --- var gotoLevel3Btn = new Text2('Ir a Nivel 3', { size: 80, fill: 0xFFFFFF, font: "'Impact','Arial Black',Tahoma" }); gotoLevel3Btn.anchor.set(0.5, 0.5); // Place the button at the bottom right, above the level 4 button gotoLevel3Btn.x = LK.gui.width - 300; gotoLevel3Btn.y = LK.gui.height - 300; gotoLevel3Btn.interactive = true; gotoLevel3Btn.buttonMode = true; gotoLevel3Btn.alpha = 0.92; LK.gui.bottom.addChild(gotoLevel3Btn); // Button event: jump to level 3 gotoLevel3Btn.down = function (x, y, obj) { if (typeof currentLevel !== "undefined" && currentLevel !== 3) { currentLevel = 3; if (typeof levelText !== "undefined" && levelText.setText) { levelText.setText('Nivel ' + currentLevel); } spawnEnemiesForLevel(currentLevel); // Add rotation/orbit variants: some reverse, some elliptical for (var k = 0; k < enemies.length; k++) { 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; } if (currentLevel > 6 && k % 2 === 0) { enemies[k].orbitSpeed = -Math.abs(enemies[k].orbitSpeed); } else { enemies[k].orbitSpeed = Math.abs(enemies[k].orbitSpeed); } } // Reset player to starting position for next 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); for (var j = 0; j < enemies.length; j++) { enemies[j].orbitAngle = Math.random() * Math.PI * 2; } player.lastRadius = player.radius + 1; } }; // Record always starts at 0 and is not persisted var record = 0; // Set initial position of the player (bottom of the screen for splash/inicio) 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; // Reduce collision area: use a smaller rectangle for the superBonus var superBonusCollisionWidth = (superBonus.width ? superBonus.width : 25) * 0.6; var superBonusCollisionHeight = (superBonus.height ? superBonus.height : 25) * 0.6; var superBonusCollisionLeft = superBonus.x - superBonusCollisionWidth / 2; var superBonusCollisionRight = superBonus.x + superBonusCollisionWidth / 2; var superBonusCollisionTop = superBonus.y - superBonusCollisionHeight / 2; var superBonusCollisionBottom = superBonus.y + superBonusCollisionHeight / 2; var sbIntersecting = player.x > superBonusCollisionLeft && player.x < superBonusCollisionRight && player.y > superBonusCollisionTop && player.y < superBonusCollisionBottom; // Prevent points if splashOverlay is visible var splashActive = typeof splashOverlay !== "undefined" && splashOverlay && splashOverlay.parent; if (!splashActive) { 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; } 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; superBonus.orbitSpeed = 0.18 + Math.random() * 0.04; } } 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 --- // Deco no longer kills the player; collisions are ignored for game over logic if (player.lastWasIntersectingDeco === undefined) player.lastWasIntersectingDeco = []; if (player.lastWasIntersectingDeco[i] === undefined) player.lastWasIntersectingDeco[i] = false; // Reduce collision area: use a smaller rectangle for the deco var decoCollisionWidth = (deco.width ? deco.width : 15) * 0.6; var decoCollisionHeight = (deco.height ? deco.height : 15) * 0.6; var decoCollisionLeft = deco.x - decoCollisionWidth / 2; var decoCollisionRight = deco.x + decoCollisionWidth / 2; var decoCollisionTop = deco.y - decoCollisionHeight / 2; var decoCollisionBottom = deco.y + decoCollisionHeight / 2; var playerHitsDeco = player.x > decoCollisionLeft && player.x < decoCollisionRight && player.y > decoCollisionTop && player.y < decoCollisionBottom; player.lastWasIntersectingDeco[i] = playerHitsDeco; // --- Deco's own collision detection for legacy/compatibility --- if (deco.lastWasIntersecting === undefined) deco.lastWasIntersecting = false; // Reduce collision area: use a smaller rectangle for the deco var decoCollisionWidth2 = (deco.width ? deco.width : 15) * 0.6; var decoCollisionHeight2 = (deco.height ? deco.height : 15) * 0.6; var decoCollisionLeft2 = deco.x - decoCollisionWidth2 / 2; var decoCollisionRight2 = deco.x + decoCollisionWidth2 / 2; var decoCollisionTop2 = deco.y - decoCollisionHeight2 / 2; var decoCollisionBottom2 = deco.y + decoCollisionHeight2 / 2; var decoIntersecting = player.x > decoCollisionLeft2 && player.x < decoCollisionRight2 && player.y > decoCollisionTop2 && player.y < decoCollisionBottom2; 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; // Reduce collision area: use a smaller rectangle for the deco vs playerball var decoCollisionWidth3 = (deco.width ? deco.width : 15) * 0.6; var decoCollisionHeight3 = (deco.height ? deco.height : 15) * 0.6; var decoCollisionLeft3 = deco.x - decoCollisionWidth3 / 2; var decoCollisionRight3 = deco.x + decoCollisionWidth3 / 2; var decoCollisionTop3 = deco.y - decoCollisionHeight3 / 2; var decoCollisionBottom3 = deco.y + decoCollisionHeight3 / 2; var decoHitsPlayerball = playerball.x > decoCollisionLeft3 && playerball.x < decoCollisionRight3 && playerball.y > decoCollisionTop3 && playerball.y < decoCollisionBottom3; deco.lastWasIntersectingPlayerball = decoHitsPlayerball; } // --- Deco collides with playerball or player (combined logic) --- if (typeof playerball !== "undefined" && playerball) { if (deco.lastWasIntersectingPlayerOrBall === undefined) deco.lastWasIntersectingPlayerOrBall = false; // Reduce collision area: use a smaller rectangle for the deco vs player or playerball var decoCollisionWidth4 = (deco.width ? deco.width : 15) * 0.6; var decoCollisionHeight4 = (deco.height ? deco.height : 15) * 0.6; var decoCollisionLeft4 = deco.x - decoCollisionWidth4 / 2; var decoCollisionRight4 = deco.x + decoCollisionWidth4 / 2; var decoCollisionTop4 = deco.y - decoCollisionHeight4 / 2; var decoCollisionBottom4 = deco.y + decoCollisionHeight4 / 2; var decoHitsPlayerOrBall = player.x > decoCollisionLeft4 && player.x < decoCollisionRight4 && player.y > decoCollisionTop4 && player.y < decoCollisionBottom4 || playerball.x > decoCollisionLeft4 && playerball.x < decoCollisionRight4 && playerball.y > decoCollisionTop4 && playerball.y < decoCollisionBottom4; deco.lastWasIntersectingPlayerOrBall = decoHitsPlayerOrBall; } else { // Only player exists if (deco.lastWasIntersectingPlayerOrBall === undefined) deco.lastWasIntersectingPlayerOrBall = false; // Reduce collision area: use a smaller rectangle for the deco vs player (only player exists) var decoCollisionWidth5 = (deco.width ? deco.width : 15) * 0.6; var decoCollisionHeight5 = (deco.height ? deco.height : 15) * 0.6; var decoCollisionLeft5 = deco.x - decoCollisionWidth5 / 2; var decoCollisionRight5 = deco.x + decoCollisionWidth5 / 2; var decoCollisionTop5 = deco.y - decoCollisionHeight5 / 2; var decoCollisionBottom5 = deco.y + decoCollisionHeight5 / 2; var decoHitsPlayer = player.x > decoCollisionLeft5 && player.x < decoCollisionRight5 && player.y > decoCollisionTop5 && player.y < decoCollisionBottom5; 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 20 levels var currentLevel = 1; var maxLevels = 20; 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 22 at level 20 var numEnemies = Math.min(3 + (level - 1), 3 + (maxLevels - 1)); // Amplified enemy orbits: increase all base radii for even wider orbits 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 = [0xff3b3b, // bright red 0xfff200, // yellow 0x00ff90, // bright green 0x00e0ff, // cyan 0x3b6cff, // blue 0xc54ce4, // purple 0xff5ef7, // pink 0xffa500 // orange ]; 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); enemy.orbitAngle = Math.random() * Math.PI * 2; enemy.orbitSpeed = 0.004 + Math.random() * 0.003; // 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); // Play Vertigo music at the start of the game, ensure it loops LK.playMusic('Vertigo', { loop: true }); // Update method for orbiting game.update = function () { // Gravity: each frame, pull the player a bit toward the center if (typeof currentLevel === "undefined") { var gravityStrength = 1.2; } else { // Increase gravityStrength by 0.002 per level (slower acceleration) var gravityStrength = 1.2 + (currentLevel - 1) * 0.002; } // Prevent player from moving from the bottom during splash screen (inicio) var splashActive = typeof splashOverlay !== "undefined" && splashOverlay && splashOverlay.parent; if (splashActive) { // Keep player at bottom center 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); } else { // Smooth and continuous player movement if (typeof playerMoveDirection !== "undefined" && playerMoveDirection !== 0) { // Adjust this value for desired rotation speed (radians per frame) // Further reduced moveSpeed for even slower left/right movement var moveSpeed = 0.012; player.angle += playerMoveDirection * moveSpeed; } player.radius = Math.max(80, player.radius - gravityStrength); 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 20 --- if (typeof currentLevel === "undefined") { var currentLevel = 1; var maxLevels = 20; } if (player.lastRadius === undefined) player.lastRadius = player.radius; // Check if player just reached the home object at the center this frame if (home && player && home.lastWasIntersecting === undefined) home.lastWasIntersecting = false; var playerAtHome = home && player && home.intersects(player); // No collision or level-advance logic between player and home if (home) home.lastWasIntersecting = playerAtHome; 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; // Reduce collision area: use a smaller rectangle for the enemy var enemyCollisionWidth = (enemy.width ? enemy.width : 150) * 0.7; var enemyCollisionHeight = (enemy.height ? enemy.height : 150) * 0.7; var enemyCollisionLeft = enemy.x - enemyCollisionWidth / 2; var enemyCollisionRight = enemy.x + enemyCollisionWidth / 2; var enemyCollisionTop = enemy.y - enemyCollisionHeight / 2; var enemyCollisionBottom = enemy.y + enemyCollisionHeight / 2; var isIntersecting = player.x > enemyCollisionLeft && player.x < enemyCollisionRight && player.y > enemyCollisionTop && player.y < enemyCollisionBottom; // Prevent player death/game over if splashOverlay is visible var splashActive = typeof splashOverlay !== "undefined" && splashOverlay && splashOverlay.parent; if (!splashActive) { if (!enemy.lastWasIntersecting && isIntersecting) { // Collision just started, trigger miniparticle explosion and then game over LK.effects.flashScreen(0xff0000, 1000); // Play dead sound 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, show game over LK.setTimeout(function () { if (typeof recordTopText !== "undefined") recordTopText.visible = true; if (typeof recordLabelText !== "undefined") recordLabelText.visible = true; LK.showGameOver(); }, miniparticleLifetime); } else { if (typeof recordTopText !== "undefined") recordTopText.visible = true; if (typeof recordLabelText !== "undefined") recordLabelText.visible = true; LK.showGameOver(); } } } 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; // Reduce collision area: use a smaller rectangle for the closeEnemy var cEnemyCollisionWidth = (cEnemy.width ? cEnemy.width : 90) * 0.7; var cEnemyCollisionHeight = (cEnemy.height ? cEnemy.height : 90) * 0.7; var cEnemyCollisionLeft = cEnemy.x - cEnemyCollisionWidth / 2; var cEnemyCollisionRight = cEnemy.x + cEnemyCollisionWidth / 2; var cEnemyCollisionTop = cEnemy.y - cEnemyCollisionHeight / 2; var cEnemyCollisionBottom = cEnemy.y + cEnemyCollisionHeight / 2; var cEnemyIntersecting = player.x > cEnemyCollisionLeft && player.x < cEnemyCollisionRight && player.y > cEnemyCollisionTop && player.y < cEnemyCollisionBottom; // Prevent player death/game over if splashOverlay is visible var splashActive = typeof splashOverlay !== "undefined" && splashOverlay && splashOverlay.parent; if (!splashActive) { if (!cEnemy.lastWasIntersecting && cEnemyIntersecting) { // enemy2 kills the player: flash red and trigger game over LK.effects.flashScreen(0xff0000, 1000); // Play dead sound LK.getSound('Dead').play(); if (typeof recordTopText !== "undefined") recordTopText.visible = true; if (typeof recordLabelText !== "undefined") recordLabelText.visible = true; LK.showGameOver(); } } cEnemy.lastWasIntersecting = cEnemyIntersecting; } } if (typeof orbitingEnemy !== "undefined" && orbitingEnemy) { if (orbitingEnemy.lastWasIntersecting === undefined) orbitingEnemy.lastWasIntersecting = false; // Reduce collision area: use a smaller rectangle for the orbitingEnemy var oEnemyCollisionWidth = (orbitingEnemy.width ? orbitingEnemy.width : 90) * 0.7; var oEnemyCollisionHeight = (orbitingEnemy.height ? orbitingEnemy.height : 90) * 0.7; var oEnemyCollisionLeft = orbitingEnemy.x - oEnemyCollisionWidth / 2; var oEnemyCollisionRight = orbitingEnemy.x + oEnemyCollisionWidth / 2; var oEnemyCollisionTop = orbitingEnemy.y - oEnemyCollisionHeight / 2; var oEnemyCollisionBottom = orbitingEnemy.y + oEnemyCollisionHeight / 2; var oEnemyIntersecting = player.x > oEnemyCollisionLeft && player.x < oEnemyCollisionRight && player.y > oEnemyCollisionTop && player.y < oEnemyCollisionBottom; // Prevent player death/game over if splashOverlay is visible var splashActive = typeof splashOverlay !== "undefined" && splashOverlay && splashOverlay.parent; if (!splashActive) { if (!orbitingEnemy.lastWasIntersecting && oEnemyIntersecting) { LK.effects.flashScreen(0xff0000, 1000); // Play dead sound LK.getSound('Dead').play(); if (typeof recordTopText !== "undefined") recordTopText.visible = true; if (typeof recordLabelText !== "undefined") recordLabelText.visible = true; LK.showGameOver(); } } orbitingEnemy.lastWasIntersecting = oEnemyIntersecting; } // --- Stage object update (orbiting) --- if (typeof stage !== "undefined" && stage) { stage.update(); } // --- Bonus objects update and collision (three bonuses, one per orbit) --- 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; // Reduce collision area: use a smaller rectangle for the bonus var bonusCollisionWidth = (bonus.width ? bonus.width : 25) * 0.6; var bonusCollisionHeight = (bonus.height ? bonus.height : 25) * 0.6; var bonusCollisionLeft = bonus.x - bonusCollisionWidth / 2; var bonusCollisionRight = bonus.x + bonusCollisionWidth / 2; var bonusCollisionTop = bonus.y - bonusCollisionHeight / 2; var bonusCollisionBottom = bonus.y + bonusCollisionHeight / 2; var bIntersecting = player.x > bonusCollisionLeft && player.x < bonusCollisionRight && player.y > bonusCollisionTop && player.y < bonusCollisionBottom; // Prevent points if splashOverlay is visible var splashActive = typeof splashOverlay !== "undefined" && splashOverlay && splashOverlay.parent; if (!splashActive) { if (!bonus.lastWasIntersecting && bIntersecting) { // Player just collected the bonus! // Defensive: always initialize lastX/lastY if (player.lastX === undefined) player.lastX = player.x; if (player.lastY === undefined) player.lastY = player.y; // Get bonus bounds for entry logic var bonusLeft = bonus.x - (bonus.width ? bonus.width / 2 : 0); var bonusRight = bonus.x + (bonus.width ? bonus.width / 2 : 0); var bonusTop = bonus.y - (bonus.height ? bonus.height / 2 : 0); var bonusBottom = bonus.y + (bonus.height ? bonus.height / 2 : 0); // Entry direction logic: use best-practice for collision entry var entryPoints = 0; // Entered from above (top edge) if (player.lastY <= bonusTop && player.y > bonusTop) { entryPoints = 100; } // Entered from below (bottom edge) else if (player.lastY >= bonusBottom && player.y < bonusBottom) { entryPoints = 5; } // Entered from left (crossed left edge, not above or below) else if (player.lastX <= bonusLeft && player.x > bonusLeft && player.lastY > bonusTop && player.lastY < bonusBottom) { entryPoints = 30; } // Entered from right (crossed right edge, not above or below) else if (player.lastX >= bonusRight && player.x < bonusRight && player.lastY > bonusTop && player.lastY < bonusBottom) { entryPoints = 30; } // Fallback: default to 50 if can't determine if (entryPoints === 0) entryPoints = 50; score += entryPoints; if (typeof scoreText !== "undefined" && scoreText.setText) { scoreText.setText('' + score); } // Update record if needed if (score > record) { record = score; } 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 this bonus to a new random angle on its own orbit (keep orbitIndex fixed) bonus.orbitAngle = Math.random() * Math.PI * 2; bonus.orbitSpeed = 0.04 + Math.random() * 0.09; } // Track last player position for next frame player.lastX = player.x; player.lastY = player.y; } bonus.lastWasIntersecting = bIntersecting; } } };
===================================================================
--- original.js
+++ change.js
@@ -407,8 +407,17 @@
stages.push(stage);
}
// Add the home object at the center
var home = game.addChild(new Home());
+// Add the player to the game (after home, so player is above home)
+var player = game.addChild(new Player());
+// Ensure player is always above home in the display list
+if (home && player && home.parent && player.parent && home.parent === player.parent) {
+ var parent = home.parent;
+ // Remove and re-add player to ensure it's above home
+ parent.removeChild(player);
+ parent.addChild(player);
+}
// Make the home object flash its alpha from 0 to 1 in a blinking effect per 1ms
if (home && home.children && home.children.length > 0 && home.children[0]) {
// Use tween to animate alpha from 0 to 1 and back, repeating forever, with 1ms duration for each fade
var _blinkHomeAlpha = function blinkHomeAlpha() {
@@ -467,9 +476,9 @@
}
}
}
// Add a player to the game
-var player = game.addChild(new Player());
+// (moved above, after home, to ensure correct z-order)
// 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
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