User prompt
haz que los clone ninja salgan en las verticales de ninja
User prompt
haz que los cloneninja salgan verticalmente al original
User prompt
haz que en vez de 90° sean 45°
User prompt
haz que no puedan haber más de 16 cloneninja y que vayan eliminando los primeros
Code edit (1 edits merged)
Please save this source code
User prompt
cuando ninja se separe en 4, que suene ninjasepare 4 veces con un pocodesface
User prompt
agrega ninja created soun cuando se crea un ninja
User prompt
no funciona correctamente el codigo
Code edit (1 edits merged)
Please save this source code
User prompt
haz que ninja al estar cerca de player se divida en 4 ninja clone en un angulo de 90° cada uno
User prompt
agrega correctamente enemyninjaclone al sistema de daño
Code edit (2 edits merged)
Please save this source code
User prompt
crea un clon de ninja llamado EnemyNinjaClone y agregalo al sistema de daño y su lista
User prompt
Haz que estrella despues de 2 segundos se destruya y se elimine de su lista
User prompt
Haz que estrella cuando este a cerca de 300 pixeles de la ultima posición de player, desde su creación, se destruya
User prompt
Haz que estrella cuando este a cerca de 300 pixeles de la ultima posición de player se destruya
User prompt
ninja sigue haciendo daño aunque se destruya
Code edit (1 edits merged)
Please save this source code
User prompt
haz que ninja despues de entre 2->4 segundos se destruya
User prompt
cuando finalice la carga que suene sawcharge
User prompt
agrega un sonido a saw cuando se crea
User prompt
dale una pequeña alteración al sonido de flecha cada vez que aparezcan para que no suenen iguales
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
cuando una flecha sea creada que suene arrowcreated
/**** * 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 }); enemyLogic(self); var angle = Math.atan2(player.y - self.y, player.x - self.x); var speed = 8; // Set speed for Circle 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 vertically aligned with the original Ninja for (var i = 0; i < 4; i++) { var clone = new EnemyNinjaClone(); clone.x = self.x; clone.y = self.y + (i - 1.5) * 100; // Position clones vertically with 100px spacing clone.update = function () { this.y += Math.sin(angle) * speed; this.rotation += 0.1; }; 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; if (levelNames[i] === 'arrow' && levelCompletedArrow) { levelSelector = LK.getAsset('LevelArrowEndless', { anchorX: 0.5, anchorY: 0.5 }); } else if (levelNames[i] === 'saw' && levelCompletedSaw) { levelSelector = LK.getAsset('LevelSawEndless', { anchorX: 0.5, anchorY: 0.5 }); } else if (levelNames[i] === 'star' && levelCompletedStar) { levelSelector = LK.getAsset('LevelStarEndless', { anchorX: 0.5, anchorY: 0.5 }); } else if (levelNames[i]) { levelSelector = LK.getAsset('Level' + levelNames[i].charAt(0).toUpperCase() + levelNames[i].slice(1), { anchorX: 0.5, anchorY: 0.5 }); } else { levelSelector = LK.getAsset('LevelBloq', { 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', 1300, 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); }
===================================================================
--- original.js
+++ change.js
@@ -102,21 +102,17 @@
// 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
+ // Create 4 Ninja Clones vertically aligned with the original Ninja
for (var i = 0; i < 4; i++) {
var clone = new EnemyNinjaClone();
clone.x = self.x;
- clone.y = self.y;
- var cloneAngle = Math.PI / 2 * i; // 90-degree increments for vertical movement
- clone.update = function (cloneAngle) {
- return function () {
- this.x = self.x; // Maintain the x position of the original
- this.y += Math.sin(cloneAngle) * speed; // Move vertically
- this.rotation += 0.1;
- };
- }(cloneAngle);
+ clone.y = self.y + (i - 1.5) * 100; // Position clones vertically with 100px spacing
+ clone.update = function () {
+ this.y += Math.sin(angle) * speed;
+ this.rotation += 0.1;
+ };
game.addChild(clone);
// Limit the number of EnemyNinjaClones to 16
if (enemyNinjaClones.length >= 16) {
var oldestClone = enemyNinjaClones.shift(); // Remove the oldest clone