User prompt
now use a pixelated spaceship sprite for the spaceship next
User prompt
there should be no cooldown to how fast u can click
User prompt
try using a pixely asteroid sprite instead of these ellipses
User prompt
the laser instantly destroys asteroids it touches, and i changed my mind, cooldown is 10 seconds
Code edit (1 edits merged)
Please save this source code
User prompt
Asteroid Blaster
Initial prompt
there is a spaceship in the bottom of the screen that follows the cursors x position, when you tap, the spaceship shoots a bullet, asteroids are falling endlessly, when you successfully hit an asteroid, you get one score, if the asteroid is not min size, it gets 1 size smaller, you can swipe up to shoot a laser, but it has a 20 second cooldown
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Asteroid = Container.expand(function (size) {
var self = Container.call(this);
self.size = size || 'large'; // large, medium, small
// Define size properties
if (self.size === 'large') {
self.health = 3;
self.speed = 2;
self.points = 3;
self.assetId = 'largeAsteroid';
} else if (self.size === 'medium') {
self.health = 2;
self.speed = 3;
self.points = 2;
self.assetId = 'mediumAsteroid';
} else {
self.health = 1;
self.speed = 4;
self.points = 1;
self.assetId = 'smallAsteroid';
}
// Create and attach asteroid graphic
self.graphic = self.attachAsset(self.assetId, {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x999999
});
// Add pixelated appearance to the asteroid
var pixels = new Container();
var pixelSize = self.size === 'large' ? 20 : self.size === 'medium' ? 14 : 8;
var baseSize = self.graphic.width;
var pixelCount = Math.floor(baseSize / pixelSize);
var colors = [0x777777, 0x555555, 0x444444, 0x666666, 0x333333];
// Create pixelated effect with small boxes
for (var i = 0; i < pixelCount; i++) {
for (var j = 0; j < pixelCount; j++) {
if (Math.random() > 0.3) {
// Some pixels empty for irregular shape
var pixel = LK.getAsset(self.assetId, {
anchorX: 0.5,
anchorY: 0.5,
width: pixelSize,
height: pixelSize,
tint: colors[Math.floor(Math.random() * colors.length)]
});
pixel.x = (i - pixelCount / 2) * pixelSize + pixelSize / 2;
pixel.y = (j - pixelCount / 2) * pixelSize + pixelSize / 2;
pixels.addChild(pixel);
}
}
}
self.addChild(pixels);
// Hide the original graphic
self.graphic.alpha = 0;
// Add rotation property
self.rotationSpeed = (Math.random() - 0.5) * 0.05;
// Add hit method
self.hit = function () {
self.health--;
// Flash the asteroid red
LK.effects.flashObject(self, 0xff0000, 300);
// If health is depleted, destroy or split
if (self.health <= 0) {
// Add score
LK.setScore(LK.getScore() + self.points);
// Split asteroid if it's not small
if (self.size !== 'small') {
// Play asteroid break sound
LK.getSound('asteroidBreak').play();
// Create smaller asteroids
var newSize = self.size === 'large' ? 'medium' : 'small';
var count = self.size === 'large' ? 2 : 1;
for (var i = 0; i < count; i++) {
var newAsteroid = new Asteroid(newSize);
newAsteroid.x = self.x + (Math.random() * 40 - 20);
newAsteroid.y = self.y + (Math.random() * 40 - 20);
asteroids.push(newAsteroid);
game.addChild(newAsteroid);
}
} else {
// Play explosion sound
LK.getSound('explosion').play();
}
// Remove this asteroid
return true;
}
return false;
};
// Update method called on each tick
self.update = function () {
// Move asteroid down
self.y += self.speed;
// Rotate asteroid
self.rotation += self.rotationSpeed;
// If asteroid is off-screen, remove it
if (self.y > 2832) {
return true; // Return true to indicate asteroid should be removed
}
return false;
};
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
// Create and attach bullet graphic
var bulletGraphic = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
// Set bullet speed
self.speed = -15;
// Update method called on each tick
self.update = function () {
self.y += self.speed;
// If bullet is off-screen, remove it
if (self.y < -50) {
return true; // Return true to indicate bullet should be removed
}
return false;
};
return self;
});
var Ship = Container.expand(function () {
var self = Container.call(this);
// Create pixelated spaceship sprite
var shipContainer = new Container();
self.addChild(shipContainer);
// Define spaceship base color and pixel size
var baseColor = 0x1e90ff;
var pixelSize = 8;
var width = 80;
var height = 100;
var colors = [baseColor, 0x0066cc, 0x66b3ff];
// Create pixelated effect for spaceship
// Ship body
for (var i = 0; i < width / pixelSize; i++) {
for (var j = 0; j < height / pixelSize; j++) {
// Skip some pixels for shape
if ((i < 2 || i > width / pixelSize - 3) && j < height / pixelSize * 0.3) continue;
if ((i < 3 || i > width / pixelSize - 4) && j < height / pixelSize * 0.1) continue;
if ((i < 3 || i > width / pixelSize - 4) && j > height / pixelSize * 0.7) continue;
// Create pixel
var pixel = LK.getAsset('ship', {
anchorX: 0.5,
anchorY: 0.5,
width: pixelSize,
height: pixelSize,
tint: colors[Math.floor(Math.random() * colors.length)]
});
// Position pixel relative to ship center
pixel.x = (i - width / pixelSize / 2) * pixelSize + pixelSize / 2;
pixel.y = (j - height / pixelSize / 2) * pixelSize + pixelSize / 2;
// Add engine glow for bottom pixels
if (j > height / pixelSize * 0.7 && i > width / pixelSize * 0.3 && i < width / pixelSize * 0.7) {
pixel.tint = Math.random() > 0.5 ? 0xff6600 : 0xff9933; // Orange/yellow engine glow
}
// Add cockpit highlight
if (j < height / pixelSize * 0.3 && i > width / pixelSize * 0.3 && i < width / pixelSize * 0.7) {
pixel.tint = 0xb3d9ff; // Light blue cockpit
}
shipContainer.addChild(pixel);
}
}
// Hide original ship graphic, but use it for collision detection
var shipGraphic = self.attachAsset('ship', {
anchorX: 0.5,
anchorY: 0.5
});
shipGraphic.alpha = 0; // Make invisible but keep for collision
// Set ship properties
self.canShoot = true;
self.canFireLaser = true;
self.laserCooldown = 0;
// Shoot method
self.shoot = function () {
// Removed cooldown check to allow shooting as fast as player can click
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - 50;
bullets.push(bullet);
game.addChild(bullet);
// Play shoot sound
LK.getSound('shoot').play();
// Removed cooldown timer to allow unlimited shooting speed
};
// Fire laser method
self.fireLaser = function () {
if (!self.canFireLaser) return;
// Create laser beam
var laser = LK.getAsset('laser', {
anchorX: 0.5,
anchorY: 1.0
});
laser.x = self.x;
laser.y = self.y - 50;
game.addChild(laser);
// Play laser sound
LK.getSound('laserBeam').play();
// Flash the laser
tween(laser, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
laser.destroy();
}
});
// Destroy all asteroids the laser touches
for (var i = asteroids.length - 1; i >= 0; i--) {
var asteroid = asteroids[i];
// Check if asteroid is within laser beam width
if (Math.abs(asteroid.x - self.x) < laser.width / 2 + asteroid.graphic.width / 2) {
// Destroy the asteroid and get points
LK.setScore(LK.getScore() + asteroid.points);
asteroids.splice(i, 1);
asteroid.destroy();
// Play explosion sound
LK.getSound('explosion').play();
}
}
// Set cooldown for laser
self.canFireLaser = false;
self.laserCooldown = 10000; // 10 seconds
// Update cooldown bar
updateCooldownBar();
};
// Update method called on each tick
self.update = function () {
// Update laser cooldown
if (!self.canFireLaser) {
self.laserCooldown -= 16.67; // Approx time per tick at 60 FPS
if (self.laserCooldown <= 0) {
self.canFireLaser = true;
updateCooldownBar();
} else {
// Update cooldown bar periodically
if (LK.ticks % 10 === 0) {
updateCooldownBar();
}
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Create ship
var ship = new Ship();
ship.x = 2048 / 2;
ship.y = 2732 - 150;
game.addChild(ship);
// Create game containers
var bullets = [];
var asteroids = [];
var lastAsteroidSpawn = 0;
var spawnInterval = 1500; // Start with 1.5 seconds between asteroid spawns
var gameStartTime = Date.now();
var swipeStartY = null;
// Create score display
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(1.0, 0);
scoreTxt.x = -20; // Offset from right edge
scoreTxt.y = 20; // Offset from top
LK.gui.topRight.addChild(scoreTxt);
// Create cooldown bar
var cooldownBarBackground = LK.getAsset('cooldownBar', {
anchorX: 0,
anchorY: 0,
tint: 0x333333
});
cooldownBarBackground.x = 20;
cooldownBarBackground.y = 20;
LK.gui.topLeft.addChild(cooldownBarBackground);
var cooldownBarFill = LK.getAsset('cooldownBar', {
anchorX: 0,
anchorY: 0
});
cooldownBarFill.x = 20;
cooldownBarFill.y = 20;
LK.gui.topLeft.addChild(cooldownBarFill);
// Create cooldown text
var cooldownText = new Text2('LASER READY', {
size: 30,
fill: 0xFFFFFF
});
cooldownText.anchor.set(0.5, 0.5);
cooldownText.x = cooldownBarBackground.x + 150;
cooldownText.y = cooldownBarBackground.y + 15;
LK.gui.topLeft.addChild(cooldownText);
// Function to update cooldown bar
function updateCooldownBar() {
if (ship.canFireLaser) {
cooldownBarFill.width = 300;
cooldownText.setText('LASER READY');
} else {
var percentage = ship.laserCooldown / 10000;
cooldownBarFill.width = 300 * (1 - percentage);
cooldownText.setText('COOLDOWN: ' + Math.ceil(ship.laserCooldown / 1000) + 's');
}
}
// Function to spawn asteroid
function spawnAsteroid() {
var asteroid = new Asteroid();
asteroid.x = Math.random() * 2048;
asteroid.y = -100;
asteroids.push(asteroid);
game.addChild(asteroid);
lastAsteroidSpawn = LK.ticks;
}
// Mouse/touch down handler
game.down = function (x, y, obj) {
// Store swipe start position
swipeStartY = y;
// Normal click shoots
ship.shoot();
};
// Mouse/touch up handler
game.up = function (x, y, obj) {
// Check for swipe up (must be minimum 200px)
if (swipeStartY !== null && swipeStartY - y > 200) {
ship.fireLaser();
}
swipeStartY = null;
};
// Mouse/touch move handler
game.move = function (x, y, obj) {
// Move ship to follow cursor X-position
ship.x = x;
};
// Game update function (called each tick)
game.update = function () {
// Update score display
scoreTxt.setText(LK.getScore());
// Increase difficulty over time
var gameTimeSeconds = (Date.now() - gameStartTime) / 1000;
spawnInterval = Math.max(300, 1500 - gameTimeSeconds * 5); // Decrease spawn interval over time, minimum 300ms
// Spawn asteroids
if (LK.ticks - lastAsteroidSpawn > spawnInterval / 16.67) {
// Convert ms to ticks (60 FPS)
spawnAsteroid();
}
// Update ship
ship.update();
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Update bullet position and check if it should be removed
if (bullet.update()) {
bullets.splice(i, 1);
bullet.destroy();
continue;
}
// Check for collisions with asteroids
for (var j = asteroids.length - 1; j >= 0; j--) {
var asteroid = asteroids[j];
if (bullet.intersects(asteroid)) {
// Bullet hit asteroid
if (asteroid.hit()) {
asteroids.splice(j, 1);
asteroid.destroy();
}
// Remove bullet
bullets.splice(i, 1);
bullet.destroy();
break;
}
}
}
// Update asteroids
for (var k = asteroids.length - 1; k >= 0; k--) {
var asteroid = asteroids[k];
// Update asteroid position and check if it should be removed
if (asteroid.update()) {
asteroids.splice(k, 1);
asteroid.destroy();
continue;
}
// Check for collision with ship
if (ship.intersects(asteroid)) {
// Game over
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
};
// Start background music
LK.playMusic('backgroundMusic', {
fade: {
start: 0,
end: 0.3,
duration: 1000
}
}); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Asteroid = Container.expand(function (size) {
var self = Container.call(this);
self.size = size || 'large'; // large, medium, small
// Define size properties
if (self.size === 'large') {
self.health = 3;
self.speed = 2;
self.points = 3;
self.assetId = 'largeAsteroid';
} else if (self.size === 'medium') {
self.health = 2;
self.speed = 3;
self.points = 2;
self.assetId = 'mediumAsteroid';
} else {
self.health = 1;
self.speed = 4;
self.points = 1;
self.assetId = 'smallAsteroid';
}
// Create and attach asteroid graphic
self.graphic = self.attachAsset(self.assetId, {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x999999
});
// Add pixelated appearance to the asteroid
var pixels = new Container();
var pixelSize = self.size === 'large' ? 20 : self.size === 'medium' ? 14 : 8;
var baseSize = self.graphic.width;
var pixelCount = Math.floor(baseSize / pixelSize);
var colors = [0x777777, 0x555555, 0x444444, 0x666666, 0x333333];
// Create pixelated effect with small boxes
for (var i = 0; i < pixelCount; i++) {
for (var j = 0; j < pixelCount; j++) {
if (Math.random() > 0.3) {
// Some pixels empty for irregular shape
var pixel = LK.getAsset(self.assetId, {
anchorX: 0.5,
anchorY: 0.5,
width: pixelSize,
height: pixelSize,
tint: colors[Math.floor(Math.random() * colors.length)]
});
pixel.x = (i - pixelCount / 2) * pixelSize + pixelSize / 2;
pixel.y = (j - pixelCount / 2) * pixelSize + pixelSize / 2;
pixels.addChild(pixel);
}
}
}
self.addChild(pixels);
// Hide the original graphic
self.graphic.alpha = 0;
// Add rotation property
self.rotationSpeed = (Math.random() - 0.5) * 0.05;
// Add hit method
self.hit = function () {
self.health--;
// Flash the asteroid red
LK.effects.flashObject(self, 0xff0000, 300);
// If health is depleted, destroy or split
if (self.health <= 0) {
// Add score
LK.setScore(LK.getScore() + self.points);
// Split asteroid if it's not small
if (self.size !== 'small') {
// Play asteroid break sound
LK.getSound('asteroidBreak').play();
// Create smaller asteroids
var newSize = self.size === 'large' ? 'medium' : 'small';
var count = self.size === 'large' ? 2 : 1;
for (var i = 0; i < count; i++) {
var newAsteroid = new Asteroid(newSize);
newAsteroid.x = self.x + (Math.random() * 40 - 20);
newAsteroid.y = self.y + (Math.random() * 40 - 20);
asteroids.push(newAsteroid);
game.addChild(newAsteroid);
}
} else {
// Play explosion sound
LK.getSound('explosion').play();
}
// Remove this asteroid
return true;
}
return false;
};
// Update method called on each tick
self.update = function () {
// Move asteroid down
self.y += self.speed;
// Rotate asteroid
self.rotation += self.rotationSpeed;
// If asteroid is off-screen, remove it
if (self.y > 2832) {
return true; // Return true to indicate asteroid should be removed
}
return false;
};
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
// Create and attach bullet graphic
var bulletGraphic = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
// Set bullet speed
self.speed = -15;
// Update method called on each tick
self.update = function () {
self.y += self.speed;
// If bullet is off-screen, remove it
if (self.y < -50) {
return true; // Return true to indicate bullet should be removed
}
return false;
};
return self;
});
var Ship = Container.expand(function () {
var self = Container.call(this);
// Create pixelated spaceship sprite
var shipContainer = new Container();
self.addChild(shipContainer);
// Define spaceship base color and pixel size
var baseColor = 0x1e90ff;
var pixelSize = 8;
var width = 80;
var height = 100;
var colors = [baseColor, 0x0066cc, 0x66b3ff];
// Create pixelated effect for spaceship
// Ship body
for (var i = 0; i < width / pixelSize; i++) {
for (var j = 0; j < height / pixelSize; j++) {
// Skip some pixels for shape
if ((i < 2 || i > width / pixelSize - 3) && j < height / pixelSize * 0.3) continue;
if ((i < 3 || i > width / pixelSize - 4) && j < height / pixelSize * 0.1) continue;
if ((i < 3 || i > width / pixelSize - 4) && j > height / pixelSize * 0.7) continue;
// Create pixel
var pixel = LK.getAsset('ship', {
anchorX: 0.5,
anchorY: 0.5,
width: pixelSize,
height: pixelSize,
tint: colors[Math.floor(Math.random() * colors.length)]
});
// Position pixel relative to ship center
pixel.x = (i - width / pixelSize / 2) * pixelSize + pixelSize / 2;
pixel.y = (j - height / pixelSize / 2) * pixelSize + pixelSize / 2;
// Add engine glow for bottom pixels
if (j > height / pixelSize * 0.7 && i > width / pixelSize * 0.3 && i < width / pixelSize * 0.7) {
pixel.tint = Math.random() > 0.5 ? 0xff6600 : 0xff9933; // Orange/yellow engine glow
}
// Add cockpit highlight
if (j < height / pixelSize * 0.3 && i > width / pixelSize * 0.3 && i < width / pixelSize * 0.7) {
pixel.tint = 0xb3d9ff; // Light blue cockpit
}
shipContainer.addChild(pixel);
}
}
// Hide original ship graphic, but use it for collision detection
var shipGraphic = self.attachAsset('ship', {
anchorX: 0.5,
anchorY: 0.5
});
shipGraphic.alpha = 0; // Make invisible but keep for collision
// Set ship properties
self.canShoot = true;
self.canFireLaser = true;
self.laserCooldown = 0;
// Shoot method
self.shoot = function () {
// Removed cooldown check to allow shooting as fast as player can click
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - 50;
bullets.push(bullet);
game.addChild(bullet);
// Play shoot sound
LK.getSound('shoot').play();
// Removed cooldown timer to allow unlimited shooting speed
};
// Fire laser method
self.fireLaser = function () {
if (!self.canFireLaser) return;
// Create laser beam
var laser = LK.getAsset('laser', {
anchorX: 0.5,
anchorY: 1.0
});
laser.x = self.x;
laser.y = self.y - 50;
game.addChild(laser);
// Play laser sound
LK.getSound('laserBeam').play();
// Flash the laser
tween(laser, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
laser.destroy();
}
});
// Destroy all asteroids the laser touches
for (var i = asteroids.length - 1; i >= 0; i--) {
var asteroid = asteroids[i];
// Check if asteroid is within laser beam width
if (Math.abs(asteroid.x - self.x) < laser.width / 2 + asteroid.graphic.width / 2) {
// Destroy the asteroid and get points
LK.setScore(LK.getScore() + asteroid.points);
asteroids.splice(i, 1);
asteroid.destroy();
// Play explosion sound
LK.getSound('explosion').play();
}
}
// Set cooldown for laser
self.canFireLaser = false;
self.laserCooldown = 10000; // 10 seconds
// Update cooldown bar
updateCooldownBar();
};
// Update method called on each tick
self.update = function () {
// Update laser cooldown
if (!self.canFireLaser) {
self.laserCooldown -= 16.67; // Approx time per tick at 60 FPS
if (self.laserCooldown <= 0) {
self.canFireLaser = true;
updateCooldownBar();
} else {
// Update cooldown bar periodically
if (LK.ticks % 10 === 0) {
updateCooldownBar();
}
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Create ship
var ship = new Ship();
ship.x = 2048 / 2;
ship.y = 2732 - 150;
game.addChild(ship);
// Create game containers
var bullets = [];
var asteroids = [];
var lastAsteroidSpawn = 0;
var spawnInterval = 1500; // Start with 1.5 seconds between asteroid spawns
var gameStartTime = Date.now();
var swipeStartY = null;
// Create score display
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(1.0, 0);
scoreTxt.x = -20; // Offset from right edge
scoreTxt.y = 20; // Offset from top
LK.gui.topRight.addChild(scoreTxt);
// Create cooldown bar
var cooldownBarBackground = LK.getAsset('cooldownBar', {
anchorX: 0,
anchorY: 0,
tint: 0x333333
});
cooldownBarBackground.x = 20;
cooldownBarBackground.y = 20;
LK.gui.topLeft.addChild(cooldownBarBackground);
var cooldownBarFill = LK.getAsset('cooldownBar', {
anchorX: 0,
anchorY: 0
});
cooldownBarFill.x = 20;
cooldownBarFill.y = 20;
LK.gui.topLeft.addChild(cooldownBarFill);
// Create cooldown text
var cooldownText = new Text2('LASER READY', {
size: 30,
fill: 0xFFFFFF
});
cooldownText.anchor.set(0.5, 0.5);
cooldownText.x = cooldownBarBackground.x + 150;
cooldownText.y = cooldownBarBackground.y + 15;
LK.gui.topLeft.addChild(cooldownText);
// Function to update cooldown bar
function updateCooldownBar() {
if (ship.canFireLaser) {
cooldownBarFill.width = 300;
cooldownText.setText('LASER READY');
} else {
var percentage = ship.laserCooldown / 10000;
cooldownBarFill.width = 300 * (1 - percentage);
cooldownText.setText('COOLDOWN: ' + Math.ceil(ship.laserCooldown / 1000) + 's');
}
}
// Function to spawn asteroid
function spawnAsteroid() {
var asteroid = new Asteroid();
asteroid.x = Math.random() * 2048;
asteroid.y = -100;
asteroids.push(asteroid);
game.addChild(asteroid);
lastAsteroidSpawn = LK.ticks;
}
// Mouse/touch down handler
game.down = function (x, y, obj) {
// Store swipe start position
swipeStartY = y;
// Normal click shoots
ship.shoot();
};
// Mouse/touch up handler
game.up = function (x, y, obj) {
// Check for swipe up (must be minimum 200px)
if (swipeStartY !== null && swipeStartY - y > 200) {
ship.fireLaser();
}
swipeStartY = null;
};
// Mouse/touch move handler
game.move = function (x, y, obj) {
// Move ship to follow cursor X-position
ship.x = x;
};
// Game update function (called each tick)
game.update = function () {
// Update score display
scoreTxt.setText(LK.getScore());
// Increase difficulty over time
var gameTimeSeconds = (Date.now() - gameStartTime) / 1000;
spawnInterval = Math.max(300, 1500 - gameTimeSeconds * 5); // Decrease spawn interval over time, minimum 300ms
// Spawn asteroids
if (LK.ticks - lastAsteroidSpawn > spawnInterval / 16.67) {
// Convert ms to ticks (60 FPS)
spawnAsteroid();
}
// Update ship
ship.update();
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Update bullet position and check if it should be removed
if (bullet.update()) {
bullets.splice(i, 1);
bullet.destroy();
continue;
}
// Check for collisions with asteroids
for (var j = asteroids.length - 1; j >= 0; j--) {
var asteroid = asteroids[j];
if (bullet.intersects(asteroid)) {
// Bullet hit asteroid
if (asteroid.hit()) {
asteroids.splice(j, 1);
asteroid.destroy();
}
// Remove bullet
bullets.splice(i, 1);
bullet.destroy();
break;
}
}
}
// Update asteroids
for (var k = asteroids.length - 1; k >= 0; k--) {
var asteroid = asteroids[k];
// Update asteroid position and check if it should be removed
if (asteroid.update()) {
asteroids.splice(k, 1);
asteroid.destroy();
continue;
}
// Check for collision with ship
if (ship.intersects(asteroid)) {
// Game over
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
};
// Start background music
LK.playMusic('backgroundMusic', {
fade: {
start: 0,
end: 0.3,
duration: 1000
}
});