User prompt
Please fix the bug: 'Timeout.tick error: something is not defined' in or related to this line: 'something.that.does.not.exist();' Line Number: 215
Code edit (1 edits merged)
Please save this source code
User prompt
Play the enemy_laser_shot sound whenever an enemy shoots
User prompt
apply the background image to be visible at all time.
User prompt
I want the background image to replace the black background screen
User prompt
set a backgroud_image
User prompt
Make the new enemy type shoot less often
User prompt
The new enemy type should have its own bullet type that shoots down towards the player randomly.
User prompt
After scoring 10 points, a new enemy type should replace the first one. This should also have a new sprite
User prompt
use the asset space_background_music for the background music
User prompt
play space_background_music as the music for the video game
User prompt
decrease the volume of the laser shot a bit
User prompt
decrease it a bit more
User prompt
add the laser_shot sound when a shot is fired by the player
User prompt
When an enemy leaves the bottom of the screen (i.e., passes the player) the game should end as well. It should not end if an asteroid passes though.
User prompt
When the player collides with an enemy or an asteroid, the game should end.
User prompt
The player should only be able to move horizontally. He should be glued to the bottom vertically.
User prompt
I also want to increase the score by 1 when I shoot an asteroid
User prompt
When I kill an enemy, I want to get an additional point and I want the total score to be displayed at the top at all times
Initial prompt
Space Shooter Game
/****
* Classes
****/
// Alien class
var Alien = Container.expand(function () {
var self = Container.call(this);
var alienGraphics = self.attachAsset('alien', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
};
});
// 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 = 5;
self.update = function () {
self.y += self.speed;
};
});
// 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 = -15;
self.update = function () {
self.y += self.speed;
};
});
//<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 = 5;
self.update = function () {
// Spaceship update logic
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game elements
var spaceship = game.addChild(new Spaceship());
spaceship.x = 2048 / 2;
spaceship.y = 2732 - 200;
var asteroids = [];
var aliens = [];
var bullets = [];
// Game update logic
game.update = function () {
// Update spaceship
spaceship.update();
// Update asteroids
for (var i = asteroids.length - 1; i >= 0; i--) {
var asteroid = asteroids[i];
asteroid.update();
if (asteroid.y > 2732) {
asteroid.destroy();
asteroids.splice(i, 1);
}
}
// Update aliens
for (var j = aliens.length - 1; j >= 0; j--) {
var alien = aliens[j];
alien.update();
if (alien.y > 2732) {
alien.destroy();
aliens.splice(j, 1);
// End the game
LK.showGameOver();
}
}
// Update bullets
for (var k = bullets.length - 1; k >= 0; k--) {
var bullet = bullets[k];
bullet.update();
if (bullet.y < 0) {
bullet.destroy();
bullets.splice(k, 1);
}
}
// Collision detection
for (var m = bullets.length - 1; m >= 0; m--) {
var bullet = bullets[m];
for (var n = asteroids.length - 1; n >= 0; n--) {
var asteroid = asteroids[n];
if (bullet.intersects(asteroid)) {
bullet.destroy();
asteroid.destroy();
bullets.splice(m, 1);
asteroids.splice(n, 1);
// Increase the score and update the score text
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
break;
}
}
for (var p = aliens.length - 1; p >= 0; p--) {
var alien = aliens[p];
if (bullet.intersects(alien)) {
bullet.destroy();
alien.destroy();
bullets.splice(m, 1);
aliens.splice(p, 1);
// Increase the score and update the score text
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
break;
}
}
}
// Check if spaceship collides with an asteroid or an alien
for (var a = asteroids.length - 1; a >= 0; a--) {
var asteroid = asteroids[a];
if (spaceship.intersects(asteroid)) {
// End the game
LK.showGameOver();
break;
}
}
for (var b = aliens.length - 1; b >= 0; b--) {
var alien = aliens[b];
if (spaceship.intersects(alien)) {
// End the game
LK.showGameOver();
break;
}
}
};
// Spawn asteroids
function spawnAsteroid() {
var asteroid = new Asteroid();
asteroid.x = Math.random() * 2048;
asteroid.y = -50;
asteroids.push(asteroid);
game.addChild(asteroid);
}
// Spawn aliens
function spawnAlien() {
var alien = new Alien();
alien.x = Math.random() * 2048;
alien.y = -50;
aliens.push(alien);
game.addChild(alien);
}
// Fire bullet
function fireBullet() {
var bullet = new Bullet();
bullet.x = spaceship.x;
bullet.y = spaceship.y - 50;
bullets.push(bullet);
game.addChild(bullet);
// Play the laser_shot sound
LK.getSound('laser_shot').play();
}
// Create a score text
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
// Add the score text to the GUI overlay
LK.gui.top.addChild(scoreTxt);
// Set intervals for spawning asteroids and aliens
LK.setInterval(spawnAsteroid, 2000);
LK.setInterval(spawnAlien, 5000);
// Handle spaceship movement
game.move = function (x, y, obj) {
spaceship.x = x;
};
// Handle firing bullets
game.down = function (x, y, obj) {
fireBullet();
}; ===================================================================
--- original.js
+++ change.js
@@ -45,9 +45,9 @@
var spaceshipGraphics = self.attachAsset('spaceship', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 10;
+ self.speed = 5;
self.update = function () {
// Spaceship update logic
};
});
Brown rocky asteroid. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Space rocket with weapons. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
evil green alien in UFO spaceship. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
dangerous enemy spaceship with weapons. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
deep dark space with stars and very few planets. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.