Code edit (1 edits merged)
Please save this source code
User prompt
trucks life is decreasing by 2 when hit by missl?
User prompt
at 100 points increase rate of fire from pirates, and increase spawn rate of pirates
User prompt
decrease the rate of extra life drops
User prompt
create +1 life pod the randomly drops and falls when a pirate explodes.
User prompt
have missles point in the direction that they're going
User prompt
decrease rate of firing missiles from pirates
User prompt
rotate dot to point directly at the truck
User prompt
give truck 3 lives, display number of lives the truck has below the score banner
User prompt
set dot health to 3, do not display a health bar
User prompt
remove dot health bar and set health to 1
User prompt
increase the size of the score banner
User prompt
have dot move towards truck as it falls
User prompt
yellow and red stars dissappeared
User prompt
stars should fall
User prompt
dot falls at consistand speed
User prompt
have dot fall toward the truck, but never sideways or upwards, just falling toward
User prompt
dot, Make sure that when health = 3, scaleX is set to 1 (full width). If scaleX should represent the proportion of health, adjust accordingly.
User prompt
health bar, To make scaling intuitive (i.e., scaling from the left side), set the anchor point's x to 0. This way, scaling will only affect the right side, keeping the left side anchored.
User prompt
dot, To prevent division by zero, add a condition to check if the distance is greater than a small threshold before updating the position.
User prompt
set the health bar of the dot to stay directly above dot
User prompt
increase speed of dot to 5
User prompt
have dot fly toward truck, if collides, sudtract 15 points
User prompt
display current points at the top of the screen in white letters and numbers, in a retro fount
User prompt
Remove the redundant self.healthBar.y assignment in the initialization or ensure it's correctly updated relative to the DOT's position.
/**** 
* 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 = 5;
	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);
		}
	};
});
// 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 = 3; // Initialize truck with 3 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
****/ 
// 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 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 () {
	// 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.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
				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
				}
				break;
			}
		}
	}
	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);
		}
	}
	// 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
		}
	}
	// 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
			}
		}
	}
	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)) {
			game.removeChild(missiles[i]);
			missiles.splice(i, 1);
			truck.lives -= 0; // Decrease truck lives by 2
			if (truck.lives <= 0) {
				LK.effects.flashScreen(0xff0000, 1000);
				LK.showGameOver();
			}
		}
	}
}; ===================================================================
--- original.js
+++ change.js
@@ -408,9 +408,9 @@
 		// Check collision with truck
 		if (missiles[i].intersects(truck)) {
 			game.removeChild(missiles[i]);
 			missiles.splice(i, 1);
-			truck.lives -= 2; // Decrease truck lives by 2
+			truck.lives -= 0; // Decrease truck lives by 2
 			if (truck.lives <= 0) {
 				LK.effects.flashScreen(0xff0000, 1000);
 				LK.showGameOver();
 			}