User prompt
haz lo siguiente: - Lazer ememy tenga distintos patrones de ataques: - top (1/3)del area movible de player - down (1/3) del area movible player - down and top (2/3) del area movible player - left (1/3) del area movible player - right (1/3) del area movible player - left and rigth (2/3) del area movible player - center vertical del area movible player - center horizontal del area movible player - cruz del area movible player - X del area movible player
User prompt
haz que laser no se mueva
User prompt
Please fix the bug: 'Timeout.tick error: patternKeys is not defined' in or related to this line: 'self.selectedPattern = patternKeys[Math.floor(Math.random() * patternKeys.length)];' Line Number: 243
User prompt
haz que el patron de ataque sea unico de cada laser creado
User prompt
Agregale a enemy laser la función de aparecer en su nivel
User prompt
haz lo siguiente: - Lazer ememy tenga distintos patrones de ataques: - top del area movible - down del area movible - down and top - left - right - left and rigth - center vertical - center horizontal - cruz - X
User prompt
haz que laser enemy eliga dos posiciones uno A y uno B haz que el largo o el alto del laser (dependiendo si su es vertical o lateral) sea igual al largo
User prompt
Please fix the bug: 'Timeout.tick error: Graphics is not a constructor' in or related to this line: 'var line = new Graphics();' Line Number: 213
User prompt
Please fix the bug: 'Timeout.tick error: LK.effects.drawLine is not a function' in or related to this line: 'LK.effects.drawLine(self, pointA, pointB, {' Line Number: 212
User prompt
Please fix the bug: 'Timeout.tick error: lineAsset.lineStyle is not a function' in or related to this line: 'lineAsset.lineStyle(5, 0xf61cf6, 1); // Set line style with color and thickness' Line Number: 212
User prompt
Please fix the bug: 'Timeout.tick error: Graphics is not a constructor' in or related to this line: 'var graphics = new Graphics();' Line Number: 208
User prompt
haz que enemy laser dibuje una linea continua de un punto A a un punto B de inmediato
User prompt
Please fix the bug: 'TypeError: Graphics is not a constructor' in or related to this line: 'var graphics = new Graphics();' Line Number: 222
User prompt
mejora la logica para que parezca un laser
User prompt
haz que laser aparezca de un punto A a B con una logica de trazado
User prompt
agrega laser enemy a su correspondido nivel y su logica de spawn
User prompt
arregla la textura del level ??? para que tenga levellaser asset y levelassetendless
User prompt
arregla el text de circle level
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'levelSelector = LK.getAsset(levelAssets[levelName], {' Line Number: 528
User prompt
agrega un nuevo nivel despues de circle con el nombre ??? y al complletarse endless\nlaser
User prompt
crea un nuevo enemigo llamado EnemyLaser sin logica
User prompt
haz que la animación de agrandamiento se repita constantemente ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz que la animación de agrandamiento se repita constantemente ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
haz que los que vayan rapido sean un 20% más chikitos
/**** * Plugins ****/ var facekit = LK.import("@upit/facekit.v1"); var storage = LK.import("@upit/storage.v1"); var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Background = Container.expand(function () { var self = Container.call(this); var backgroundGraphics = self.attachAsset('Background', { anchorX: 0.5, anchorY: 0.5 }); self.x = 2048 / 2; // Set the x position to the center of the screen self.y = 2732 / 2; // Set the y position to the center of the screen }); var Button = Container.expand(function (text, x, y, callback) { var self = Container.call(this); self.buttonAsset = self.attachAsset('Buttom', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); self.buttonAsset.x = x; self.buttonAsset.y = y; var buttonText = new Text2(text, { size: 100, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" }); buttonText.anchor.set(0.5, 0.5); buttonText.x = x; buttonText.y = y; self.addChild(buttonText); self.buttonAsset.down = function (x, y, obj) { LK.getSound('ButtomSound').play(); callback(x, y, obj); }; }); var EnemyArrow = Container.expand(function () { var self = Container.call(this); var bEnemyArrowGraphics = self.attachAsset('EnemyArrow', { anchorX: 0.5, anchorY: 0.5 }); var arrowSound = LK.getSound('ArrowCreated'); arrowSound.pitch = 0.9 + Math.random() * 0.2; // Random pitch between 0.9 and 1.1 arrowSound.play(); enemyLogic(self); var angle = Math.atan2(player.y - self.y, player.x - self.x); var speed = 17.5; // Fixed speed for straight trajectory self.update = function () { if (!gamestart) { return; } self.x += Math.cos(angle) * speed; self.y += Math.sin(angle) * speed; self.rotation = angle; }; }); var EnemyCircle = Container.expand(function () { var self = Container.call(this); var bEnemyCircleGraphics = self.attachAsset('EnemyCircle', { anchorX: 0.5, anchorY: 0.5, scaleX: randomChance < 0.33 ? 0.8 : randomChance < 0.66 ? 1.0 : 0.8, // Reduce size by 20% if targeting player directly or moving fast scaleY: randomChance < 0.33 ? 0.8 : randomChance < 0.66 ? 1.0 : 0.8 // Reduce size by 20% if targeting player directly or moving fast }); // Add pulsing transparency and size increase animation function addPulsingAnimation(target) { tween(target, { alpha: 0.5, scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(target, { alpha: 1.0, scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { addPulsingAnimation(target); // Loop the effect } }); } }); } if (randomChance >= 0.33) { addPulsingAnimation(bEnemyCircleGraphics); } enemyLogic(self); // Determine target position based on random chance var randomChance = Math.random(); var targetX, targetY; if (randomChance < 0.33) { // 33% chance to go to the player's last position targetX = player.x; targetY = player.y; } else if (randomChance < 0.66) { // 33% chance to go to a very offset position from the player's last position var offsetX = (Math.random() - 0.5) * 800; // Random offset between -400 and 400 var offsetY = (Math.random() - 0.5) * 800; // Random offset between -400 and 400 targetX = player.x + offsetX; targetY = player.y + offsetY; } else { // 33% chance to go to a random position within the player's movement area var leftBound = (2048 - 1000) / 2; var rightBound = leftBound + 1000; var topBound = (2732 - 1000) / 2; var bottomBound = topBound + 1000; targetX = Math.random() * (rightBound - leftBound) + leftBound; targetY = Math.random() * (bottomBound - topBound) + topBound; } var angle = Math.atan2(targetY - self.y, targetX - self.x); var speed; if (randomChance < 0.33) { speed = 15; // Speed for direct to player } else if (randomChance < 0.66) { speed = 10; // Speed for nearby position } else { speed = 5; // Speed for random position // Add pulsing size animation for slower EnemyCircle instances tween(self, { scaleX: 1.4, scaleY: 1.4 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { addPulsingAnimation(self); // Loop the effect } }); } }); } self.update = function () { if (!gamestart) { return; } self.x += Math.cos(angle) * speed; self.y += Math.sin(angle) * speed; self.rotation += 0.03; // Add rotation to Circle }; }); var EnemyNinja = Container.expand(function () { var self = Container.call(this); var bEnemyNinjaGraphics = self.attachAsset('EnemyNinja', { anchorX: 0.5, anchorY: 0.5 }); var ninjaSound = LK.getSound('Ninjacreated'); ninjaSound.play(); enemyLogic(self); var angle = Math.atan2(player.y - self.y, player.x - self.x); self.directionChanges = 0; var speed = 18; // Set speed for Ninja self.cooldown = false; // Initialize cooldown state self.update = function () { if (!gamestart) { return; } self.x += Math.cos(angle) * speed; self.y += Math.sin(angle) * speed; self.rotation += 0.1; // Add rotation to Ninja // Check if Ninja is near the player and not on cooldown var distanceToPlayer = Math.sqrt(Math.pow(player.x - self.x, 2) + Math.pow(player.y - self.y, 2)); if (distanceToPlayer <= 600 && !self.cooldown) { self.cooldown = true; // Set cooldown to prevent immediate re-triggering // Create 4 Ninja Clones at 90-degree angles for (var i = 0; i < 4; i++) { var clone = new EnemyNinjaClone(); clone.x = self.x; clone.y = self.y; var cloneAngle = angle + Math.PI / 2 * i; // 90-degree increments clone.update = function (cloneAngle) { return function () { this.x += Math.cos(cloneAngle) * speed; this.y += Math.sin(cloneAngle) * speed; this.rotation += 0.1; }; }(cloneAngle); game.addChild(clone); // Limit the number of EnemyNinjaClones to 16 if (enemyNinjaClones.length >= 16) { var oldestClone = enemyNinjaClones.shift(); // Remove the oldest clone oldestClone.destroy(); // Destroy the oldest clone } enemyNinjaClones.push(clone); // Play 'Ninjasepare' sound with a slight delay for each clone LK.setTimeout(function () { LK.getSound('Ninjasepare').play(); }, i * 100); } self.destroy(); enemyNinjas.splice(enemyNinjas.indexOf(self), 1); } }; }); var EnemyNinjaClone = Container.expand(function () { var self = Container.call(this); var bEnemyNinjaCloneGraphics = self.attachAsset('EnemyNinja', { anchorX: 0.5, anchorY: 0.5 }); enemyLogic(self); var angle = Math.atan2(player.y - self.y, player.x - self.x); self.directionChanges = 0; var speed = 12; // Set speed for Ninja Clone self.cooldown = false; // Initialize cooldown state self.update = function () { if (!gamestart) { return; } self.x += Math.cos(angle) * speed; self.y += Math.sin(angle) * speed; self.rotation += 0.1; // Add rotation to Ninja Clone }; }); var EnemySaw = Container.expand(function () { var self = Container.call(this); var bEnemySawGraphics = self.attachAsset('EnemySaw', { anchorX: 0.5, anchorY: 0.5 }); var sawSound = LK.getSound('sawcreated'); sawSound.play(); enemyLogic(self); var angle = Math.atan2(player.y - self.y, player.x - self.x); var newAngle = null; var speed = 12.5; self.update = function () { if (!gamestart) { return; } var distanceToPlayer = Math.sqrt(Math.pow(player.x - self.x, 2) + Math.pow(player.y - self.y, 2)); if (distanceToPlayer <= 450 && !self.hasPaused) { self.hasPaused = true; // Set the boolean to true to ensure it only happens once var originalSpeed = speed; // Store original speed speed = 0; LK.setTimeout(function () { speed = originalSpeed * 2; newAngle = Math.atan2(player.y - self.y, player.x - self.x); // Assign new angle towards player's position LK.getSound('Sawcharge').play(); // Play 'Sawcharge' sound }, 1000); } var currentAngle = newAngle !== null ? newAngle : angle; // Use new angle if available self.x += Math.cos(currentAngle) * speed; self.y += Math.sin(currentAngle) * speed; self.rotation += 0.05; }; }); var EnemyStar = Container.expand(function () { var self = Container.call(this); var bEnemyStarGraphics = self.attachAsset('EnemyStar', { anchorX: 0.5, anchorY: 0.5 }); enemyLogic(self); self.directionChanges = 0; var angle = Math.atan2(player.y - self.y, player.x - self.x); var speed = 10; // Maintain original speed self.cooldown = false; // Initialize cooldown state self.update = function () { if (!gamestart) { return; } var distanceToPlayer = Math.sqrt(Math.pow(player.x - self.x, 2) + Math.pow(player.y - self.y, 2)); if (self.directionChanges < 3 && distanceToPlayer < 900 && !self.cooldown) { speed *= 1.2; angle = Math.atan2(player.y - self.y, player.x - self.x); self.directionChanges++; self.cooldown = true; LK.setTimeout(function () { self.cooldown = false; }, 1000); } self.x += Math.cos(angle) * speed; self.y += Math.sin(angle) * speed; self.rotation += 0.05; }; }); var Energy = Container.expand(function () { var self = Container.call(this); var energyGraphics = self.attachAsset('Energy', { anchorX: 0.5, anchorY: 0.5 }); self.value = 100; // Initial energy value self.decrease = function (amount) { self.value = Math.max(0, self.value - amount); }; self.increase = function (amount) { self.value = Math.min(100, self.value + amount); }; }); var Life = Container.expand(function () { var self = Container.call(this); var lifeGraphics = self.attachAsset('Life', { anchorX: 0.5, anchorY: 0.5 }); self.value = 100; // Initial life value self.decrease = function (amount) { self.value = Math.max(0, self.value - amount); if (self.value === 0) { lifeQuantity = Math.max(0, lifeQuantity - 1); updateLifeIcons(); if (lifeQuantity === 0) { self.destroy(); LK.showGameOver(); } } }; self.increase = function (amount) { self.value = Math.min(100, self.value + amount); }; }); var Player = Container.expand(function () { var self = Container.call(this); var faceGraphics = self.attachAsset('faceObject', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { if (!gamestart) { return; } var smoothing = 0.075; var targetX = facekit.noseTip.x; var targetY = facekit.noseTip.y; var leftBound = (2048 - 1000) / 2; var rightBound = leftBound + 1000; var topBound = (2732 - 1000) / 2; var bottomBound = topBound + 1000; targetX = Math.max(leftBound, Math.min(rightBound, targetX)); targetY = Math.max(topBound, Math.min(bottomBound, targetY)); self.x += (targetX - self.x) * smoothing; self.y += (targetY - self.y) * smoothing; var allEnemies = enemyArrows.concat(enemySaw, enemyNinjas, enemyNinjaClones, enemyStars, enemyCircles); for (var i = 0; i < allEnemies.length; i++) { if (self.intersects(allEnemies[i]) && !allEnemies[i].destroyed) { lifeQuantity = Math.max(0, lifeQuantity - 1); updateLifeIcons(); allEnemies[i].destroy(); if (enemyArrows.includes(allEnemies[i])) { enemyArrows.splice(enemyArrows.indexOf(allEnemies[i]), 1); } else if (enemySaw.includes(allEnemies[i])) { enemySaw.splice(enemySaw.indexOf(allEnemies[i]), 1); } else if (enemyStars.includes(allEnemies[i])) { enemyStars.splice(enemyStars.indexOf(allEnemies[i]), 1); } else if (enemyNinjas.includes(allEnemies[i])) { enemyNinjas.splice(enemyNinjas.indexOf(allEnemies[i]), 1); } else if (enemyCircles.includes(allEnemies[i])) { enemyCircles.splice(enemyCircles.indexOf(allEnemies[i]), 1); } else if (enemyNinjaClones.includes(allEnemies[i])) { enemyNinjaClones.splice(enemyNinjaClones.indexOf(allEnemies[i]), 1); allEnemies[i].destroy(); // Ensure the clone is destroyed } if (lifeQuantity === 0) { self.destroy(); gamestart = false; LK.showGameOver(); } break; } } }; }); var RangedLimiter = Container.expand(function () { var self = Container.call(this); var limiterGraphics = self.attachAsset('RangedLimiter', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5 }); }); var TextElement = Container.expand(function (text, size, color, font, x, y) { var self = Container.call(this); var textElement = new Text2(text, { size: size, fill: color, font: font }); textElement.anchor.set(0.5, 0.5); textElement.x = x; textElement.y = y; self.addChild(textElement); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var levelCompletedArrow = storage.levelCompletedArrow || false; var levelCompletedSaw = storage.levelCompletedSaw || false; var levelCompletedNinja = storage.levelCompletedNinja || false; var levelCompletedStar = storage.levelCompletedStar || false; var levelCompletedCircle = storage.levelCompletedCircle || false; function showSelectLevelPage() { // Add pulsing transparency effect to RangedLimiter using tween plugin function addPulsingEffect(target) { tween(target, { alpha: 0.2 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(target, { alpha: 0.5 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { addPulsingEffect(target); // Loop the effect } }); } }); } addPulsingEffect(rangerlimited); var selectLevelContainer = new Container(); // Add a background to the select level page var selectLevelBackground = LK.getAsset('BackgroundMenu', { anchorX: 0.5, anchorY: 0.5 }); selectLevelBackground.x = 2048 / 2; selectLevelBackground.y = 2732 / 2; selectLevelContainer.addChild(selectLevelBackground); // Add a title to the select level page var selectLevelTitle = new TextElement('Select Level', 150, 0xFFFFFF, "'Press Start 2P', cursive", 2048 / 2, 500); selectLevelContainer.addChild(selectLevelTitle); // Add a back button to return to the main menu var backButton = new Button('Back', 2048 / 2, 2400, function (x, y, obj) { selectLevelContainer.visible = false; // Hide the select level page menuContainer.visible = true; // Show the main menu }); selectLevelContainer.addChild(backButton); // Add 'How to Play' button to the select level page var howToPlayButton = new Button('How to Play', 2048 / 2, 2100, function (x, y, obj) { // Add logic for how to play button }); selectLevelContainer.addChild(howToPlayButton); var levelNames = ['arrow', 'saw', 'ninja', 'star', 'circle']; // Conventional levels var endlessModeName = 'endless'; // Endless mode var levelSelectors = []; // Array to store level selectors for (var i = 0; i < levelNames.length + 1; i++) { var levelName = i < levelNames.length ? levelNames[i] : endlessModeName; // Add endless mode after last level var levelSelector; var levelAssets = { 'arrow': levelCompletedArrow ? 'LevelArrowEndless' : 'LevelBloq', 'saw': levelCompletedSaw ? 'LevelSawEndless' : 'LevelBloq', 'star': levelCompletedStar ? 'LevelStarEndless' : 'LevelBloq', 'ninja': levelCompletedNinja ? 'LevelNinjaEndless' : 'LevelBloq', 'circle': levelCompletedCircle ? 'LevelCircleEndless' : 'LevelBloq', 'endless': 'LevelBloq' }; levelSelector = LK.getAsset(levelAssets[levelName], { anchorX: 0.5, anchorY: 0.5 }); levelSelector.x = 2048 / 2; levelSelector.y = 1300; // Align vertically levelSelector.levelType = levelName; levelSelector.down = function (index) { // Create a closure to capture the current index return function (x, y, obj) { if (true) { leftArrow.buttonAsset.down = null; // Disable left arrow button rightArrow.buttonAsset.down = null; // Disable right arrow button backButton.buttonAsset.down = null; // Disable back button howToPlayButton.buttonAsset.down = null; // Disable how to play button if (!this.soundPlayed) { LK.getSound('InitialLevel').play(); // Play initial level sound this.soundPlayed = true; // Ensure the sound only plays once } LK.setTimeout(function () { // Add a 3-second cooldown before starting the level gamestart = true; // Start the game selectLevelContainer.visible = false; levelID = index; console.log("Starting level:", obj.levelType); }, 3000); } else { console.log("Previous level's endless mode not completed. Cannot start this level."); } }; }(i); // Pass the current index to the closure selectLevelContainer.addChild(levelSelector); // Add level text below each level selector var levelTextContent = levelName === 'endless' ? 'endless\nmode' : levelName === 'arrow' && levelCompletedArrow ? 'endless\narrow' : levelName === 'saw' && levelCompletedSaw ? 'endless\nsaw' : levelName === 'star' && levelCompletedStar ? 'endless\nstar' : levelName; var levelText = new Text2(levelTextContent, { size: 80, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" }); levelText.anchor.set(0.5, 0.5); levelText.x = levelSelector.x; levelText.y = levelSelector.y + 300; // Position text below the selector selectLevelContainer.addChild(levelText); levelSelector.levelText = levelText; // Store levelText in levelSelector levelSelectors.push(levelSelector); // Add to array } // Add arrow buttons for level navigation var currentLevelIndex = 0; function updateLevelSelectors() { for (var i = 0; i < levelSelectors.length; i++) { levelSelectors[i].visible = i === currentLevelIndex; levelSelectors[i].levelText.visible = i === currentLevelIndex; } } var leftArrow = new Button('<', 2048 / 2 - 700, 1300, function (x, y, obj) { if (currentLevelIndex > 0) { currentLevelIndex--; updateLevelSelectors(); } }); selectLevelContainer.addChild(leftArrow); var rightArrow = new Button('>', 2048 / 2 + 700, 1300, function (x, y, obj) { if (currentLevelIndex < levelSelectors.length - 1) { currentLevelIndex++; updateLevelSelectors(); } }); selectLevelContainer.addChild(rightArrow); updateLevelSelectors(); game.addChild(selectLevelContainer); } var levelID = 0; var lifeQuantity = 3; var energyQuantity = 100; var gamestart = false; function enemyLogic(entity) { var spawnPositions = [{ x: Math.random() * 2000, y: 0 }, { x: Math.random() * 2000, y: 3000 }, { x: 0, y: Math.random() * 2000 }, { x: 3000, y: Math.random() * 2000 }]; var position = spawnPositions[Math.floor(Math.random() * spawnPositions.length)]; entity.x = position.x; entity.y = position.y; entity.spawnTime = entity.spawnTime || Math.random() * 2000 + 2000; } var background = game.addChild(new Background()); var timerTxt = new Text2('0', { size: 100, fill: 0xFFFFFF }); timerTxt.anchor.set(0.5, 0); timerTxt.visible = false; // Initially hide the timer text LK.gui.top.addChild(timerTxt); var elapsedTime = 0; var timerInterval = LK.setInterval(function () { if (!gamestart) { return; } // Ensure timer only updates when gamestart is true if (gamestart && !timerTxt.visible) { timerTxt.visible = true; // Show timer text when game starts } else if (!gamestart && timerTxt.visible) { timerTxt.visible = false; // Hide timer text when game is not started } elapsedTime++; if (elapsedTime >= 30 && (levelID === 1 && !levelCompletedSaw || levelID === 2 && !levelCompletedNinja || levelID === 3 && !levelCompletedStar || levelID === 0 && !levelCompletedArrow || levelID === 4 && !levelCompletedCircle)) { gamestart = false; if (levelID === 0) { levelCompletedArrow = true; storage.levelCompletedArrow = true; // Save to cloud } else if (levelID === 1) { levelCompletedSaw = true; storage.levelCompletedSaw = true; // Save to cloud } else if (levelID === 2) { levelCompletedNinja = true; storage.levelCompletedNinja = true; // Save to cloud } else if (levelID === 3) { levelCompletedStar = true; storage.levelCompletedStar = true; // Save to cloud } else if (levelID === 4) { levelCompletedCircle = true; storage.levelCompletedCircle = true; // Save to cloud } LK.showYouWin(); // Show "you win" and reset the game state } var minutes = Math.floor(elapsedTime / 60); // Calculate minutes var seconds = elapsedTime % 60; // Calculate remaining seconds var timeString = minutes > 0 ? minutes + "m " + seconds + "s" : seconds + "s"; // Format time string timerTxt.setText(timeString); }, 1000); var player = game.addChild(new Player()); player.x = 2048 / 2; // Center the player on the x-axis player.y = 2732 / 2; // Center the player on the y-axis game.up = function (x, y, obj) { player.scaleX = 1; player.scaleY = 1; if (energyDecreaseInterval) { LK.clearInterval(energyDecreaseInterval); // Clear interval when player returns to normal size } }; game.down = function (x, y, obj) { if (energy.value > 0) { // Check if energy is greater than 0 player.scaleX = 0.5; player.scaleY = 0.5; energyDecreaseInterval = LK.setInterval(function () { energy.decrease(2); // Decrease energy by 2% energyText.setText(energy.value + '%'); // Update energy text if (energy.value <= 0) { player.scaleX = 1; // Reset player size if energy depletes player.scaleY = 1; LK.clearInterval(energyDecreaseInterval); // Clear interval } }, 1000); // Decrease energy every second } }; // Create a list to store EnemyArrow instances function spawnEnemy(type, interval, levelCheck, enemyArray, enemyClass) { return LK.setInterval(function () { if (!gamestart || !levelCheck()) { return; } var newEnemy = game.addChild(new enemyClass()); enemyArray.push(newEnemy); newEnemy.spawnTime = Date.now(); LK.setTimeout(function () { if (enemyArray.includes(newEnemy) && Date.now() - newEnemy.spawnTime >= 10000) { newEnemy.destroy(); enemyArray.splice(enemyArray.indexOf(newEnemy), 1); } }, 20000); }, interval); } var enemyArrows = []; var enemySaw = []; var enemyNinjas = []; // New array to store EnemyNinja instances var enemyNinjaClones = []; // New array to store EnemyNinjaClone instances var enemyStars = []; // New array to store EnemyStar instances var enemyCircles = []; // New array to store EnemyCircle instances var enemyArrowInterval = spawnEnemy('arrow', 700, function () { return levelID === 0; }, enemyArrows, EnemyArrow); var enemySawInterval = spawnEnemy('saw', 1000, function () { return levelID === 1; }, enemySaw, EnemySaw); var enemyNinjaInterval = spawnEnemy('ninja', 1200, function () { return levelID === 2; }, enemyNinjas, EnemyNinja); var enemyStarInterval = spawnEnemy('star', 1500, function () { return levelID === 3; }, enemyStars, EnemyStar); var enemyCircleInterval = spawnEnemy('circle', 700, function () { return levelID === 4; }, enemyCircles, EnemyCircle); var lifeIcons = []; for (var i = 0; i < lifeQuantity; i++) { var lifeIcon = game.addChild(new Life()); lifeIcon.x = 2048 / 2 - 600 + i * 160; // Position each life icon to the right of the previous one lifeIcon.y = 100; // Align vertically with the timer lifeIcons.push(lifeIcon); } // Function to update life icons when life decreases function updateLifeIcons() { for (var i = 0; i < lifeIcons.length; i++) { if (i < lifeQuantity) { lifeIcons[i].visible = true; } else { lifeIcons[i].visible = false; } } } var energy = game.addChild(new Energy()); energy.x = 2048 / 2 + 600; // Position energy to the right of the timer energy.y = 100; // Align vertically with the timer var energyText = new Text2(energyQuantity + '%', { size: 80, fill: 0xFFFFFF }); energyText.anchor.set(1, 0.5); // Anchor to the right center energyText.x = energy.x - 100; // Position to the left of energy energyText.y = energy.y; game.addChild(energyText); var rangerlimited = game.addChild(new RangedLimiter()); rangerlimited.x = 2048 / 2; // Center the RangedLimiter on the x-axis rangerlimited.y = 2732 / 2; // Center the RangedLimiter on the y-axis // Create an initial menu var menuContainer = new Container(); /* * Menu inicial */ var menuBackground = LK.getAsset('BackgroundMenu', { anchorX: 0.5, anchorY: 0.5 }); menuBackground.x = 2048 / 2; menuBackground.y = 2732 / 2; menuContainer.addChild(menuBackground); // Add a title to the menu var title = new TextElement('Game Title', 150, 0xFFFFFF, "'Press Start 2P', cursive", 2048 / 2, 500); menuContainer.addChild(title); // Create buttons var startButton = new Button('Game Start', 2048 / 2, 1200, function (x, y, obj) { menuContainer.visible = false; // Hide the menu showSelectLevelPage(); // Redirect to 'select level' page }); menuContainer.addChild(startButton); var recordButton = new Button('Record', 2048 / 2, 1700, function (x, y, obj) { menuContainer.visible = false; // Hide the main menu showRecordsPage(); // Show the records page }); menuContainer.addChild(recordButton); var creditsButton = new Button('Credits', 2048 / 2, 2200, function (x, y, obj) { showCreditsPage(); }); menuContainer.addChild(creditsButton); function showCreditsPage() { // Create a new container for the credits page var creditsContainer = new Container(); // Add the credits background var creditsBackground = LK.getAsset('Credits', { anchorX: 0.5, anchorY: 0.5 }); creditsBackground.x = 2048 / 2; creditsBackground.y = 2732 / 2; creditsContainer.addChild(creditsBackground); // Add event listener to hide credits page on touch creditsBackground.down = function (x, y, obj) { creditsContainer.visible = false; // Hide the credits page menuContainer.visible = true; // Show the main menu }; // Add the credits page to the game game.addChild(creditsContainer); } game.addChild(menuContainer); ; // Function to display the records page function showRecordsPage() { // Create a new container for the records page var recordsContainer = new Container(); // Add a black background to the records page var recordsBackground = LK.getAsset('BackgroundMenu', { anchorX: 0.5, anchorY: 0.5 }); recordsBackground.x = 2048 / 2; recordsBackground.y = 2732 / 2; recordsContainer.addChild(recordsBackground); // Add a title to the records page var recordsTitle = new TextElement('Records', 150, 0xFFFFFF, "'Press Start 2P', cursive", 2048 / 2, 500); recordsContainer.addChild(recordsTitle); var backButtonAsset = LK.getAsset('Buttom', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); backButtonAsset.x = 2048 / 2; backButtonAsset.y = 2300; recordsContainer.addChild(backButtonAsset); var backButton = new Text2('Back', { size: 100, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" }); backButton.anchor.set(0.5, 0.5); backButton.x = 2048 / 2; backButton.y = 2400; recordsContainer.addChild(backButton); // Add event listener to 'Back' button backButtonAsset.down = function (x, y, obj) { LK.getSound('ButtomSound').play(); recordsContainer.visible = false; // Hide the records page menuContainer.visible = true; // Show the main menu }; // Add the records page to the game game.addChild(recordsContainer); }
/****
* Plugins
****/
var facekit = LK.import("@upit/facekit.v1");
var storage = LK.import("@upit/storage.v1");
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('Background', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2; // Set the x position to the center of the screen
self.y = 2732 / 2; // Set the y position to the center of the screen
});
var Button = Container.expand(function (text, x, y, callback) {
var self = Container.call(this);
self.buttonAsset = self.attachAsset('Buttom', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
self.buttonAsset.x = x;
self.buttonAsset.y = y;
var buttonText = new Text2(text, {
size: 100,
fill: 0xFFFFFF,
font: "'Press Start 2P', cursive"
});
buttonText.anchor.set(0.5, 0.5);
buttonText.x = x;
buttonText.y = y;
self.addChild(buttonText);
self.buttonAsset.down = function (x, y, obj) {
LK.getSound('ButtomSound').play();
callback(x, y, obj);
};
});
var EnemyArrow = Container.expand(function () {
var self = Container.call(this);
var bEnemyArrowGraphics = self.attachAsset('EnemyArrow', {
anchorX: 0.5,
anchorY: 0.5
});
var arrowSound = LK.getSound('ArrowCreated');
arrowSound.pitch = 0.9 + Math.random() * 0.2; // Random pitch between 0.9 and 1.1
arrowSound.play();
enemyLogic(self);
var angle = Math.atan2(player.y - self.y, player.x - self.x);
var speed = 17.5; // Fixed speed for straight trajectory
self.update = function () {
if (!gamestart) {
return;
}
self.x += Math.cos(angle) * speed;
self.y += Math.sin(angle) * speed;
self.rotation = angle;
};
});
var EnemyCircle = Container.expand(function () {
var self = Container.call(this);
var bEnemyCircleGraphics = self.attachAsset('EnemyCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: randomChance < 0.33 ? 0.8 : randomChance < 0.66 ? 1.0 : 0.8,
// Reduce size by 20% if targeting player directly or moving fast
scaleY: randomChance < 0.33 ? 0.8 : randomChance < 0.66 ? 1.0 : 0.8 // Reduce size by 20% if targeting player directly or moving fast
});
// Add pulsing transparency and size increase animation
function addPulsingAnimation(target) {
tween(target, {
alpha: 0.5,
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(target, {
alpha: 1.0,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
addPulsingAnimation(target); // Loop the effect
}
});
}
});
}
if (randomChance >= 0.33) {
addPulsingAnimation(bEnemyCircleGraphics);
}
enemyLogic(self);
// Determine target position based on random chance
var randomChance = Math.random();
var targetX, targetY;
if (randomChance < 0.33) {
// 33% chance to go to the player's last position
targetX = player.x;
targetY = player.y;
} else if (randomChance < 0.66) {
// 33% chance to go to a very offset position from the player's last position
var offsetX = (Math.random() - 0.5) * 800; // Random offset between -400 and 400
var offsetY = (Math.random() - 0.5) * 800; // Random offset between -400 and 400
targetX = player.x + offsetX;
targetY = player.y + offsetY;
} else {
// 33% chance to go to a random position within the player's movement area
var leftBound = (2048 - 1000) / 2;
var rightBound = leftBound + 1000;
var topBound = (2732 - 1000) / 2;
var bottomBound = topBound + 1000;
targetX = Math.random() * (rightBound - leftBound) + leftBound;
targetY = Math.random() * (bottomBound - topBound) + topBound;
}
var angle = Math.atan2(targetY - self.y, targetX - self.x);
var speed;
if (randomChance < 0.33) {
speed = 15; // Speed for direct to player
} else if (randomChance < 0.66) {
speed = 10; // Speed for nearby position
} else {
speed = 5; // Speed for random position
// Add pulsing size animation for slower EnemyCircle instances
tween(self, {
scaleX: 1.4,
scaleY: 1.4
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
addPulsingAnimation(self); // Loop the effect
}
});
}
});
}
self.update = function () {
if (!gamestart) {
return;
}
self.x += Math.cos(angle) * speed;
self.y += Math.sin(angle) * speed;
self.rotation += 0.03; // Add rotation to Circle
};
});
var EnemyNinja = Container.expand(function () {
var self = Container.call(this);
var bEnemyNinjaGraphics = self.attachAsset('EnemyNinja', {
anchorX: 0.5,
anchorY: 0.5
});
var ninjaSound = LK.getSound('Ninjacreated');
ninjaSound.play();
enemyLogic(self);
var angle = Math.atan2(player.y - self.y, player.x - self.x);
self.directionChanges = 0;
var speed = 18; // Set speed for Ninja
self.cooldown = false; // Initialize cooldown state
self.update = function () {
if (!gamestart) {
return;
}
self.x += Math.cos(angle) * speed;
self.y += Math.sin(angle) * speed;
self.rotation += 0.1; // Add rotation to Ninja
// Check if Ninja is near the player and not on cooldown
var distanceToPlayer = Math.sqrt(Math.pow(player.x - self.x, 2) + Math.pow(player.y - self.y, 2));
if (distanceToPlayer <= 600 && !self.cooldown) {
self.cooldown = true; // Set cooldown to prevent immediate re-triggering
// Create 4 Ninja Clones at 90-degree angles
for (var i = 0; i < 4; i++) {
var clone = new EnemyNinjaClone();
clone.x = self.x;
clone.y = self.y;
var cloneAngle = angle + Math.PI / 2 * i; // 90-degree increments
clone.update = function (cloneAngle) {
return function () {
this.x += Math.cos(cloneAngle) * speed;
this.y += Math.sin(cloneAngle) * speed;
this.rotation += 0.1;
};
}(cloneAngle);
game.addChild(clone);
// Limit the number of EnemyNinjaClones to 16
if (enemyNinjaClones.length >= 16) {
var oldestClone = enemyNinjaClones.shift(); // Remove the oldest clone
oldestClone.destroy(); // Destroy the oldest clone
}
enemyNinjaClones.push(clone);
// Play 'Ninjasepare' sound with a slight delay for each clone
LK.setTimeout(function () {
LK.getSound('Ninjasepare').play();
}, i * 100);
}
self.destroy();
enemyNinjas.splice(enemyNinjas.indexOf(self), 1);
}
};
});
var EnemyNinjaClone = Container.expand(function () {
var self = Container.call(this);
var bEnemyNinjaCloneGraphics = self.attachAsset('EnemyNinja', {
anchorX: 0.5,
anchorY: 0.5
});
enemyLogic(self);
var angle = Math.atan2(player.y - self.y, player.x - self.x);
self.directionChanges = 0;
var speed = 12; // Set speed for Ninja Clone
self.cooldown = false; // Initialize cooldown state
self.update = function () {
if (!gamestart) {
return;
}
self.x += Math.cos(angle) * speed;
self.y += Math.sin(angle) * speed;
self.rotation += 0.1; // Add rotation to Ninja Clone
};
});
var EnemySaw = Container.expand(function () {
var self = Container.call(this);
var bEnemySawGraphics = self.attachAsset('EnemySaw', {
anchorX: 0.5,
anchorY: 0.5
});
var sawSound = LK.getSound('sawcreated');
sawSound.play();
enemyLogic(self);
var angle = Math.atan2(player.y - self.y, player.x - self.x);
var newAngle = null;
var speed = 12.5;
self.update = function () {
if (!gamestart) {
return;
}
var distanceToPlayer = Math.sqrt(Math.pow(player.x - self.x, 2) + Math.pow(player.y - self.y, 2));
if (distanceToPlayer <= 450 && !self.hasPaused) {
self.hasPaused = true; // Set the boolean to true to ensure it only happens once
var originalSpeed = speed; // Store original speed
speed = 0;
LK.setTimeout(function () {
speed = originalSpeed * 2;
newAngle = Math.atan2(player.y - self.y, player.x - self.x); // Assign new angle towards player's position
LK.getSound('Sawcharge').play(); // Play 'Sawcharge' sound
}, 1000);
}
var currentAngle = newAngle !== null ? newAngle : angle; // Use new angle if available
self.x += Math.cos(currentAngle) * speed;
self.y += Math.sin(currentAngle) * speed;
self.rotation += 0.05;
};
});
var EnemyStar = Container.expand(function () {
var self = Container.call(this);
var bEnemyStarGraphics = self.attachAsset('EnemyStar', {
anchorX: 0.5,
anchorY: 0.5
});
enemyLogic(self);
self.directionChanges = 0;
var angle = Math.atan2(player.y - self.y, player.x - self.x);
var speed = 10; // Maintain original speed
self.cooldown = false; // Initialize cooldown state
self.update = function () {
if (!gamestart) {
return;
}
var distanceToPlayer = Math.sqrt(Math.pow(player.x - self.x, 2) + Math.pow(player.y - self.y, 2));
if (self.directionChanges < 3 && distanceToPlayer < 900 && !self.cooldown) {
speed *= 1.2;
angle = Math.atan2(player.y - self.y, player.x - self.x);
self.directionChanges++;
self.cooldown = true;
LK.setTimeout(function () {
self.cooldown = false;
}, 1000);
}
self.x += Math.cos(angle) * speed;
self.y += Math.sin(angle) * speed;
self.rotation += 0.05;
};
});
var Energy = Container.expand(function () {
var self = Container.call(this);
var energyGraphics = self.attachAsset('Energy', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 100; // Initial energy value
self.decrease = function (amount) {
self.value = Math.max(0, self.value - amount);
};
self.increase = function (amount) {
self.value = Math.min(100, self.value + amount);
};
});
var Life = Container.expand(function () {
var self = Container.call(this);
var lifeGraphics = self.attachAsset('Life', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 100; // Initial life value
self.decrease = function (amount) {
self.value = Math.max(0, self.value - amount);
if (self.value === 0) {
lifeQuantity = Math.max(0, lifeQuantity - 1);
updateLifeIcons();
if (lifeQuantity === 0) {
self.destroy();
LK.showGameOver();
}
}
};
self.increase = function (amount) {
self.value = Math.min(100, self.value + amount);
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
var faceGraphics = self.attachAsset('faceObject', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
if (!gamestart) {
return;
}
var smoothing = 0.075;
var targetX = facekit.noseTip.x;
var targetY = facekit.noseTip.y;
var leftBound = (2048 - 1000) / 2;
var rightBound = leftBound + 1000;
var topBound = (2732 - 1000) / 2;
var bottomBound = topBound + 1000;
targetX = Math.max(leftBound, Math.min(rightBound, targetX));
targetY = Math.max(topBound, Math.min(bottomBound, targetY));
self.x += (targetX - self.x) * smoothing;
self.y += (targetY - self.y) * smoothing;
var allEnemies = enemyArrows.concat(enemySaw, enemyNinjas, enemyNinjaClones, enemyStars, enemyCircles);
for (var i = 0; i < allEnemies.length; i++) {
if (self.intersects(allEnemies[i]) && !allEnemies[i].destroyed) {
lifeQuantity = Math.max(0, lifeQuantity - 1);
updateLifeIcons();
allEnemies[i].destroy();
if (enemyArrows.includes(allEnemies[i])) {
enemyArrows.splice(enemyArrows.indexOf(allEnemies[i]), 1);
} else if (enemySaw.includes(allEnemies[i])) {
enemySaw.splice(enemySaw.indexOf(allEnemies[i]), 1);
} else if (enemyStars.includes(allEnemies[i])) {
enemyStars.splice(enemyStars.indexOf(allEnemies[i]), 1);
} else if (enemyNinjas.includes(allEnemies[i])) {
enemyNinjas.splice(enemyNinjas.indexOf(allEnemies[i]), 1);
} else if (enemyCircles.includes(allEnemies[i])) {
enemyCircles.splice(enemyCircles.indexOf(allEnemies[i]), 1);
} else if (enemyNinjaClones.includes(allEnemies[i])) {
enemyNinjaClones.splice(enemyNinjaClones.indexOf(allEnemies[i]), 1);
allEnemies[i].destroy(); // Ensure the clone is destroyed
}
if (lifeQuantity === 0) {
self.destroy();
gamestart = false;
LK.showGameOver();
}
break;
}
}
};
});
var RangedLimiter = Container.expand(function () {
var self = Container.call(this);
var limiterGraphics = self.attachAsset('RangedLimiter', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5
});
});
var TextElement = Container.expand(function (text, size, color, font, x, y) {
var self = Container.call(this);
var textElement = new Text2(text, {
size: size,
fill: color,
font: font
});
textElement.anchor.set(0.5, 0.5);
textElement.x = x;
textElement.y = y;
self.addChild(textElement);
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var levelCompletedArrow = storage.levelCompletedArrow || false;
var levelCompletedSaw = storage.levelCompletedSaw || false;
var levelCompletedNinja = storage.levelCompletedNinja || false;
var levelCompletedStar = storage.levelCompletedStar || false;
var levelCompletedCircle = storage.levelCompletedCircle || false;
function showSelectLevelPage() {
// Add pulsing transparency effect to RangedLimiter using tween plugin
function addPulsingEffect(target) {
tween(target, {
alpha: 0.2
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(target, {
alpha: 0.5
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
addPulsingEffect(target); // Loop the effect
}
});
}
});
}
addPulsingEffect(rangerlimited);
var selectLevelContainer = new Container();
// Add a background to the select level page
var selectLevelBackground = LK.getAsset('BackgroundMenu', {
anchorX: 0.5,
anchorY: 0.5
});
selectLevelBackground.x = 2048 / 2;
selectLevelBackground.y = 2732 / 2;
selectLevelContainer.addChild(selectLevelBackground);
// Add a title to the select level page
var selectLevelTitle = new TextElement('Select Level', 150, 0xFFFFFF, "'Press Start 2P', cursive", 2048 / 2, 500);
selectLevelContainer.addChild(selectLevelTitle);
// Add a back button to return to the main menu
var backButton = new Button('Back', 2048 / 2, 2400, function (x, y, obj) {
selectLevelContainer.visible = false; // Hide the select level page
menuContainer.visible = true; // Show the main menu
});
selectLevelContainer.addChild(backButton);
// Add 'How to Play' button to the select level page
var howToPlayButton = new Button('How to Play', 2048 / 2, 2100, function (x, y, obj) {
// Add logic for how to play button
});
selectLevelContainer.addChild(howToPlayButton);
var levelNames = ['arrow', 'saw', 'ninja', 'star', 'circle']; // Conventional levels
var endlessModeName = 'endless'; // Endless mode
var levelSelectors = []; // Array to store level selectors
for (var i = 0; i < levelNames.length + 1; i++) {
var levelName = i < levelNames.length ? levelNames[i] : endlessModeName; // Add endless mode after last level
var levelSelector;
var levelAssets = {
'arrow': levelCompletedArrow ? 'LevelArrowEndless' : 'LevelBloq',
'saw': levelCompletedSaw ? 'LevelSawEndless' : 'LevelBloq',
'star': levelCompletedStar ? 'LevelStarEndless' : 'LevelBloq',
'ninja': levelCompletedNinja ? 'LevelNinjaEndless' : 'LevelBloq',
'circle': levelCompletedCircle ? 'LevelCircleEndless' : 'LevelBloq',
'endless': 'LevelBloq'
};
levelSelector = LK.getAsset(levelAssets[levelName], {
anchorX: 0.5,
anchorY: 0.5
});
levelSelector.x = 2048 / 2;
levelSelector.y = 1300; // Align vertically
levelSelector.levelType = levelName;
levelSelector.down = function (index) {
// Create a closure to capture the current index
return function (x, y, obj) {
if (true) {
leftArrow.buttonAsset.down = null; // Disable left arrow button
rightArrow.buttonAsset.down = null; // Disable right arrow button
backButton.buttonAsset.down = null; // Disable back button
howToPlayButton.buttonAsset.down = null; // Disable how to play button
if (!this.soundPlayed) {
LK.getSound('InitialLevel').play(); // Play initial level sound
this.soundPlayed = true; // Ensure the sound only plays once
}
LK.setTimeout(function () {
// Add a 3-second cooldown before starting the level
gamestart = true; // Start the game
selectLevelContainer.visible = false;
levelID = index;
console.log("Starting level:", obj.levelType);
}, 3000);
} else {
console.log("Previous level's endless mode not completed. Cannot start this level.");
}
};
}(i); // Pass the current index to the closure
selectLevelContainer.addChild(levelSelector);
// Add level text below each level selector
var levelTextContent = levelName === 'endless' ? 'endless\nmode' : levelName === 'arrow' && levelCompletedArrow ? 'endless\narrow' : levelName === 'saw' && levelCompletedSaw ? 'endless\nsaw' : levelName === 'star' && levelCompletedStar ? 'endless\nstar' : levelName;
var levelText = new Text2(levelTextContent, {
size: 80,
fill: 0xFFFFFF,
font: "'Press Start 2P', cursive"
});
levelText.anchor.set(0.5, 0.5);
levelText.x = levelSelector.x;
levelText.y = levelSelector.y + 300; // Position text below the selector
selectLevelContainer.addChild(levelText);
levelSelector.levelText = levelText; // Store levelText in levelSelector
levelSelectors.push(levelSelector); // Add to array
}
// Add arrow buttons for level navigation
var currentLevelIndex = 0;
function updateLevelSelectors() {
for (var i = 0; i < levelSelectors.length; i++) {
levelSelectors[i].visible = i === currentLevelIndex;
levelSelectors[i].levelText.visible = i === currentLevelIndex;
}
}
var leftArrow = new Button('<', 2048 / 2 - 700, 1300, function (x, y, obj) {
if (currentLevelIndex > 0) {
currentLevelIndex--;
updateLevelSelectors();
}
});
selectLevelContainer.addChild(leftArrow);
var rightArrow = new Button('>', 2048 / 2 + 700, 1300, function (x, y, obj) {
if (currentLevelIndex < levelSelectors.length - 1) {
currentLevelIndex++;
updateLevelSelectors();
}
});
selectLevelContainer.addChild(rightArrow);
updateLevelSelectors();
game.addChild(selectLevelContainer);
}
var levelID = 0;
var lifeQuantity = 3;
var energyQuantity = 100;
var gamestart = false;
function enemyLogic(entity) {
var spawnPositions = [{
x: Math.random() * 2000,
y: 0
}, {
x: Math.random() * 2000,
y: 3000
}, {
x: 0,
y: Math.random() * 2000
}, {
x: 3000,
y: Math.random() * 2000
}];
var position = spawnPositions[Math.floor(Math.random() * spawnPositions.length)];
entity.x = position.x;
entity.y = position.y;
entity.spawnTime = entity.spawnTime || Math.random() * 2000 + 2000;
}
var background = game.addChild(new Background());
var timerTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
timerTxt.anchor.set(0.5, 0);
timerTxt.visible = false; // Initially hide the timer text
LK.gui.top.addChild(timerTxt);
var elapsedTime = 0;
var timerInterval = LK.setInterval(function () {
if (!gamestart) {
return;
} // Ensure timer only updates when gamestart is true
if (gamestart && !timerTxt.visible) {
timerTxt.visible = true; // Show timer text when game starts
} else if (!gamestart && timerTxt.visible) {
timerTxt.visible = false; // Hide timer text when game is not started
}
elapsedTime++;
if (elapsedTime >= 30 && (levelID === 1 && !levelCompletedSaw || levelID === 2 && !levelCompletedNinja || levelID === 3 && !levelCompletedStar || levelID === 0 && !levelCompletedArrow || levelID === 4 && !levelCompletedCircle)) {
gamestart = false;
if (levelID === 0) {
levelCompletedArrow = true;
storage.levelCompletedArrow = true; // Save to cloud
} else if (levelID === 1) {
levelCompletedSaw = true;
storage.levelCompletedSaw = true; // Save to cloud
} else if (levelID === 2) {
levelCompletedNinja = true;
storage.levelCompletedNinja = true; // Save to cloud
} else if (levelID === 3) {
levelCompletedStar = true;
storage.levelCompletedStar = true; // Save to cloud
} else if (levelID === 4) {
levelCompletedCircle = true;
storage.levelCompletedCircle = true; // Save to cloud
}
LK.showYouWin(); // Show "you win" and reset the game state
}
var minutes = Math.floor(elapsedTime / 60); // Calculate minutes
var seconds = elapsedTime % 60; // Calculate remaining seconds
var timeString = minutes > 0 ? minutes + "m " + seconds + "s" : seconds + "s"; // Format time string
timerTxt.setText(timeString);
}, 1000);
var player = game.addChild(new Player());
player.x = 2048 / 2; // Center the player on the x-axis
player.y = 2732 / 2; // Center the player on the y-axis
game.up = function (x, y, obj) {
player.scaleX = 1;
player.scaleY = 1;
if (energyDecreaseInterval) {
LK.clearInterval(energyDecreaseInterval); // Clear interval when player returns to normal size
}
};
game.down = function (x, y, obj) {
if (energy.value > 0) {
// Check if energy is greater than 0
player.scaleX = 0.5;
player.scaleY = 0.5;
energyDecreaseInterval = LK.setInterval(function () {
energy.decrease(2); // Decrease energy by 2%
energyText.setText(energy.value + '%'); // Update energy text
if (energy.value <= 0) {
player.scaleX = 1; // Reset player size if energy depletes
player.scaleY = 1;
LK.clearInterval(energyDecreaseInterval); // Clear interval
}
}, 1000); // Decrease energy every second
}
};
// Create a list to store EnemyArrow instances
function spawnEnemy(type, interval, levelCheck, enemyArray, enemyClass) {
return LK.setInterval(function () {
if (!gamestart || !levelCheck()) {
return;
}
var newEnemy = game.addChild(new enemyClass());
enemyArray.push(newEnemy);
newEnemy.spawnTime = Date.now();
LK.setTimeout(function () {
if (enemyArray.includes(newEnemy) && Date.now() - newEnemy.spawnTime >= 10000) {
newEnemy.destroy();
enemyArray.splice(enemyArray.indexOf(newEnemy), 1);
}
}, 20000);
}, interval);
}
var enemyArrows = [];
var enemySaw = [];
var enemyNinjas = []; // New array to store EnemyNinja instances
var enemyNinjaClones = []; // New array to store EnemyNinjaClone instances
var enemyStars = []; // New array to store EnemyStar instances
var enemyCircles = []; // New array to store EnemyCircle instances
var enemyArrowInterval = spawnEnemy('arrow', 700, function () {
return levelID === 0;
}, enemyArrows, EnemyArrow);
var enemySawInterval = spawnEnemy('saw', 1000, function () {
return levelID === 1;
}, enemySaw, EnemySaw);
var enemyNinjaInterval = spawnEnemy('ninja', 1200, function () {
return levelID === 2;
}, enemyNinjas, EnemyNinja);
var enemyStarInterval = spawnEnemy('star', 1500, function () {
return levelID === 3;
}, enemyStars, EnemyStar);
var enemyCircleInterval = spawnEnemy('circle', 700, function () {
return levelID === 4;
}, enemyCircles, EnemyCircle);
var lifeIcons = [];
for (var i = 0; i < lifeQuantity; i++) {
var lifeIcon = game.addChild(new Life());
lifeIcon.x = 2048 / 2 - 600 + i * 160; // Position each life icon to the right of the previous one
lifeIcon.y = 100; // Align vertically with the timer
lifeIcons.push(lifeIcon);
}
// Function to update life icons when life decreases
function updateLifeIcons() {
for (var i = 0; i < lifeIcons.length; i++) {
if (i < lifeQuantity) {
lifeIcons[i].visible = true;
} else {
lifeIcons[i].visible = false;
}
}
}
var energy = game.addChild(new Energy());
energy.x = 2048 / 2 + 600; // Position energy to the right of the timer
energy.y = 100; // Align vertically with the timer
var energyText = new Text2(energyQuantity + '%', {
size: 80,
fill: 0xFFFFFF
});
energyText.anchor.set(1, 0.5); // Anchor to the right center
energyText.x = energy.x - 100; // Position to the left of energy
energyText.y = energy.y;
game.addChild(energyText);
var rangerlimited = game.addChild(new RangedLimiter());
rangerlimited.x = 2048 / 2; // Center the RangedLimiter on the x-axis
rangerlimited.y = 2732 / 2; // Center the RangedLimiter on the y-axis
// Create an initial menu
var menuContainer = new Container();
/*
* Menu inicial
*/
var menuBackground = LK.getAsset('BackgroundMenu', {
anchorX: 0.5,
anchorY: 0.5
});
menuBackground.x = 2048 / 2;
menuBackground.y = 2732 / 2;
menuContainer.addChild(menuBackground);
// Add a title to the menu
var title = new TextElement('Game Title', 150, 0xFFFFFF, "'Press Start 2P', cursive", 2048 / 2, 500);
menuContainer.addChild(title);
// Create buttons
var startButton = new Button('Game Start', 2048 / 2, 1200, function (x, y, obj) {
menuContainer.visible = false; // Hide the menu
showSelectLevelPage(); // Redirect to 'select level' page
});
menuContainer.addChild(startButton);
var recordButton = new Button('Record', 2048 / 2, 1700, function (x, y, obj) {
menuContainer.visible = false; // Hide the main menu
showRecordsPage(); // Show the records page
});
menuContainer.addChild(recordButton);
var creditsButton = new Button('Credits', 2048 / 2, 2200, function (x, y, obj) {
showCreditsPage();
});
menuContainer.addChild(creditsButton);
function showCreditsPage() {
// Create a new container for the credits page
var creditsContainer = new Container();
// Add the credits background
var creditsBackground = LK.getAsset('Credits', {
anchorX: 0.5,
anchorY: 0.5
});
creditsBackground.x = 2048 / 2;
creditsBackground.y = 2732 / 2;
creditsContainer.addChild(creditsBackground);
// Add event listener to hide credits page on touch
creditsBackground.down = function (x, y, obj) {
creditsContainer.visible = false; // Hide the credits page
menuContainer.visible = true; // Show the main menu
};
// Add the credits page to the game
game.addChild(creditsContainer);
}
game.addChild(menuContainer);
;
// Function to display the records page
function showRecordsPage() {
// Create a new container for the records page
var recordsContainer = new Container();
// Add a black background to the records page
var recordsBackground = LK.getAsset('BackgroundMenu', {
anchorX: 0.5,
anchorY: 0.5
});
recordsBackground.x = 2048 / 2;
recordsBackground.y = 2732 / 2;
recordsContainer.addChild(recordsBackground);
// Add a title to the records page
var recordsTitle = new TextElement('Records', 150, 0xFFFFFF, "'Press Start 2P', cursive", 2048 / 2, 500);
recordsContainer.addChild(recordsTitle);
var backButtonAsset = LK.getAsset('Buttom', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
backButtonAsset.x = 2048 / 2;
backButtonAsset.y = 2300;
recordsContainer.addChild(backButtonAsset);
var backButton = new Text2('Back', {
size: 100,
fill: 0xFFFFFF,
font: "'Press Start 2P', cursive"
});
backButton.anchor.set(0.5, 0.5);
backButton.x = 2048 / 2;
backButton.y = 2400;
recordsContainer.addChild(backButton);
// Add event listener to 'Back' button
backButtonAsset.down = function (x, y, obj) {
LK.getSound('ButtomSound').play();
recordsContainer.visible = false; // Hide the records page
menuContainer.visible = true; // Show the main menu
};
// Add the records page to the game
game.addChild(recordsContainer);
}