User prompt
Play the background sound and repeat it after it finishes
User prompt
Continue to play the background sound after the hero dies and the player tries again
User prompt
Play the background sound during the whole game every time
User prompt
Play the background sound continuously for the whole duration of the game
User prompt
Make the explosion sound louder it the hero hits an asteroid
User prompt
Whenever an explosion appears on the screen, make the explosion sound pplay
User prompt
make the whole boss move slowly downwards when it appears
User prompt
spawn asteroids less frequently
User prompt
When the score hits 15, stop spawning enemies and asteroids, and spawn a single boss
User prompt
make one bullet hit cause 1 health loss
User prompt
decrease the number of asteroids spawned
User prompt
When the boss is hit with 10 bullets, he explodes and dies
User prompt
when the boss appears, don't spawn any asteroids or other enemies
User prompt
make the boss appear when the score hits 12
User prompt
Make the hero have 5x the health of a normal enemy
User prompt
The boss's health is 10x the health of the normal enemies
User prompt
When the boss reaches the bottom of the screen, the game over appears
User prompt
When the boss appears, no others appear
User prompt
make the boss appear when the score hits 15
User prompt
make the boss appear when the score hit 20
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ // Asteroid class var Asteroid = Container.expand(function () { var self = Container.call(this); var asteroidGraphics = self.attachAsset('asteroid', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.rotationSpeed = 0.02; self.update = function () { self.y += self.speed; self.rotation += self.rotationSpeed; if (self.y > 2732) { self.destroy(); } }; }); // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5, rotation: 0.785398 // Rotate by 45 degrees to the right }); self.speed = -30; self.update = function () { self.y += self.speed; if (self.y < 0) { self.destroy(); } }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); enemyGraphics.rotation = -0.785398; // Rotate by 90 degrees to the left self.speed = 3; self.horizontalSpeed = Math.random() * 4 - 2; // Random speed between -2 and 2 self.update = function () { self.y += self.speed; self.x += self.horizontalSpeed; if (self.x < 0) { self.x = 0; self.horizontalSpeed = Math.random() * 4 - 2; // Random speed between -2 and 2 } else if (self.x > 2048) { self.x = 2048; self.horizontalSpeed = Math.random() * 4 - 2; // Random speed between -2 and 2 } if (self.y > 2732) { self.destroy(); } for (var i = 0; i < enemies.length; i++) { if (enemies[i] != self && enemies[i].intersects(self)) { self.horizontalSpeed = -self.horizontalSpeed; break; } } for (var i = 0; i < asteroids.length; i++) { if (asteroids[i].intersects(self)) { self.horizontalSpeed = -self.horizontalSpeed; break; } } }; }); // Explosion class var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5 }); // Play explosion sound when an explosion is created var explosionSound = LK.getSound('Explosion'); explosionSound.volume = 0.5; // Increase the volume explosionSound.play(); self.update = function () { self.scale.x -= 0.01; self.scale.y -= 0.01; if (self.scale.x <= 0 || self.scale.y <= 0) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.bulletLimit = 10; // Limit of bullets that can be fired before reloading self.bulletsFired = 0; // Number of bullets fired since last reload self.reloadTime = 180; // Time to reload in ticks (3 seconds) self.reloadCounter = 0; // Counter for reload time self.canShoot = true; // Whether the hero can shoot or not self.update = function () { // If the hero has fired the maximum number of bullets, start the reload counter if (self.bulletsFired >= self.bulletLimit) { self.canShoot = false; self.reloadCounter++; // If the reload time has passed, reset the counter and the number of bullets fired if (self.reloadCounter >= self.reloadTime) { self.bulletsFired = 0; self.reloadCounter = 0; self.canShoot = true; bulletCountTxt.setText('Bullets: ' + (self.bulletLimit - self.bulletsFired)); reloadTxt.visible = false; // Hide the reload sign } else if (self.reloadCounter > 0) { reloadTxt.visible = true; // Show the reload sign } } }; }); // Star class var Star = Container.expand(function () { var self = Container.call(this); var starGraphics = self.attachAsset('star', { anchorX: 0.5, anchorY: 0.5 }); // Set a random brightness for each star starGraphics.alpha = Math.random(); self.speed = 30; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize hero var hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 400; // Create a Text2 object to display the number of bullets left before reloading var bulletCountTxt = new Text2('Bullets: ' + (hero.bulletLimit - hero.bulletsFired), { size: 50, fill: "#ffffff" }); bulletCountTxt.anchor.set(1, 1); // Anchor to the bottom right corner LK.gui.bottomRight.addChild(bulletCountTxt); // Create a Text2 object to display the score at the top of the screen var scoreTxt = new Text2('Score: 0', { size: 100, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); // Anchor to the top center LK.gui.top.addChild(scoreTxt); // Create a Text2 object to display the reload sign var reloadTxt = new Text2('RELOADING...', { size: 100, fill: "#ff0000" }); reloadTxt.anchor.set(0.5, 0.5); // Anchor to the center reloadTxt.visible = false; // Initially hidden LK.gui.center.addChild(reloadTxt); // Initialize arrays for asteroids, enemies, bullets and stars var asteroids = []; var enemies = []; var bullets = []; var stars = []; // Initialize a variable to keep track of the number of enemies in the current wave var enemiesInWave = 0; // Function to spawn stars function spawnStar() { var star = new Star(); star.x = Math.random() * 2048; star.y = -50; stars.push(star); game.addChild(star); } // Function to handle hero movement function handleMove(x, y, obj) { hero.x = x; } // Function to shoot bullets function shootBullet() { var bullet = new Bullet(); bullet.x = hero.x; bullet.y = hero.y - 50; bullets.push(bullet); game.addChild(bullet); } // Function to spawn asteroids function spawnAsteroid() { var asteroid = new Asteroid(); asteroid.x = Math.random() * 2048; asteroid.y = -50; asteroids.push(asteroid); game.addChild(asteroid); } // Function to spawn enemies function spawnEnemy() { // Only spawn a new wave of enemies if all enemies from the previous wave have been destroyed if (enemiesInWave == 0) { for (var i = 0; i < 3; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = -50; enemies.push(enemy); game.addChild(enemy); } enemiesInWave = 3; } } // Handle game move event game.move = handleMove; // Handle game down event to shoot bullets game.down = function (x, y, obj) { if (hero.canShoot) { shootBullet(); hero.bulletsFired++; bulletCountTxt.setText('Bullets: ' + (hero.bulletLimit - hero.bulletsFired)); } }; // Update game logic game.update = function () { // Play the background sound and repeat it after it finishes var backgroundSound = LK.getSound('Background'); if (!backgroundSound.isPlaying) { backgroundSound.play(); } // Update asteroids for (var i = asteroids.length - 1; i >= 0; i--) { asteroids[i].update(); if (asteroids[i].intersects(hero)) { LK.effects.flashScreen(0xff0000, 1000); // Create an explosion at the point of collision var explosion = new Explosion(); explosion.x = hero.x; explosion.y = hero.y; game.addChild(explosion); // Make the hero vanish off the screen hero.x = -1000; hero.y = -1000; LK.setTimeout(function () { LK.showGameOver(); }, 3000); } } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (enemies[j].intersects(hero)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } else if (enemies[j].y >= 2732) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Update bullets for (var k = bullets.length - 1; k >= 0; k--) { bullets[k].update(); for (var l = enemies.length - 1; l >= 0; l--) { if (bullets[k].intersects(enemies[l])) { // Create a smaller explosion at the point of collision var smallExplosion = new Explosion(); smallExplosion.x = bullets[k].x; smallExplosion.y = bullets[k].y; smallExplosion.scale.x = 0.5; smallExplosion.scale.y = 0.5; game.addChild(smallExplosion); bullets[k].destroy(); enemies[l].destroy(); bullets.splice(k, 1); enemies.splice(l, 1); // Decrease the number of enemies in the current wave enemiesInWave--; // Increase the score and update the score text LK.setScore(LK.getScore() + 1); scoreTxt.setText('Score: ' + LK.getScore()); break; } } } // Update stars for (var m = stars.length - 1; m >= 0; m--) { stars[m].update(); if (stars[m].y > 2732) { stars[m].destroy(); stars.splice(m, 1); } } // Spawn asteroids, enemies and stars periodically if (LK.ticks % 30 == 0) { spawnAsteroid(); } if (LK.ticks % 120 == 0) { spawnEnemy(); } if (LK.ticks % 5 == 0) { spawnStar(); } };
===================================================================
--- original.js
+++ change.js
@@ -153,12 +153,8 @@
// Initialize hero
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 400;
-// Play the background sound
-var backgroundSound = LK.getSound('Background');
-backgroundSound.loop = true; // Loop the sound
-backgroundSound.play();
// Create a Text2 object to display the number of bullets left before reloading
var bulletCountTxt = new Text2('Bullets: ' + (hero.bulletLimit - hero.bulletsFired), {
size: 50,
fill: "#ffffff"
@@ -240,8 +236,13 @@
}
};
// Update game logic
game.update = function () {
+ // Play the background sound and repeat it after it finishes
+ var backgroundSound = LK.getSound('Background');
+ if (!backgroundSound.isPlaying) {
+ backgroundSound.play();
+ }
// Update asteroids
for (var i = asteroids.length - 1; i >= 0; i--) {
asteroids[i].update();
if (asteroids[i].intersects(hero)) {
@@ -254,12 +255,8 @@
// Make the hero vanish off the screen
hero.x = -1000;
hero.y = -1000;
LK.setTimeout(function () {
- // Play the background sound
- var backgroundSound = LK.getSound('Background');
- backgroundSound.loop = true; // Loop the sound
- backgroundSound.play();
LK.showGameOver();
}, 3000);
}
}
asteroid. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single enemy spaceship flying straight downwards viewed from above in colour. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single futuristic spaceship flying straight upwards viewed from above in colour without any background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single space torpedo flying upwards in colour. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
explosion in colour. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
large enemy space ship with massive cannons flying downwards viewed from on top in colour. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.