User prompt
Limit bullets firing rate to 3 at a time
User prompt
Add 1up asset to screen in front of player after 50 kills
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'destroy')' in or related to this line: 'game.children[i].destroy();' Line Number: 248
User prompt
Add 1up sound when 1up is shot
User prompt
Shoot 1up add free life
User prompt
Allow player to collect 1up for extra life
User prompt
Add 1up asset to screen in front of player after 20 kills
User prompt
Move score 300 pixels left
User prompt
Move score over 300 pixels
User prompt
Move score to the middle top of screen
User prompt
Limit bullets firing rate to 2 at a time
User prompt
Allocate player 3 lives.
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var j = enemies.length - 1; j >= 0; j--) {' Line Number: 133
User prompt
Adjust text to reflect accuracy
User prompt
Create text2 dialogue bar at bottom of screen
User prompt
Create stats bar at bottom of screen to show accuracy
User prompt
Create text to show hit accuracy at bottom of the screen
User prompt
Limit bullets fired only 3 allowed on screen at any time
User prompt
Only 3 bullets can be fired every second
User prompt
Reduct 1point when bullet misses
User prompt
Play startmusic on loop
User prompt
You win game when you reach level 11
User prompt
You win game once you defeat enemy10
User prompt
Change enemy at level 10
User prompt
Play level 10
/**** * Classes ****/ // Define a class for bullets var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.x += self.speedX; self.y += self.speedY; if (self.x > 2048 + 50 || self.y < -50) { self.destroy(); } }; }); // Define a class for enemies var Enemy = Container.expand(function () { var self = Container.call(this); var enemyAssetId = LK.getScore() >= 90 ? 'Enemy10' : LK.getScore() >= 80 ? 'Enemy9' : LK.getScore() >= 70 ? 'Enemy8' : LK.getScore() >= 60 ? 'Enemy7' : LK.getScore() >= 50 ? 'Enemy6' : LK.getScore() >= 40 ? 'Enemy5' : LK.getScore() >= 30 ? 'enemy4' : LK.getScore() >= 20 ? 'enemy3' : LK.getScore() >= 10 ? 'enemy2' : 'enemy'; var enemyGraphics = self.attachAsset(enemyAssetId, { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5 + Math.floor(LK.getScore() / 20); self.update = function () { self.x -= self.speed; self.y += Math.sin(LK.ticks / 20) * 5; // Make enemy fly up and down if (enemyAssetId === 'enemy2' || enemyAssetId === 'enemy3') { self.y += Math.sin(LK.ticks / 10) * 10; // Make enemy2 and enemy3 fly in small circles self.x += Math.cos(LK.ticks / 10) * 10; // Add horizontal movement for circular path } if (self.y > 1366) { // Ensure enemies stay in the top half of the screen self.y = 1366; } if (self.x < -50) { self.destroy(); } }; }); // Define a class for a steady moving background var MovingBackground = Container.expand(function () { var self = Container.call(this); var bg1 = self.attachAsset('background', { anchorX: 0, anchorY: 0 }); var bg2 = self.attachAsset('background2', { anchorX: 0, anchorY: 0 }); bg1.x = 0; bg2.x = 2048; // Position the second background right after the first one self.speed = 4 + Math.floor(LK.getScore() / 50); self.update = function () { bg1.x -= self.speed; bg2.x -= self.speed; // Reset positions to create a continuous loop if (bg1.x <= -2048) { bg1.x = bg2.x + 2048; } if (bg2.x <= -2048) { bg2.x = bg1.x + 2048; } }; }); //<Assets used in the game will automatically appear here> // Define a class for the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.lives = 3; self.speed = 5; self.jumpHeight = 40; self.update = function () {}; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ var movingBackground = game.addChild(new MovingBackground()); LK.getSound('Startmusic').play(); // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2 - 600; // Move player further back player.y = 2732 / 2 - 100; // Move player up a bit // Initialize enemies var enemies = []; var enemySpawnInterval = 100; var enemySpawnCounter = 0; // Create a new Text2 object to display the score var scoreText = new Text2('0', { size: 100, fill: 0xFFFFFF }); // Add the score text to the game GUI at the top center of the screen LK.gui.top.addChild(scoreText); scoreText.anchor.set(0.5, 0); // Center the score text horizontally scoreText.x = 2048 / 2; scoreText.y = 0; // Create a new Text2 object to display the level var levelText = new Text2('Level 1', { size: 100, fill: 0xFFFFFF }); // Add the level text to the game GUI at the top left of the screen LK.gui.topLeft.addChild(levelText); levelText.x = 20; levelText.y = 0; // Create a new Text2 object to display the lives var livesText = new Text2('Lives: 3', { size: 100, fill: 0xFFFFFF }); // Add the lives text to the game GUI at the top right of the screen LK.gui.topRight.addChild(livesText); livesText.x = -20 - livesText.width; livesText.y = 0; // Add the score text next to the level text scoreText.x = levelText.x + levelText.width + 20 - 300; scoreText.y = levelText.y; // Handle game updates game.update = function () { player.update(); movingBackground.update(); // Spawn enemies enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { // Add more enemies every 10 points if (LK.getScore() % 10 === 0 && LK.getScore() !== 0) { // Check if the player has reached level 11 if (Math.floor(LK.getScore() / 10) + 1 >= 11) { LK.showYouWin(); // Show "you win" screen return; // Exit the update function to prevent further updates } // Update level text var currentLevel = Math.floor(LK.getScore() / 10) + 1; levelText.setText('Level ' + currentLevel); for (var i = 0; i < 2; i++) { // Add two enemies var extraEnemy = new Enemy(); extraEnemy.x = 2048; extraEnemy.y = Math.random() * (2732 / 2); // Randomize Y position in the top half enemies.push(extraEnemy); game.addChild(extraEnemy); } } var enemy = new Enemy(); enemy.x = 2048; enemy.y = Math.random() * (2732 / 2); // Randomize Y position in the top half to allow flying enemies.push(enemy); game.addChild(enemy); // Randomize the spawn interval for the next enemy enemySpawnInterval = Math.floor(Math.random() * 150) + 50; enemySpawnCounter = 0; } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j])) { LK.effects.flashScreen(0xff0000, 1000); player.lives -= 1; livesText.setText('Lives: ' + player.lives); if (player.lives <= 0) { LK.showGameOver(); } enemies[j].destroy(); enemies.splice(j, 1); continue; } // Check for bullet collision with enemies for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i] instanceof Bullet && game.children[i].intersects(enemies[j])) { // Create explosion effect var explosion = LK.getAsset('fire', { anchorX: 0.5, anchorY: 0.5, x: enemies[j].x, y: enemies[j].y }); game.addChild(explosion); // Remove explosion after a short delay LK.setTimeout(function () { explosion.destroy(); }, 500); game.children[i].destroy(); enemies[j].destroy(); if (enemies[j].attachAsset('enemy2')) { // Check if the player has reached 20 kills if (LK.getScore() % 20 === 0 && LK.getScore() !== 0) { // Add 1up asset in front of the player var oneUp = LK.getAsset('1up', { anchorX: 0.5, anchorY: 0.5, x: player.x + player.width + 50, // Position it in front of the player y: player.y }); game.addChild(oneUp); } LK.getSound('enemy2_destroyed').play(); } else { LK.getSound('enemy_destroyed').play(); } LK.setScore(LK.getScore() + 1); // Add 1 point to score scoreText.setText(LK.getScore()); enemies.splice(j, 1); break; enemies.splice(j, 1); break; } } } }; // Handle player jump game.down = function (x, y, obj) { // Check if the number of bullets on screen is less than 2 var bulletCount = 0; for (var i = 0; i < game.children.length; i++) { if (game.children[i] instanceof Bullet) { bulletCount++; } } if (bulletCount < 2) { var newBullet = new Bullet(); var angle = Math.atan2(y - player.y, x - player.x); newBullet.x = player.x + player.width / 2; // Adjust the bullet's initial x position to the cannon's position newBullet.y = player.y; // Adjust the bullet's initial y position to the cannon's position newBullet.speedX = Math.cos(angle) * newBullet.speed; newBullet.speedY = Math.sin(angle) * newBullet.speed; game.addChild(newBullet); LK.getSound('shoot').play(); } };
===================================================================
--- original.js
+++ change.js
@@ -199,8 +199,20 @@
}, 500);
game.children[i].destroy();
enemies[j].destroy();
if (enemies[j].attachAsset('enemy2')) {
+ // Check if the player has reached 20 kills
+ if (LK.getScore() % 20 === 0 && LK.getScore() !== 0) {
+ // Add 1up asset in front of the player
+ var oneUp = LK.getAsset('1up', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: player.x + player.width + 50,
+ // Position it in front of the player
+ y: player.y
+ });
+ game.addChild(oneUp);
+ }
LK.getSound('enemy2_destroyed').play();
} else {
LK.getSound('enemy_destroyed').play();
}
🔥 fire. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Mario driving a tank. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Wario flying an aeroplane. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Waluigi flying a helicopter. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows