Code edit (2 edits merged)
Please save this source code
User prompt
decrease spawn rate of space pirates when points reach 500
User prompt
at score 500 decrease the spawn rate of space pirates
User prompt
'spacePirateMotherShip' has health of 10
User prompt
'spacePirateMotherShip' not detecting collisions with bullets
User prompt
mothership not detecting collisions
User prompt
mothership isnt detecting collisions
User prompt
mother ship isnt the right asset
User prompt
start game with 490 points and 10 lives
User prompt
space pirate mother ship has 5 lives
User prompt
create space pirate mother ship that appears after 500 points, then stop generating dot and space pirates, space pirate mother ship drops down about 1/4 of the way down and then stops. it then only moves side to side
User prompt
after 300 points increase missile speed
User prompt
after 250 POINTS, SPAWN PIRATES More FREQUIENTLY
User prompt
make truck invincible for .5 seconds after being hit by a missile
Code edit (1 edits merged)
Please save this source code
User prompt
life banner flashes green when an extra life is added
User prompt
scorer banner flashes red anytime pionts are removed
User prompt
score banner flashes green anytime points are added
User prompt
lives banner flashes red twice when hit by a missle
User prompt
lives banner flashes red twice when a life is removed
User prompt
increase speed of missles
User prompt
immediately remove the missile that collides with the truck
User prompt
decrease truck life by 1 if hit by pirate
Code edit (1 edits merged)
Please save this source code
User prompt
trucks life is decreasing by 2 when hit by missl?
/**** 
* 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 = -5;
	self.update = function () {
		self.y += self.speed;
	};
});
// Explosion class
var Explosion = Container.expand(function () {
	var self = Container.call(this);
	var explosionGraphics = self.attachAsset('explosion', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.lifetime = 30; // Duration of the explosion effect
	self.update = function () {
		self.lifetime--;
		if (self.lifetime <= 0) {
			self.destroy();
		}
	};
});
// LifePod class
var LifePod = Container.expand(function () {
	var self = Container.call(this);
	var podGraphics = self.attachAsset('cargo', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 2; // Falling speed of the life pod
	self.update = function () {
		self.y += self.speed;
		// Check if the life pod goes off screen
		if (self.y > 2732) {
			self.destroy();
		}
	};
});
// Missile class
var Missile = Container.expand(function () {
	var self = Container.call(this);
	var missileGraphics = self.attachAsset('missile', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 8;
	self.update = function () {
		self.x += self.vx;
		self.y += self.vy;
		// Calculate the angle of movement
		var angle = Math.atan2(self.vy, self.vx);
		// Rotate the missile to point in the direction of movement
		missileGraphics.rotation = angle;
	};
});
// Red Star class
var RedStar = Container.expand(function () {
	var self = Container.call(this);
	var starGraphics = self.attachAsset('redStar', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 1; // Set a consistent falling speed for stars
	self.update = function () {
		self.y += self.speed;
		if (self.y > 2732) {
			self.y = -self.height; // Reset position to top when it goes off screen
		}
	};
});
// Space DOT class
var SpaceDOT = Container.expand(function () {
	var self = Container.call(this);
	var dotGraphics = self.attachAsset('spaceDOT', {
		anchorX: 0.0,
		anchorY: 0.5
	});
	self.speed = 5;
	self.health = 3;
	// self.healthBar.y = self.y - self.height / 2 - 10; // Update the health bar position
	self.update = function () {
		// Calculate angle towards the truck
		var angle = Math.atan2(truck.y - self.y, truck.x - self.x);
		// Rotate the SpaceDOT to point towards the truck
		dotGraphics.rotation = angle;
		// Calculate direction towards the truck
		var dx = truck.x - self.x;
		var dy = truck.y - self.y;
		var distance = Math.sqrt(dx * dx + dy * dy);
		if (distance > 0.1) {
			// Prevent division by zero
			// Calculate movement towards the truck
			self.x += dx / distance * self.speed;
			self.y += dy / distance * self.speed;
		}
		if (self.y > 2732) {
			self.y = -self.height;
		}
	};
});
// Space Pirate class
var SpacePirate = Container.expand(function () {
	var self = Container.call(this);
	var pirateGraphics = self.attachAsset('spacePirate', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 3;
	self.update = function () {
		self.y += self.speed;
		if (self.y > 2732) {
			self.y = -self.height;
		}
		// Space pirates fire missiles
		if (LK.ticks % 120 == 0) {
			var newMissile = new Missile();
			newMissile.x = self.x;
			newMissile.y = self.y;
			// Calculate direction towards the truck
			var dx = truck.x - self.x;
			var dy = truck.y - self.y;
			var distance = Math.sqrt(dx * dx + dy * dy);
			newMissile.vx = dx / distance * newMissile.speed;
			newMissile.vy = dy / distance * newMissile.speed;
			missiles.push(newMissile);
			game.addChild(newMissile);
		}
	};
});
// Space Pirate Mother Ship class
var SpacePirateMotherShip = Container.expand(function () {
	var self = Container.call(this);
	var motherShipGraphics = self.attachAsset('spacePirateMotherShip', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 3;
	self.direction = 1; // 1 for right, -1 for left
	self.health = 10; // Initialize mother ship with 10 lives
	self.update = function () {
		// Move side to side
		self.x += self.speed * self.direction;
		if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
			self.direction *= -1; // Change direction
		}
	};
});
// Star class
var Star = Container.expand(function () {
	var self = Container.call(this);
	var starGraphics = self.attachAsset('blueStar', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 1; // Set a consistent falling speed for stars
	self.update = function () {
		self.y += self.speed;
		if (self.y > 2732) {
			self.y = -self.height; // Reset position to top when it goes off screen
		}
	};
});
//<Assets used in the game will automatically appear here>
// Truck class
var Truck = Container.expand(function () {
	var self = Container.call(this);
	self.lives = 10; // Initialize truck with 10 lives
	var truckGraphics = self.attachAsset('truck', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 5;
	self.update = function () {
		// Truck movement logic
		// Touch-based controls for truck movement
		game.move = function (x, y, obj) {
			self.x = x;
			self.y = y;
		};
		if (LK.ticks % 30 == 0) {
			var newBullet = new Bullet();
			newBullet.x = self.x;
			newBullet.y = self.y;
			bullets.push(newBullet);
			game.addChild(newBullet);
		}
	};
	self.move = function (x, y, obj) {
		self.x = x;
		self.y = y;
	};
});
// Yellow Star class
var YellowStar = Container.expand(function () {
	var self = Container.call(this);
	var starGraphics = self.attachAsset('yellowStar', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 1; // Set a consistent falling speed for stars
	self.update = function () {
		self.y += self.speed;
		if (self.y > 2732) {
			self.y = -self.height; // Reset position to top when it goes off screen
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000 //Init game with black background
});
/**** 
* Game Code
****/ 
// Flag to check if the mother ship has been spawned
var motherShipSpawned = false;
// Initialize stars
var stars = [];
for (var i = 0; i < 100; i++) {
	var star;
	var randomType = Math.random();
	if (randomType < 0.33) {
		star = new Star();
	} else if (randomType < 0.66) {
		star = new RedStar();
	} else {
		star = new YellowStar();
	}
	star.x = Math.random() * 2048;
	star.y = Math.random() * 2732;
	stars.push(star);
	game.addChild(star);
}
// Update stars
for (var i = 0; i < stars.length; i++) {
	stars[i].update();
}
// Initialize score to 490 points
LK.setScore(490);
// Initialize bullets
var bullets = [];
// Initialize missiles
var missiles = [];
// Initialize truck
var truck = game.addChild(new Truck());
truck.x = 2048 / 2;
truck.y = 2732 - 200;
// Initialize space pirates
var spacePirates = [];
var pirateSpawnInterval = LK.setInterval(function () {
	var pirate = new SpacePirate();
	pirate.x = Math.random() * 2048;
	pirate.y = Math.random() * -2732; // Ensure pirates spawn off-screen initially
	spacePirates.push(pirate);
	game.addChild(pirate);
}, 5000); // Spawn a pirate every 5 seconds
// Initialize space DOTs
var spaceDOTs = [];
var dotSpawnInterval = LK.setInterval(function () {
	var dot = new SpaceDOT();
	dot.x = Math.random() * 2048;
	dot.y = Math.random() * -500;
	spaceDOTs.push(dot);
	game.addChild(dot);
}, 10000); // Spawn a DOT every 10 seconds
// Handle truck movement
game.move = function (x, y, obj) {
	truck.x = x;
	truck.y = y;
};
// Display current points at the top of the screen in white letters and numbers, in a retro font
var scoreDisplay = new Text2('Score: 0', {
	size: 100,
	// Increased size for the score banner
	fill: "#ffffff",
	font: "'Press Start 2P', cursive" // Retro font
});
scoreDisplay.anchor.set(0.5, 0); // Center the text horizontally
LK.gui.top.addChild(scoreDisplay);
// Display truck lives below the score banner
var livesDisplay = new Text2('Lives: 3', {
	size: 80,
	fill: "#ffffff",
	font: "'Press Start 2P', cursive"
});
livesDisplay.anchor.set(0.5, 0);
livesDisplay.y = scoreDisplay.height; // Position below the score banner
LK.gui.top.addChild(livesDisplay);
// Update game logic
game.update = function () {
	// Increase missile speed after reaching 300 points
	if (LK.getScore() >= 300) {
		for (var i = 0; i < missiles.length; i++) {
			missiles[i].speed = 12; // Increase speed
		}
	}
	// Spawn Space Pirate Mother Ship after reaching 500 points
	if (LK.getScore() >= 500 && !motherShipSpawned) {
		// Stop generating DOTs and space pirates
		LK.clearInterval(pirateSpawnInterval);
		LK.clearInterval(dotSpawnInterval);
		// Spawn the mother ship
		var motherShip = new SpacePirateMotherShip();
		motherShip.x = 2048 / 2;
		motherShip.y = 2732 / 4; // 1/4 down the screen
		game.addChild(motherShip);
		motherShipSpawned = true;
	} else if (LK.getScore() >= 500) {
		// Decrease the spawn rate of space pirates
		if (LK.ticks % 200 == 0) {
			// Spawn a pirate every 5 seconds
			var pirate = new SpacePirate();
			pirate.x = Math.random() * 2048;
			pirate.y = Math.random() * -2732;
			spacePirates.push(pirate);
			game.addChild(pirate);
		}
	}
	// Check if score is 100 or more to increase difficulty
	if (LK.getScore() >= 100) {
		// Increase pirate fire rate
		for (var i = 0; i < spacePirates.length; i++) {
			if (LK.ticks % 60 == 0) {
				// Fire every second instead of every two seconds
				var newMissile = new Missile();
				newMissile.x = spacePirates[i].x;
				newMissile.y = spacePirates[i].y;
				var dx = truck.x - spacePirates[i].x;
				var dy = truck.y - spacePirates[i].y;
				var distance = Math.sqrt(dx * dx + dy * dy);
				newMissile.vx = dx / distance * newMissile.speed;
				newMissile.vy = dy / distance * newMissile.speed;
				missiles.push(newMissile);
				game.addChild(newMissile);
			}
		}
		// Increase pirate spawn rate
		if (LK.getScore() >= 250) {
			if (LK.ticks % 150 == 0) {
				// Spawn a pirate every 2.5 seconds
				var pirate = new SpacePirate();
				pirate.x = Math.random() * 2048;
				pirate.y = Math.random() * -2732;
				spacePirates.push(pirate);
				game.addChild(pirate);
			}
		} else {
			if (LK.ticks % 300 == 0) {
				// Spawn a pirate every 5 seconds
				var pirate = new SpacePirate();
				pirate.x = Math.random() * 2048;
				pirate.y = Math.random() * -2732;
				spacePirates.push(pirate);
				game.addChild(pirate);
			}
		}
	}
	// Update lives display
	livesDisplay.setText('Lives: ' + truck.lives);
	// Update score display
	scoreDisplay.setText('Score: ' + LK.getScore());
	// Update game logic
	// Update bullets
	for (var i = bullets.length - 1; i >= 0; i--) {
		bullets[i].update();
		// Remove bullets that go off screen
		if (bullets[i].y < -50) {
			game.removeChild(bullets[i]);
			bullets.splice(i, 1);
			continue;
		}
		// Check collision with space pirates
		for (var j = spacePirates.length - 1; j >= 0; j--) {
			if (bullets[i].intersects(spacePirates[j])) {
				game.removeChild(bullets[i]);
				var explosion = new Explosion();
				explosion.x = spacePirates[j].x;
				explosion.y = spacePirates[j].y;
				game.addChild(explosion);
				game.removeChild(spacePirates[j]);
				// 20% chance to spawn a LifePod
				if (Math.random() < 0.2) {
					var lifePod = new LifePod();
					lifePod.x = spacePirates[j].x;
					lifePod.y = spacePirates[j].y;
					game.addChild(lifePod);
				}
				bullets.splice(i, 1);
				spacePirates.splice(j, 1);
				LK.setScore(LK.getScore() + 5); // Add 5 points for destroying a space pirate
				scoreDisplay.setStyle({
					fill: "#00ff00"
				}); // Change text color to green
				LK.setTimeout(function () {
					scoreDisplay.setStyle({
						fill: "#ffffff"
					}); // Change text color back to white
				}, 200);
				break;
			}
		}
		// Check collision with spaceDOTs
		for (var j = spaceDOTs.length - 1; j >= 0; j--) {
			if (bullets[i] && bullets[i].intersects(spaceDOTs[j])) {
				game.removeChild(bullets[i]);
				bullets.splice(i, 1);
				spaceDOTs[j].health -= 1;
				if (spaceDOTs[j].health <= 0) {
					var explosion = new Explosion();
					explosion.x = spaceDOTs[j].x;
					explosion.y = spaceDOTs[j].y;
					game.addChild(explosion);
					game.removeChild(spaceDOTs[j]);
					spaceDOTs.splice(j, 1);
					LK.setScore(LK.getScore() + 15); // Add 15 points for destroying a DOT
					scoreDisplay.setStyle({
						fill: "#00ff00"
					}); // Change text color to green
					LK.setTimeout(function () {
						scoreDisplay.setStyle({
							fill: "#ffffff"
						}); // Change text color back to white
					}, 200);
				}
				break;
			}
			// Check collision with SpacePirateMotherShip
			if (motherShipSpawned) {
				for (var i = bullets.length - 1; i >= 0; i--) {
					if (bullets[i].intersects(motherShip)) {
						game.removeChild(bullets[i]);
						bullets.splice(i, 1);
						motherShip.health -= 1;
						if (motherShip.health <= 0) {
							var explosion = new Explosion();
							explosion.x = motherShip.x;
							explosion.y = motherShip.y;
							game.addChild(explosion);
							game.removeChild(motherShip);
							LK.setScore(LK.getScore() + 50); // Add 50 points for destroying the mother ship
							motherShipSpawned = false; // Reset flag
						}
						break; // Exit loop after handling collision
					}
				}
			}
		}
	}
	for (var i = 0; i < spacePirates.length; i++) {
		spacePirates[i].update();
		// If a space pirate is destroyed, spawn a new one
		if (spacePirates.length == 0) {
			var pirate = new SpacePirate();
			pirate.x = Math.random() * 2048;
			pirate.y = Math.random() * -2732;
			spacePirates.push(pirate);
			game.addChild(pirate);
		}
		// Check collision with truck
		if (spacePirates[i].intersects(truck)) {
			game.removeChild(spacePirates[i]);
			spacePirates.splice(i, 1);
			truck.lives -= 1; // Decrease truck lives by 1
			livesDisplay.setStyle({
				fill: "#ff0000"
			}); // Change text color to red
			LK.setTimeout(function () {
				livesDisplay.setStyle({
					fill: "#ffffff"
				}); // Change text color back to white
				LK.setTimeout(function () {
					livesDisplay.setStyle({
						fill: "#ff0000"
					}); // Change text color to red again
					LK.setTimeout(function () {
						livesDisplay.setStyle({
							fill: "#ffffff"
						}); // Change text color back to white
					}, 200);
				}, 200);
			}, 200);
			if (truck.lives <= 0) {
				LK.effects.flashScreen(0xff0000, 1000);
				LK.showGameOver();
			}
		}
	}
	// Update space DOTs
	for (var i = 0; i < spaceDOTs.length; i++) {
		spaceDOTs[i].update();
		// Check collision with truck
		if (spaceDOTs[i].intersects(truck)) {
			var explosion = new Explosion();
			explosion.x = spaceDOTs[i].x;
			explosion.y = spaceDOTs[i].y;
			game.addChild(explosion);
			game.removeChild(spaceDOTs[i]);
			spaceDOTs.splice(i, 1);
			LK.setScore(LK.getScore() - 15); // Subtract 15 points for collision with the truck
			scoreDisplay.setStyle({
				fill: "#ff0000"
			}); // Change text color to red
			LK.setTimeout(function () {
				scoreDisplay.setStyle({
					fill: "#ffffff"
				}); // Change text color back to white
			}, 200);
		}
	}
	// Update life pods
	for (var i = game.children.length - 1; i >= 0; i--) {
		var child = game.children[i];
		if (child instanceof LifePod) {
			child.update();
			if (child.intersects(truck)) {
				game.removeChild(child);
				truck.lives += 1; // Increase truck lives by 1
				livesDisplay.setStyle({
					fill: "#00ff00"
				}); // Change text color to green
				LK.setTimeout(function () {
					livesDisplay.setStyle({
						fill: "#ffffff"
					}); // Change text color back to white
				}, 200);
			}
		}
	}
	for (var i = missiles.length - 1; i >= 0; i--) {
		missiles[i].update();
		// Remove missiles that go off screen
		if (missiles[i].y > 2732 || missiles[i].x < -50 || missiles[i].x > 2098) {
			game.removeChild(missiles[i]);
			missiles.splice(i, 1);
			continue;
		}
		// Check collision with truck
		if (missiles[i].intersects(truck) && !truck.invincible) {
			game.removeChild(missiles[i]);
			missiles.splice(i, 1);
			truck.lives -= 1;
			truck.invincible = true; // Make truck invincible
			LK.setTimeout(function () {
				truck.invincible = false; // Remove invincibility after 0.5 seconds
			}, 500);
			livesDisplay.setStyle({
				fill: "#ff0000"
			}); // Change text color to red
			LK.setTimeout(function () {
				livesDisplay.setStyle({
					fill: "#ffffff"
				}); // Change text color back to white
				LK.setTimeout(function () {
					livesDisplay.setStyle({
						fill: "#ff0000"
					}); // Change text color to red again
					LK.setTimeout(function () {
						livesDisplay.setStyle({
							fill: "#ffffff"
						}); // Change text color back to white
					}, 200);
				}, 200);
			}, 200);
			if (truck.lives <= 0) {
				LK.effects.flashScreen(0xff0000, 1000);
				LK.showGameOver();
			}
			continue; // Ensure the missile is immediately removed
		}
	}
}; ===================================================================
--- original.js
+++ change.js
@@ -318,9 +318,9 @@
 		game.addChild(motherShip);
 		motherShipSpawned = true;
 	} else if (LK.getScore() >= 500) {
 		// Decrease the spawn rate of space pirates
-		if (LK.ticks % 300 == 0) {
+		if (LK.ticks % 200 == 0) {
 			// Spawn a pirate every 5 seconds
 			var pirate = new SpacePirate();
 			pirate.x = Math.random() * 2048;
 			pirate.y = Math.random() * -2732;