User prompt
Save the code please
User prompt
Make that each level gets harder and harder and make the powerups rare to drop
User prompt
Earth-monster has 20 hearts
User prompt
If you defeated the earth-monster you win
User prompt
At the end of the game that’s level 10 the earth-monster comes out it’s bullets shoots 5 times more bullets and 3 times stronger
User prompt
Bad-oil is the same as oil-food but takes 10 percent of oil away
User prompt
If you touch oil-food you gain 1 percent of oil
User prompt
If you don’t have any oil the game stops and you start with 20/40
User prompt
If you touch oil-food you get 1 percent of oil if you do not have any oil then it says enemy’s win then the game stops
User prompt
Make there be Ten Hearts and Also, if you hit a new enemy and an enemy you lose one heart, but you kill the
User prompt
Make the new-ast like the asteroid but if you touch it you lose comes at level 2
User prompt
Make it the new-enemy goes left and right only
User prompt
Now make new-enemy the same as enemy but it only a comes out at level 4
User prompt
Make a second enemy that only appears at level 10
User prompt
Please fix the bug: 'Timeout.tick error: tween.to is not a function. (In 'tween.to(instructionsTxt, { alpha: 0 }, 1000)', 'tween.to' is undefined)' in or related to this line: 'tween.to(instructionsTxt, {' Line Number: 494 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
The bullet hits the asteroid, then the bullet breaks and disappears.
User prompt
You can't Shoot and destroy the asteroid, but you can only dodge it
Code edit (1 edits merged)
Please save this source code
User prompt
Galactic Defender: Space Shooter
Initial prompt
A space shooter game
/**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/**** 
* Classes
****/ 
var Asteroid = Container.expand(function () {
	var self = Container.call(this);
	var asteroidGraphics = self.attachAsset('asteroid', {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 1.5,
		scaleY: 1.5
	});
	self.speed = 6;
	self.rotationSpeed = Math.random() * 0.05 - 0.025;
	self.scoreValue = 5;
	self.lastY = -100; // Track last position for collision detection
	self.update = function () {
		self.lastY = self.y;
		self.y += self.speed;
		self.rotation += self.rotationSpeed;
		// Add side-to-side movement to make dodging more challenging
		self.x += Math.sin(LK.ticks * 0.02) * 2;
	};
	return self;
});
var Enemy = Container.expand(function () {
	var self = Container.call(this);
	var enemyGraphics = self.attachAsset('enemy', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 3;
	self.moveDirection = 1; // 1 for right, -1 for left
	self.shootChance = 0.01; // Chance to shoot per update
	self.scoreValue = 10;
	self.update = function () {
		// Move down
		self.y += self.speed;
		// Move side to side
		self.x += self.moveDirection * 2;
		// Change direction at edges
		if (self.x < 100 || self.x > 2048 - 100) {
			self.moveDirection *= -1;
		}
	};
	return self;
});
var EnemyBullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('enemyBullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 8;
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
var PlayerBullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('playerBullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -15;
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
var PlayerShip = Container.expand(function () {
	var self = Container.call(this);
	var shipGraphics = self.attachAsset('playerShip', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.shield = self.attachAsset('shield', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0
	});
	self.hasShield = false;
	self.fireRate = 20; // Time between shots in ticks
	self.fireCooldown = 0;
	self.rapidFire = false;
	self.rapidFireTimer = 0;
	self.lives = 3;
	self.activateShield = function () {
		self.hasShield = true;
		self.shield.alpha = 0.5;
	};
	self.deactivateShield = function () {
		self.hasShield = false;
		self.shield.alpha = 0;
	};
	self.activateRapidFire = function () {
		self.rapidFire = true;
		self.rapidFireTimer = 300; // 5 seconds at 60 FPS
	};
	self.canFire = function () {
		if (self.fireCooldown <= 0) {
			self.fireCooldown = self.rapidFire ? Math.floor(self.fireRate / 2) : self.fireRate;
			return true;
		}
		return false;
	};
	self.hit = function () {
		if (self.hasShield) {
			self.deactivateShield();
			return false; // Shield absorbed the hit
		} else {
			self.lives--;
			LK.effects.flashObject(self, 0xff0000, 500);
			return true; // Ship took damage
		}
	};
	self.update = function () {
		if (self.fireCooldown > 0) {
			self.fireCooldown--;
		}
		if (self.rapidFire && self.rapidFireTimer > 0) {
			self.rapidFireTimer--;
			if (self.rapidFireTimer <= 0) {
				self.rapidFire = false;
			}
		}
	};
	return self;
});
var PowerUp = Container.expand(function () {
	var self = Container.call(this);
	var powerupGraphics = self.attachAsset('powerup', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 3;
	self.type = Math.floor(Math.random() * 2); // 0 for shield, 1 for rapid fire
	// Set color based on type
	if (self.type === 0) {
		powerupGraphics.tint = 0x3498db; // Blue for shield
	} else {
		powerupGraphics.tint = 0xf39c12; // Orange for rapid fire
	}
	self.update = function () {
		self.y += self.speed;
		// Floating animation
		self.x += Math.sin(LK.ticks * 0.05) * 1;
	};
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
// Background
game.setBackgroundColor(0x0c1445);
// Game variables
var player;
var playerBullets = [];
var enemies = [];
var enemyBullets = [];
var asteroids = [];
var powerups = [];
var gameLevel = 1;
var enemySpawnRate = 240; // Reduced enemy spawn rate to focus on dodging asteroids
var asteroidSpawnRate = 90; // Increased asteroid spawn rate to create dodging challenge
var powerupSpawnRate = 600; // Every 10 seconds
var gameState = "playing";
var scoreValue = 0;
// Setup score display
var scoreTxt = new Text2('Score: 0', {
	size: 60,
	fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
scoreTxt.x = -300; // Offset from right edge
// Lives display
var livesTxt = new Text2('Lives: 3', {
	size: 60,
	fill: 0xFFFFFF
});
livesTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(livesTxt);
livesTxt.x = -300;
livesTxt.y = 70; // Below score text
// Level display
var levelTxt = new Text2('Level: 1', {
	size: 60,
	fill: 0xFFFFFF
});
levelTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(levelTxt);
levelTxt.x = -300;
levelTxt.y = 140; // Below lives text
// Initialize player
function initializePlayer() {
	player = new PlayerShip();
	player.x = 2048 / 2;
	player.y = 2732 - 200;
	game.addChild(player);
}
// Spawn enemy
function spawnEnemy() {
	var enemy = new Enemy();
	enemy.x = Math.random() * (2048 - 200) + 100;
	enemy.y = -100;
	enemy.speed = 2 + gameLevel * 0.5; // Increase speed with level
	enemies.push(enemy);
	game.addChild(enemy);
}
// Spawn asteroid
function spawnAsteroid() {
	var asteroid = new Asteroid();
	asteroid.x = Math.random() * (2048 - 200) + 100;
	asteroid.y = -100;
	asteroid.speed = 3 + gameLevel * 0.3; // Increase speed with level
	asteroids.push(asteroid);
	game.addChild(asteroid);
}
// Spawn power-up
function spawnPowerUp() {
	var powerup = new PowerUp();
	powerup.x = Math.random() * (2048 - 200) + 100;
	powerup.y = -100;
	powerups.push(powerup);
	game.addChild(powerup);
}
// Fire player bullet
function firePlayerBullet() {
	if (player && player.canFire()) {
		var bullet = new PlayerBullet();
		bullet.x = player.x;
		bullet.y = player.y - 50;
		playerBullets.push(bullet);
		game.addChild(bullet);
		LK.getSound('laser').play();
	}
}
// Fire enemy bullet
function fireEnemyBullet(enemy) {
	var bullet = new EnemyBullet();
	bullet.x = enemy.x;
	bullet.y = enemy.y + 50;
	enemyBullets.push(bullet);
	game.addChild(bullet);
}
// Update score
function updateScore(points) {
	scoreValue += points;
	LK.setScore(scoreValue);
	scoreTxt.setText('Score: ' + scoreValue);
}
// Check level progression
function checkLevelProgress() {
	if (scoreValue >= gameLevel * 100) {
		gameLevel++;
		levelTxt.setText('Level: ' + gameLevel);
		// Make game more difficult
		enemySpawnRate = Math.max(60, enemySpawnRate - 10);
		asteroidSpawnRate = Math.max(90, asteroidSpawnRate - 15);
	}
}
// Drag handling
var isDragging = false;
function handleMove(x, y, obj) {
	if (isDragging && player) {
		// Constrain player to screen bounds
		player.x = Math.max(50, Math.min(2048 - 50, x));
		player.y = Math.max(50, Math.min(2732 - 50, y));
	}
}
game.move = handleMove;
game.down = function (x, y, obj) {
	isDragging = true;
	handleMove(x, y, obj);
	// Auto-fire when touching
	firePlayerBullet();
};
game.up = function (x, y, obj) {
	isDragging = false;
};
// Main game loop
game.update = function () {
	if (gameState !== "playing") {
		return;
	}
	// Spawn enemies
	if (LK.ticks % enemySpawnRate === 0) {
		spawnEnemy();
	}
	// Spawn asteroids
	if (LK.ticks % asteroidSpawnRate === 0) {
		spawnAsteroid();
	}
	// Spawn powerups
	if (LK.ticks % powerupSpawnRate === 0) {
		spawnPowerUp();
	}
	// Auto fire for enemies, not asteroids
	if (player && LK.ticks % 15 === 0) {
		firePlayerBullet();
	}
	// Update player bullets
	for (var i = playerBullets.length - 1; i >= 0; i--) {
		var bullet = playerBullets[i];
		// Remove bullets that go off screen
		if (bullet.y < -50) {
			bullet.destroy();
			playerBullets.splice(i, 1);
			continue;
		}
		// Check collisions with enemies
		for (var j = enemies.length - 1; j >= 0; j--) {
			var enemy = enemies[j];
			if (bullet.intersects(enemy)) {
				// Destroy enemy and bullet
				updateScore(enemy.scoreValue);
				LK.effects.flashObject(enemy, 0xff0000, 200);
				LK.getSound('explosion').play();
				enemy.destroy();
				enemies.splice(j, 1);
				bullet.destroy();
				playerBullets.splice(i, 1);
				checkLevelProgress();
				break;
			}
		}
		// Bullets can't destroy asteroids, player must dodge them
		if (playerBullets[i]) {
			// Keeping the code structure but removing the asteroid destruction logic
		}
	}
	// Update enemy bullets
	for (var i = enemyBullets.length - 1; i >= 0; i--) {
		var bullet = enemyBullets[i];
		// Remove bullets that go off screen
		if (bullet.y > 2732 + 50) {
			bullet.destroy();
			enemyBullets.splice(i, 1);
			continue;
		}
		// Check collisions with player
		if (player && bullet.intersects(player)) {
			// Player takes damage
			var hitSuccess = player.hit();
			if (hitSuccess) {
				livesTxt.setText('Lives: ' + player.lives);
				if (player.lives <= 0) {
					gameState = "over";
					LK.effects.flashScreen(0xff0000, 1000);
					LK.showGameOver();
				}
			}
			bullet.destroy();
			enemyBullets.splice(i, 1);
		}
	}
	// Update enemies
	for (var i = enemies.length - 1; i >= 0; i--) {
		var enemy = enemies[i];
		// Remove enemies that go off screen
		if (enemy.y > 2732 + 50) {
			enemy.destroy();
			enemies.splice(i, 1);
			continue;
		}
		// Enemy shooting
		if (Math.random() < enemy.shootChance) {
			fireEnemyBullet(enemy);
		}
		// Check collisions with player
		if (player && enemy.intersects(player)) {
			// Player takes damage
			var hitSuccess = player.hit();
			if (hitSuccess) {
				livesTxt.setText('Lives: ' + player.lives);
				if (player.lives <= 0) {
					gameState = "over";
					LK.effects.flashScreen(0xff0000, 1000);
					LK.showGameOver();
				}
			}
			// Destroy enemy
			enemy.destroy();
			enemies.splice(i, 1);
			LK.getSound('explosion').play();
		}
	}
	// Update asteroids
	for (var i = asteroids.length - 1; i >= 0; i--) {
		var asteroid = asteroids[i];
		// Track if asteroid just passed the player
		if (asteroid.lastY < player.y - 100 && asteroid.y >= player.y - 100) {
			// Award points for successful dodge
			updateScore(10);
			checkLevelProgress();
		}
		// Remove asteroids that go off screen
		if (asteroid.y > 2732 + 50) {
			asteroid.destroy();
			asteroids.splice(i, 1);
			continue;
		}
		// Check collisions with player
		if (player && asteroid.intersects(player)) {
			// Player takes damage
			var hitSuccess = player.hit();
			if (hitSuccess) {
				livesTxt.setText('Lives: ' + player.lives);
				if (player.lives <= 0) {
					gameState = "over";
					LK.effects.flashScreen(0xff0000, 1000);
					LK.showGameOver();
				}
			}
			// Destroy asteroid
			asteroid.destroy();
			asteroids.splice(i, 1);
			LK.getSound('explosion').play();
		}
	}
	// Update powerups
	for (var i = powerups.length - 1; i >= 0; i--) {
		var powerup = powerups[i];
		// Remove powerups that go off screen
		if (powerup.y > 2732 + 50) {
			powerup.destroy();
			powerups.splice(i, 1);
			continue;
		}
		// Check collisions with player
		if (player && powerup.intersects(player)) {
			// Apply powerup effect
			if (powerup.type === 0) {
				player.activateShield();
			} else {
				player.activateRapidFire();
			}
			// Destroy powerup
			powerup.destroy();
			powerups.splice(i, 1);
			LK.getSound('powerupCollect').play();
			updateScore(25); // Bonus points for collecting powerup
		}
	}
};
// Create instructions text
var instructionsTxt = new Text2('DODGE THE ASTEROIDS TO SURVIVE!', {
	size: 80,
	fill: 0xFFFFFF
});
instructionsTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(instructionsTxt);
instructionsTxt.y = -150;
// Hide instructions after 5 seconds
LK.setTimeout(function () {
	tween.to(instructionsTxt, {
		alpha: 0
	}, 1000);
}, 5000);
// Initialize the game
initializePlayer();
// Play background music
LK.playMusic('bgmusic'); ===================================================================
--- original.js
+++ change.js
@@ -10,16 +10,22 @@
 var Asteroid = Container.expand(function () {
 	var self = Container.call(this);
 	var asteroidGraphics = self.attachAsset('asteroid', {
 		anchorX: 0.5,
-		anchorY: 0.5
+		anchorY: 0.5,
+		scaleX: 1.5,
+		scaleY: 1.5
 	});
-	self.speed = 5;
+	self.speed = 6;
 	self.rotationSpeed = Math.random() * 0.05 - 0.025;
 	self.scoreValue = 5;
+	self.lastY = -100; // Track last position for collision detection
 	self.update = function () {
+		self.lastY = self.y;
 		self.y += self.speed;
 		self.rotation += self.rotationSpeed;
+		// Add side-to-side movement to make dodging more challenging
+		self.x += Math.sin(LK.ticks * 0.02) * 2;
 	};
 	return self;
 });
 var Enemy = Container.expand(function () {
@@ -168,10 +174,10 @@
 var enemyBullets = [];
 var asteroids = [];
 var powerups = [];
 var gameLevel = 1;
-var enemySpawnRate = 120; // Every 2 seconds at 60 FPS
-var asteroidSpawnRate = 180; // Every 3 seconds
+var enemySpawnRate = 240; // Reduced enemy spawn rate to focus on dodging asteroids
+var asteroidSpawnRate = 90; // Increased asteroid spawn rate to create dodging challenge
 var powerupSpawnRate = 600; // Every 10 seconds
 var gameState = "playing";
 var scoreValue = 0;
 // Setup score display
@@ -303,9 +309,9 @@
 	// Spawn powerups
 	if (LK.ticks % powerupSpawnRate === 0) {
 		spawnPowerUp();
 	}
-	// Auto fire
+	// Auto fire for enemies, not asteroids
 	if (player && LK.ticks % 15 === 0) {
 		firePlayerBullet();
 	}
 	// Update player bullets
@@ -332,26 +338,11 @@
 				checkLevelProgress();
 				break;
 			}
 		}
-		// Check collisions with asteroids
+		// Bullets can't destroy asteroids, player must dodge them
 		if (playerBullets[i]) {
-			// Make sure bullet still exists
-			for (var k = asteroids.length - 1; k >= 0; k--) {
-				var asteroid = asteroids[k];
-				if (bullet.intersects(asteroid)) {
-					// Destroy asteroid and bullet
-					updateScore(asteroid.scoreValue);
-					LK.effects.flashObject(asteroid, 0xff0000, 200);
-					LK.getSound('explosion').play();
-					asteroid.destroy();
-					asteroids.splice(k, 1);
-					bullet.destroy();
-					playerBullets.splice(i, 1);
-					checkLevelProgress();
-					break;
-				}
-			}
+			// Keeping the code structure but removing the asteroid destruction logic
 		}
 	}
 	// Update enemy bullets
 	for (var i = enemyBullets.length - 1; i >= 0; i--) {
@@ -411,8 +402,14 @@
 	}
 	// Update asteroids
 	for (var i = asteroids.length - 1; i >= 0; i--) {
 		var asteroid = asteroids[i];
+		// Track if asteroid just passed the player
+		if (asteroid.lastY < player.y - 100 && asteroid.y >= player.y - 100) {
+			// Award points for successful dodge
+			updateScore(10);
+			checkLevelProgress();
+		}
 		// Remove asteroids that go off screen
 		if (asteroid.y > 2732 + 50) {
 			asteroid.destroy();
 			asteroids.splice(i, 1);
@@ -460,8 +457,22 @@
 			updateScore(25); // Bonus points for collecting powerup
 		}
 	}
 };
+// Create instructions text
+var instructionsTxt = new Text2('DODGE THE ASTEROIDS TO SURVIVE!', {
+	size: 80,
+	fill: 0xFFFFFF
+});
+instructionsTxt.anchor.set(0.5, 0.5);
+LK.gui.center.addChild(instructionsTxt);
+instructionsTxt.y = -150;
+// Hide instructions after 5 seconds
+LK.setTimeout(function () {
+	tween.to(instructionsTxt, {
+		alpha: 0
+	}, 1000);
+}, 5000);
 // Initialize the game
 initializePlayer();
 // Play background music
 LK.playMusic('bgmusic');
\ No newline at end of file
:quality(85)/https://cdn.frvr.ai/680ade0499a163a8ea9c1750.png%3F3) 
 Rocky rock. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/680adfd799a163a8ea9c1760.png%3F3) 
 A space ship with guns. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/680ae14299a163a8ea9c177b.png%3F3) 
 A spaceship with weapons and four wings. Single Game Texture. In-Game asset. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/680ae53a99a163a8ea9c17bc.png%3F3) 
 A spaceship with engines at the back and lots of mini spaceships next to the big one. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/680ae7a999a163a8ea9c17c6.png%3F3) 
 Rocky green rock with green venom dripping off it. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/680aeb76b54cc7f0ed85d30f.png%3F3) 
 Black oil dripping out a container. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/680aeca3b54cc7f0ed85d31a.png%3F3) 
 Red oil floating in space with skulls flowing too. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/680aef2db54cc7f0ed85d321.png%3F3) 
 Super scary earth with sharp teeth. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/680c0047cdb2650caf349aa1.png%3F3) 
 Energy ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows