User prompt
the extra bullets should have a different icon
User prompt
in the player.shoot method. fix the extra bullet icons
Code edit (1 edits merged)
Please save this source code
User prompt
set the background image
User prompt
add another sprite for bullets
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: powerUps.push is not a function' in or related to this line: 'powerUps.push(powerUp);' Line Number: 171
Code edit (2 edits merged)
Please save this source code
User prompt
add a global variable for the powerup level
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self is undefined' in or related to this line: 'bullet1.x = self.x - 20;' Line Number: 142
User prompt
give the bullets a direction variable
Initial prompt
Defence Attack
/**** * Classes ****/ // Bullet class 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.direction = 45; // Add direction variable self.update = function () { self.y += self.speed * Math.cos(self.direction); // Update y position based on speed and direction self.x += self.speed * Math.sin(self.direction); // Update x position based on speed and direction }; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.shoot = function () { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y - 50; bullet.direction = 0; bullets.push(bullet); game.addChild(bullet); }; }); // PowerUp class var PowerUp = Container.expand(function () { var self = Container.call(this); var powerUpGraphics = self.attachAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 2; }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Spaceship class var Spaceship = Container.expand(function () { var self = Container.call(this); var spaceshipGraphics = self.attachAsset('spaceship', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2500; // Initialize arrays var spaceships = []; var bullets = []; var powerUps = []; // Initialize powerup level var powerUpLevel = 0; // Game update function game.update = function () { // Update spaceships for (var i = spaceships.length - 1; i >= 0; i--) { var spaceship = spaceships[i]; spaceship.update(); if (spaceship.y > 2732) { spaceship.destroy(); spaceships.splice(i, 1); } } // Update bullets for (var j = bullets.length - 1; j >= 0; j--) { var bullet = bullets[j]; bullet.update(); if (bullet.y < 0) { bullet.destroy(); bullets.splice(j, 1); } } // Update power-ups for (var k = powerUps.length - 1; k >= 0; k--) { var powerUp = powerUps[k]; powerUp.update(); if (powerUp.y > 2732) { powerUp.destroy(); powerUps.splice(k, 1); } } // Check for collisions checkCollisions(); }; // Function to check for collisions function checkCollisions() { // Check bullet and spaceship collisions for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; for (var j = spaceships.length - 1; j >= 0; j--) { var spaceship = spaceships[j]; if (bullet.intersects(spaceship)) { bullet.destroy(); spaceship.destroy(); bullets.splice(i, 1); spaceships.splice(j, 1); break; } } } // Check player and power-up collisions for (var k = powerUps.length - 1; k >= 0; k--) { var powerUp = powerUps[k]; if (player.intersects(powerUp)) { powerUp.destroy(); powerUps.splice(k, 1); // Upgrade player's gun } ; } } // Function to spawn spaceships function spawnSpaceships() { var spaceship = new Spaceship(); spaceship.x = Math.random() * 2048; spaceship.y = -50; spaceships.push(spaceship); game.addChild(spaceship); } // Function to spawn power-ups function spawnPowerUp() { var powerUp = new PowerUp(); powerUp.x = Math.random() * 2048; powerUp.y = -50; powerUps.push(powerUp); game.addChild(powerUp); } // Set intervals for spawning LK.setInterval(spawnSpaceships, 1000); LK.setInterval(spawnPowerUp, 10000); // Player controls game.down = function (x, y, obj) { player.x = x; player.y = y; }; game.move = function (x, y, obj) { player.x = x; player.y = y; }; game.up = function (x, y, obj) { player.shoot(); };
===================================================================
--- original.js
+++ change.js
@@ -131,21 +131,10 @@
if (player.intersects(powerUp)) {
powerUp.destroy();
powerUps.splice(k, 1);
// Upgrade player's gun
- player.shoot = function () {
- var bullet1 = new Bullet();
- bullet1.x = player.x - 20;
- bullet1.y = player.y - 50;
- bullets.push(bullet1);
- game.addChild(bullet1);
- var bullet2 = new Bullet();
- bullet2.x = player.x + 20;
- bullet2.y = player.y - 50;
- bullets.push(bullet2);
- game.addChild(bullet2);
- };
}
+ ;
}
}
// Function to spawn spaceships
function spawnSpaceships() {
spaceship, retro game, 2d. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
yellow ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
game flying saucer. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
star field. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
neon circle with a 'p'. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
fire explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
double sided space ship. symetrical. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows, color, neon
hot stone, red. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
large rock. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows