Code edit (1 edits merged)
Please save this source code
User prompt
haz que los textos sean reusables
User prompt
Please fix the bug: 'startButtonAsset is not defined' in or related to this line: 'startButtonAsset.down = function (x, y, obj) {' Line Number: 634
User prompt
Please fix the bug: 'recordButtonAsset is not defined' in or related to this line: 'recordButtonAsset.down = function (x, y, obj) {' Line Number: 542
User prompt
otimiza el codigo de los botones para hacerlos reusables
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'push')' in or related to this line: 'enemyArray.push(newEnemy);' Line Number: 434
User prompt
Optimize enemy spawning logic by reducing redundant checks
User prompt
Optimize enemy spawning logic by reducing redundant checks
User prompt
Optimize collision detection by using a single loop for all enemies
User prompt
Optimize collision detection by using a single loop for all enemies Optimize enemy spawning logic by reducing redundant checks
User prompt
Please fix the bug: 'ReferenceError: topBound is not defined' in or related to this line: 'targetY = Math.max(topBound, Math.min(bottomBound, targetY));' Line Number: 217
User prompt
Please fix the bug: 'ReferenceError: leftBound is not defined' in or related to this line: 'targetX = Math.max(leftBound, Math.min(rightBound, targetX));' Line Number: 216
User prompt
Analiza todo el codigo del juego Busca que pueda causar un retrazo busca metodos de optimizacioĢn para el codigo pule las mecanicas
User prompt
Analiza todo el codigo del juego Busca que pueda causar un retrazo busca metodos de optimizacioĢn para el codigo pule las mecanicas
User prompt
Analiza todo el codigo del juego Busca que pueda causar un retrazo busca metodos de optimizacioĢn para el codigo pule las mecanicas
User prompt
la optimizacioĢn es muy mala, el juego anda trabajo
Code edit (3 edits merged)
Please save this source code
User prompt
haz que enemyninja se elimine al crear los newarrow
Code edit (1 edits merged)
Please save this source code
User prompt
haz: - Enemy ninja se divide en dos a menos de 400 pixeles de player - Enemy ninja solo de divide 1 vez - Los new arrow - Los new arrow son el doble de rapidos - Los new arrow aparecen en + 45 grados y - 45 de player nre position
User prompt
haz: - Enemy ninja se divide en dos a menos de 400 pixeles de player - Enemy ninja solo de divide 1 vez - Los new ninjas no se clonan - Los new ninjas son el doble de rapidos - Los new ninjas aparecene n + 45 grados y - 45 de player nre position
User prompt
haz: - Enemy ninja se divide en dos a menos de 400 pixeles de player - Los new ninjas no se clonan - Los new ninjas son el doble de rapidos
User prompt
haz que la multiplicacioĢn solo funcione una vez y los clones no tengan esta caracteristica
User prompt
haz que enemyninja cuando este a maĢs de 400 pixeles de player se divida en 2 a 45 grados menos y maĢs de la nueva posicioĢn de layer
User prompt
haz que enemyninja colisione con player
/**** * Plugins ****/ var facekit = LK.import("@upit/facekit.v1"); var storage = LK.import("@upit/storage.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 EnemyArrow = Container.expand(function () { var self = Container.call(this); var bEnemyArrowGraphics = self.attachAsset('EnemyArrow', { anchorX: 0.5, anchorY: 0.5 }); enemyLogic(self); var targetX = player.x; var targetY = player.y; self.update = function () { if (!gamestart) { return; } var dx = targetX - self.x; var dy = targetY - self.y; var angle = Math.atan2(dy, dx); self.x += Math.cos(angle) * 8.5; self.y += Math.sin(angle) * 8.5; self.rotation = angle; if (Math.abs(self.x - targetX) < 5 && Math.abs(self.y - targetY) < 5) { targetX += Math.cos(angle) * 1000; targetY += Math.sin(angle) * 1000; } if (self.x < 0 || self.x > 3000 || self.y < 0 || self.y > 3000) { self.destroy(); } }; }); var EnemyNinja = Container.expand(function () { var self = Container.call(this); var bEnemyNinjaGraphics = self.attachAsset('EnemyNinja', { anchorX: 0.5, anchorY: 0.5 }); enemyLogic(self); var targetX = player.x; var targetY = player.y; self.update = function () { if (!gamestart) { return; } var dx = targetX - self.x; var dy = targetY - self.y; var angle = Math.atan2(dy, dx); self.x += Math.cos(angle) * 5; // Ninja moves faster self.y += Math.sin(angle) * 5; self.rotation += 0.05; // Rotate the ninja continuously if (Math.abs(self.x - targetX) < 5 && Math.abs(self.y - targetY) < 5) { targetX += Math.cos(angle) * 1000; targetY += Math.sin(angle) * 1000; } if (!self.hasSplit && Math.sqrt(dx * dx + dy * dy) < 400) { self.hasSplit = true; var angleOffset = Math.PI / 4; // 45 degrees in radians for (var i = -1; i <= 1; i += 2) { var newArrow = new NewArrow(); newArrow.x = self.x; newArrow.y = self.y; newArrow.rotation = angle + i * angleOffset; enemyArrows.push(newArrow); game.addChild(newArrow); } } if (self.x < 0 || self.x > 3000 || self.y < 0 || self.y > 3000) { self.destroy(); // Remove the EnemyNinja from the game } }; }); var EnemySaw = Container.expand(function () { var self = Container.call(this); var bEnemySawGraphics = self.attachAsset('EnemySaw', { anchorX: 0.5, anchorY: 0.5 }); enemyLogic(self); var targetX = player.x; var targetY = player.y; self.update = function () { if (!gamestart) { return; } var dx = targetX - self.x; var dy = targetY - self.y; var angle = Math.atan2(dy, dx); if (!self.stopSaw && !self.hasStopped && Math.sqrt(dx * dx + dy * dy) < 100) { self.stopSaw = true; self.hasStopped = true; LK.setTimeout(function () { self.stopSaw = false; targetX = player.x; targetY = player.y; }, 2000); } if (!self.stopSaw) { var speedMultiplier = self.hasStopped ? 1.5 : 1; self.x += Math.cos(angle) * 7.5 * speedMultiplier; self.y += Math.sin(angle) * 7.5 * speedMultiplier; } self.rotation += 0.03; if (Math.abs(self.x - targetX) < 5 && Math.abs(self.y - targetY) < 5) { targetX += Math.cos(angle) * 1000; targetY += Math.sin(angle) * 1000; } // Check if the EnemySaw has moved to the opposite side of its spawn point if (self.x < 0 || self.x > 3000 || self.y < 0 || self.y > 3000) { self.destroy(); } }; }); 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 NewArrow = Container.expand(function () { var self = Container.call(this); var newArrowGraphics = self.attachAsset('EnemyArrow', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { if (!gamestart) { return; } self.x += Math.cos(self.rotation) * 17; // Double the speed of regular arrows self.y += Math.sin(self.rotation) * 17; if (self.x < 0 || self.x > 3000 || self.y < 0 || self.y > 3000) { self.destroy(); } }; }); 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.05; 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; for (var i = 0; i < enemyArrows.length; i++) { if (self.intersects(enemyArrows[i])) { lifeQuantity = Math.max(0, lifeQuantity - 1); updateLifeIcons(); enemyArrows[i].destroy(); // Destroy the enemy arrow enemyArrows.splice(i, 1); // Remove the enemy arrow from the array if (lifeQuantity === 0) { self.destroy(); // Eliminate player LK.showGameOver(); // End the game } break; } } for (var i = 0; i < enemySaw.length; i++) { if (self.intersects(enemySaw[i])) { lifeQuantity = Math.max(0, lifeQuantity - 1); updateLifeIcons(); enemySaw[i].destroy(); // Destroy the enemy saw enemySaw.splice(i, 1); // Remove the enemy saw from the array if (lifeQuantity === 0) { self.destroy(); // Eliminate player gamestart = false; // Set gamestart to false LK.showGameOver(); // End the game } break; } } for (var i = 0; i < enemyNinjas.length; i++) { if (self.intersects(enemyNinjas[i])) { lifeQuantity = Math.max(0, lifeQuantity - 1); updateLifeIcons(); enemyNinjas[i].destroy(); // Destroy the enemy ninja enemyNinjas.splice(i, 1); // Remove the enemy ninja from the array if (lifeQuantity === 0) { self.destroy(); // Eliminate player gamestart = false; // Set gamestart to false LK.showGameOver(); // End the game } 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 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ function showSelectLevelPage() { // Create a new container for the select level page 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 Text2('Select Level', { size: 150, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" }); selectLevelTitle.anchor.set(0.5, 0.5); selectLevelTitle.x = 2048 / 2; selectLevelTitle.y = 500; selectLevelContainer.addChild(selectLevelTitle); // Add a back button to return to the main menu var backButtonAsset = LK.getAsset('Buttom', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); backButtonAsset.x = 2048 / 2; backButtonAsset.y = 2300; selectLevelContainer.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; selectLevelContainer.addChild(backButton); // Add event listener to 'Back' button backButtonAsset.down = function (x, y, obj) { selectLevelContainer.visible = false; // Hide the select level page menuContainer.visible = true; // Show the main menu }; // Add level selectors var levelNames = ['endless', 'arrow', 'saw', 'newLevel']; // Added new level with id 3 for (var i = 0; i < levelNames.length; i++) { var levelSelector = LK.getAsset('level', { anchorX: 0.5, anchorY: 0.5 }); levelSelector.x = 2048 / 2 - 600 + i * 600; // Position each level selector in a row levelSelector.y = 1500; // Align vertically levelSelector.levelType = levelNames[i]; // Assign level type to selector // Add interaction to start the game when a level is selected levelSelector.down = function (index) { // Create a closure to capture the current index return function (x, y, obj) { gamestart = true; // Start the game selectLevelContainer.visible = false; // Hide the select level page levelID = index; // Update levelID based on the order of the level selector console.log("Starting level:", obj.levelType); // Log the selected level type // Additional logic to initialize the selected level can be added here }; }(i); // Pass the current index to the closure selectLevelContainer.addChild(levelSelector); // Add level text below each level selector var levelText = new Text2(levelNames[i], { 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); } // Add the select level page to the game game.addChild(selectLevelContainer); } var nameplayer = "aaa"; // Variable to store the player's name var playerTime = 0; // Variable to track the player's time var records = storage.records || [{ name: "kaoshi", time: 120 }, { name: "Slime", time: 110 }, { name: "Pepe", time: 100 }, { name: "Arturo", time: 90 }, { name: "Juan", time: 80 }, { name: "NoSe", time: 70 }, { name: "JJAJA", time: 60 }, { name: "Alguien", time: 50 }, { name: "Leera", time: 40 }]; // List to store player records records = storage.records || records; var levelID = 0; // Numeric variable to track the current level var lifeQuantity = 3; // Initial life quantity var energyQuantity = 100; // Initial energy quantity var gamestart = false; function enemyLogic(entity) { var edge = Math.random(); if (edge < 0.25) { entity.x = Math.random() * 2000; entity.y = 0; } else if (edge < 0.5) { entity.x = Math.random() * 2000; entity.y = 3000; } else if (edge < 0.75) { entity.x = 0; entity.y = Math.random() * 2000; } else { entity.x = 3000; entity.y = Math.random() * 2000; } 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); LK.gui.top.addChild(timerTxt); var elapsedTime = 0; var timerInterval = LK.setInterval(function () { if (!gamestart) { return; } // Ensure timer only updates when gamestart is true elapsedTime++; 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; }; game.down = function (x, y, obj) { player.scaleX = 0.5; player.scaleY = 0.5; }; // Create a list to store EnemyArrow instances var enemyArrows = []; // Create a timer that creates a new EnemyArrow every random interval between 1 and 2 seconds var enemyArrowInterval = LK.setInterval(function () { if (!gamestart || levelID !== 0 && levelID !== 1) { return; } var enemyArrow = game.addChild(new EnemyArrow()); enemyArrows.push(enemyArrow); // Add the new EnemyArrow to the list // Set a timeout to remove the EnemyArrow after 20 seconds LK.setTimeout(function () { if (enemyArrows.includes(enemyArrow)) { enemyArrow.destroy(); enemyArrows.splice(enemyArrows.indexOf(enemyArrow), 1); } }, 20000); }, Math.random() * 380 + 1000); var enemySaw = []; var enemySawInterval = LK.setInterval(function () { if (!gamestart || levelID !== 0 && levelID !== 2) { return; } var newEnemySaw = game.addChild(new EnemySaw()); enemySaw.push(newEnemySaw); // Add the new EnemySaw to the list // Set a timeout to remove the EnemySaw after 20 seconds LK.setTimeout(function () { if (enemySaw.includes(newEnemySaw)) { newEnemySaw.destroy(); enemySaw.splice(enemySaw.indexOf(newEnemySaw), 1); } }, 20000); }, 2000); var enemyNinjas = []; var enemyNinjaInterval = LK.setInterval(function () { if (!gamestart || levelID !== 3) { return; } var newEnemyNinja = game.addChild(new EnemyNinja()); enemyNinjas.push(newEnemyNinja); // Add the new EnemyNinja to the list // Set a timeout to remove the EnemyNinja after 20 seconds LK.setTimeout(function () { if (enemyNinjas.includes(newEnemyNinja)) { newEnemyNinja.destroy(); enemyNinjas.splice(enemyNinjas.indexOf(newEnemyNinja), 1); } }, 20000); }, 1500); // Spawn ninjas more frequently 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 Text2('Game Title', { size: 150, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" // Arcade style font }); title.anchor.set(0.5, 0.5); title.x = 2048 / 2; title.y = 500; menuContainer.addChild(title); // Create buttons var startButtonAsset = LK.getAsset('Buttom', { anchorX: 0.5, anchorY: 0.5, alpha: 0 // Set transparency to 0 }); startButtonAsset.x = 2048 / 2; startButtonAsset.y = 1000; menuContainer.addChild(startButtonAsset); var startButton = new Text2('Game Start', { size: 100, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" // Arcade style font }); startButton.anchor.set(0.5, 0.5); startButton.x = 2048 / 2; startButton.y = 1000; menuContainer.addChild(startButton); var recordButtonAsset = LK.getAsset('Buttom', { anchorX: 0.5, anchorY: 0.5, alpha: 0 // Set transparency to 0 }); recordButtonAsset.x = 2048 / 2; recordButtonAsset.y = 1300; menuContainer.addChild(recordButtonAsset); var recordButton = new Text2('Record', { size: 100, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" // Arcade style font }); recordButton.anchor.set(0.5, 0.5); recordButton.x = 2048 / 2; recordButton.y = 1300; menuContainer.addChild(recordButton); var howToPlayButtonAsset = LK.getAsset('Buttom', { anchorX: 0.5, anchorY: 0.5, alpha: 0 // Set transparency to 0 }); howToPlayButtonAsset.x = 2048 / 2; howToPlayButtonAsset.y = 1600; menuContainer.addChild(howToPlayButtonAsset); var howToPlayButton = new Text2('How to Play', { size: 100, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" // Arcade style font }); howToPlayButton.anchor.set(0.5, 0.5); howToPlayButton.x = 2048 / 2; howToPlayButton.y = 1600; menuContainer.addChild(howToPlayButton); var creditsButtonAsset = LK.getAsset('Buttom', { anchorX: 0.5, anchorY: 0.5, alpha: 0 // Set transparency to 0 }); creditsButtonAsset.x = 2048 / 2; creditsButtonAsset.y = 1900; menuContainer.addChild(creditsButtonAsset); var creditsButton = new Text2('Credits', { size: 100, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" // Arcade style font }); creditsButton.anchor.set(0.5, 0.5); creditsButton.x = 2048 / 2; creditsButton.y = 1900; menuContainer.addChild(creditsButton); game.addChild(menuContainer); ; // Add event listener to 'Record' button recordButtonAsset.down = function (x, y, obj) { // Create a temporary text message var tempMessage = new Text2('Option not yet implemented due to engine errors', { size: 40, fill: 0xFF0000, font: "'Press Start 2P', cursive" }); tempMessage.anchor.set(0.5, 0.5); tempMessage.x = 2048 / 2; tempMessage.y = 2732 - 300; // Position at the bottom of the screen game.addChild(tempMessage); // Set a timeout to remove the message after a few seconds LK.setTimeout(function () { game.removeChild(tempMessage); }, 3000); }; // 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 Text2('Records', { size: 150, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" }); recordsTitle.anchor.set(0.5, 0.5); recordsTitle.x = 2048 / 2; recordsTitle.y = 500; recordsContainer.addChild(recordsTitle); // Create a table for the records var tableStartY = 700; var rowHeight = 150; var columnWidths = [200, 800, 400]; // Widths for Top, Name, Best Time columns // Add table headers var headers = ['Top', 'Name', 'Best Time']; for (var i = 0; i < headers.length; i++) { var header = new Text2(headers[i], { size: 60, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" }); header.anchor.set(0.5, 0.5); header.x = 2048 / 2 - 600 + columnWidths.slice(0, i).reduce(function (a, b) { return a + b; }, 0) + columnWidths[i] / 2; header.y = tableStartY; recordsContainer.addChild(header); } // Add table rows for (var row = 0; row < 10; row++) { for (var col = 0; col < headers.length; col++) { var cellText = ''; if (row < records.length) { if (col === 0) { cellText = "#" + (row + 1).toString(); // Top position } else if (col === 1) { cellText = records[row].name; // Player name } else if (col === 2) { cellText = records[row].time.toString(); // Best time } } var cell = new Text2(cellText, { size: 80, fill: 0xFFFFFF, font: "'Press Start 2P', cursive" }); cell.anchor.set(0.5, 0.5); cell.x = 2048 / 2 - 600 + columnWidths.slice(0, col).reduce(function (a, b) { return a + b; }, 0) + columnWidths[col] / 2; cell.y = tableStartY + (row + 1) * rowHeight; recordsContainer.addChild(cell); } } // Add a back button to return to the main menu 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) { recordsContainer.visible = false; // Hide the records page menuContainer.visible = true; // Show the main menu }; // Add the records page to the game game.addChild(recordsContainer); } startButtonAsset.down = function (x, y, obj) { menuContainer.visible = false; // Hide the menu // Redirect to 'select level' page showSelectLevelPage(); };
===================================================================
--- original.js
+++ change.js
@@ -62,27 +62,24 @@
var angle = Math.atan2(dy, dx);
self.x += Math.cos(angle) * 5; // Ninja moves faster
self.y += Math.sin(angle) * 5;
self.rotation += 0.05; // Rotate the ninja continuously
- // Check if the ninja is close to the player and hasn't split yet
- if (!self.hasSplit && Math.sqrt(dx * dx + dy * dy) < 400) {
- self.hasSplit = true; // Mark as split to prevent further splitting
- // Create two new ninjas at +45 and -45 degrees
- for (var i = -1; i <= 1; i += 2) {
- var newNinja = game.addChild(new EnemyNinja());
- newNinja.x = self.x;
- newNinja.y = self.y;
- var newAngle = angle + i * Math.PI / 4; // +45 and -45 degrees
- newNinja.x += Math.cos(newAngle) * 10; // Offset position slightly
- newNinja.y += Math.sin(newAngle) * 10;
- newNinja.speed = 10; // Double the speed
- enemyNinjas.push(newNinja);
- }
- }
if (Math.abs(self.x - targetX) < 5 && Math.abs(self.y - targetY) < 5) {
targetX += Math.cos(angle) * 1000;
targetY += Math.sin(angle) * 1000;
}
+ if (!self.hasSplit && Math.sqrt(dx * dx + dy * dy) < 400) {
+ self.hasSplit = true;
+ var angleOffset = Math.PI / 4; // 45 degrees in radians
+ for (var i = -1; i <= 1; i += 2) {
+ var newArrow = new NewArrow();
+ newArrow.x = self.x;
+ newArrow.y = self.y;
+ newArrow.rotation = angle + i * angleOffset;
+ enemyArrows.push(newArrow);
+ game.addChild(newArrow);
+ }
+ }
if (self.x < 0 || self.x > 3000 || self.y < 0 || self.y > 3000) {
self.destroy(); // Remove the EnemyNinja from the game
}
};
@@ -163,8 +160,25 @@
self.increase = function (amount) {
self.value = Math.min(100, self.value + amount);
};
});
+var NewArrow = Container.expand(function () {
+ var self = Container.call(this);
+ var newArrowGraphics = self.attachAsset('EnemyArrow', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ if (!gamestart) {
+ return;
+ }
+ self.x += Math.cos(self.rotation) * 17; // Double the speed of regular arrows
+ self.y += Math.sin(self.rotation) * 17;
+ if (self.x < 0 || self.x > 3000 || self.y < 0 || self.y > 3000) {
+ self.destroy();
+ }
+ };
+});
var Player = Container.expand(function () {
var self = Container.call(this);
var faceGraphics = self.attachAsset('faceObject', {
anchorX: 0.5,
ButtomSound
Sound effect
InitialLevel
Sound effect
ArrowCreated
Sound effect
sawcreated
Sound effect
Sawcharge
Sound effect
Ninjacreated
Sound effect
Ninjasepare
Sound effect
StarCreated
Sound effect
CircleCreated
Sound effect
HexagonCreated
Sound effect
GameplayMusic
Music