/**** 
* Classes
****/ 
// EnemyBullet class
var EnemyBullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('enemyBullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 3;
	self.update = function () {
		self.y += self.speed;
		if (self.y > 2732 + bulletGraphics.height) {
			self.destroy();
			enemyBullets.splice(enemyBullets.indexOf(self), 1);
		}
	};
});
// HealthItem class
var HealthItem = Container.expand(function () {
	var self = Container.call(this);
	var healthItemGraphics = self.attachAsset('healthItem', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 2;
	self.update = function () {
		self.y += self.speed;
		if (self.y > 2732 + healthItemGraphics.height) {
			self.destroy();
			healthItems.splice(healthItems.indexOf(self), 1);
		}
	};
});
// HeroBullet class
var HeroBullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('heroBullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -15;
	self.update = function () {
		self.y += self.speed;
		if (self.y < -bulletGraphics.height) {
			self.destroy();
			heroBullets.splice(heroBullets.indexOf(self), 1);
		}
	};
});
//<Assets used in the game will automatically appear here>
// Jet class
var Jet = Container.expand(function () {
	var self = Container.call(this);
	var jetGraphics = self.attachAsset('jet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 10;
	self.health = 3;
	self.update = function () {
		// Jet update logic
		if (LK.ticks % 30 == 0) {
			self.shoot();
		}
	};
	self.shoot = function () {
		var bullet = new HeroBullet();
		bullet.x = self.x;
		bullet.y = self.y - jetGraphics.height / 2;
		game.addChild(bullet);
		heroBullets.push(bullet);
	};
});
// UFO class
var UFO = Container.expand(function () {
	var self = Container.call(this);
	var ufoGraphics = self.attachAsset('ufo', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 2;
	self.shoot = function () {
		var bullet = new EnemyBullet();
		bullet.x = self.x;
		bullet.y = self.y + ufoGraphics.height / 2;
		game.addChild(bullet);
		enemyBullets.push(bullet);
		LK.getSound('UFO').play();
	};
	self.update = function () {
		self.y += self.speed;
		if (self.y > 2732 + ufoGraphics.height) {
			self.destroy();
			ufos.splice(ufos.indexOf(self), 1);
			enemiesCrossed++;
		}
		// UFO shoots every 120 ticks
		if (LK.ticks % 120 == 0) {
			self.shoot();
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000 //Init game with black background
});
/**** 
* Game Code
****/ 
var background = game.attachAsset('background', {
	anchorX: 0.0,
	anchorY: 0.0,
	x: 0,
	y: 0
});
var jet;
var heroBullets = [];
var ufos = [];
var enemyBullets = [];
var healthItems = [];
var score = 0;
var enemiesCrossed = 0;
var scoreTxt = new Text2('0', {
	size: 150,
	fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function spawnUFO() {
	var ufo = new UFO();
	ufo.x = Math.random() * 2048;
	ufo.y = -ufo.height;
	game.addChild(ufo);
	ufos.push(ufo);
}
game.update = function () {
	jet.update();
	heroBullets.forEach(function (bullet) {
		bullet.update();
	});
	ufos.forEach(function (ufo) {
		ufo.update();
	});
	enemyBullets.forEach(function (bullet) {
		bullet.update();
	});
	enemyBullets.forEach(function (bullet) {
		bullet.update();
	});
	game.move = function (x, y, obj) {
		jet.x = x;
	};
	for (var i = heroBullets.length - 1; i >= 0; i--) {
		for (var j = ufos.length - 1; j >= 0; j--) {
			if (heroBullets[i].intersects(ufos[j])) {
				heroBullets[i].destroy();
				heroBullets.splice(i, 1);
				var ufoDestroyVFX = LK.getAsset('ufoDestroyVFX', {
					anchorX: 0.5,
					anchorY: 0.5,
					x: ufos[j].x,
					y: ufos[j].y
				});
				game.addChild(ufoDestroyVFX);
				LK.setTimeout(function () {
					ufoDestroyVFX.destroy();
				}, 100);
				ufos[j].destroy();
				ufos.splice(j, 1);
				score += 10;
				scoreTxt.setText(score);
				break;
			}
		}
	}
	for (var i = enemyBullets.length - 1; i >= 0; i--) {
		if (enemyBullets[i].intersects(jet)) {
			enemyBullets[i].destroy();
			enemyBullets.splice(i, 1);
			jet.destroy();
			LK.showGameOver();
			break;
		}
		// Check if enemy bullet intersects with hero bullet
		for (var j = heroBullets.length - 1; j >= 0; j--) {
			if (enemyBullets[i] && enemyBullets[i].intersects(heroBullets[j])) {
				// Destroy both bullets
				enemyBullets[i].destroy();
				enemyBullets.splice(i, 1);
				heroBullets[j].destroy();
				heroBullets.splice(j, 1);
				// Play bullet collision sound
				LK.getSound('BulletCollision').play();
				break;
			}
		}
		// Check if jet intersects with a health item
		for (var i = healthItems.length - 1; i >= 0; i--) {
			if (healthItems[i].intersects(jet)) {
				healthItems[i].destroy();
				healthItems.splice(i, 1);
				jet.health += 1;
				break;
			}
		}
	}
	// Spawn UFOs and health items periodically
	if (LK.ticks % 240 == 0) {
		spawnUFO();
		if (Math.random() < 0.1) {
			// 10% chance to spawn a health item
			var healthItem = new HealthItem();
			healthItem.x = Math.random() * 2048;
			healthItem.y = -healthItem.height;
			game.addChild(healthItem);
			healthItems.push(healthItem);
		}
	}
};
// Removed the code that makes the player shoot automatically
jet = game.addChild(new Jet());
jet.x = 2048 / 2;
jet.y = 2732 - 200;
jet.health = 3; /**** 
* Classes
****/ 
// EnemyBullet class
var EnemyBullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('enemyBullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 3;
	self.update = function () {
		self.y += self.speed;
		if (self.y > 2732 + bulletGraphics.height) {
			self.destroy();
			enemyBullets.splice(enemyBullets.indexOf(self), 1);
		}
	};
});
// HealthItem class
var HealthItem = Container.expand(function () {
	var self = Container.call(this);
	var healthItemGraphics = self.attachAsset('healthItem', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 2;
	self.update = function () {
		self.y += self.speed;
		if (self.y > 2732 + healthItemGraphics.height) {
			self.destroy();
			healthItems.splice(healthItems.indexOf(self), 1);
		}
	};
});
// HeroBullet class
var HeroBullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('heroBullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -15;
	self.update = function () {
		self.y += self.speed;
		if (self.y < -bulletGraphics.height) {
			self.destroy();
			heroBullets.splice(heroBullets.indexOf(self), 1);
		}
	};
});
//<Assets used in the game will automatically appear here>
// Jet class
var Jet = Container.expand(function () {
	var self = Container.call(this);
	var jetGraphics = self.attachAsset('jet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 10;
	self.health = 3;
	self.update = function () {
		// Jet update logic
		if (LK.ticks % 30 == 0) {
			self.shoot();
		}
	};
	self.shoot = function () {
		var bullet = new HeroBullet();
		bullet.x = self.x;
		bullet.y = self.y - jetGraphics.height / 2;
		game.addChild(bullet);
		heroBullets.push(bullet);
	};
});
// UFO class
var UFO = Container.expand(function () {
	var self = Container.call(this);
	var ufoGraphics = self.attachAsset('ufo', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 2;
	self.shoot = function () {
		var bullet = new EnemyBullet();
		bullet.x = self.x;
		bullet.y = self.y + ufoGraphics.height / 2;
		game.addChild(bullet);
		enemyBullets.push(bullet);
		LK.getSound('UFO').play();
	};
	self.update = function () {
		self.y += self.speed;
		if (self.y > 2732 + ufoGraphics.height) {
			self.destroy();
			ufos.splice(ufos.indexOf(self), 1);
			enemiesCrossed++;
		}
		// UFO shoots every 120 ticks
		if (LK.ticks % 120 == 0) {
			self.shoot();
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000 //Init game with black background
});
/**** 
* Game Code
****/ 
var background = game.attachAsset('background', {
	anchorX: 0.0,
	anchorY: 0.0,
	x: 0,
	y: 0
});
var jet;
var heroBullets = [];
var ufos = [];
var enemyBullets = [];
var healthItems = [];
var score = 0;
var enemiesCrossed = 0;
var scoreTxt = new Text2('0', {
	size: 150,
	fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function spawnUFO() {
	var ufo = new UFO();
	ufo.x = Math.random() * 2048;
	ufo.y = -ufo.height;
	game.addChild(ufo);
	ufos.push(ufo);
}
game.update = function () {
	jet.update();
	heroBullets.forEach(function (bullet) {
		bullet.update();
	});
	ufos.forEach(function (ufo) {
		ufo.update();
	});
	enemyBullets.forEach(function (bullet) {
		bullet.update();
	});
	enemyBullets.forEach(function (bullet) {
		bullet.update();
	});
	game.move = function (x, y, obj) {
		jet.x = x;
	};
	for (var i = heroBullets.length - 1; i >= 0; i--) {
		for (var j = ufos.length - 1; j >= 0; j--) {
			if (heroBullets[i].intersects(ufos[j])) {
				heroBullets[i].destroy();
				heroBullets.splice(i, 1);
				var ufoDestroyVFX = LK.getAsset('ufoDestroyVFX', {
					anchorX: 0.5,
					anchorY: 0.5,
					x: ufos[j].x,
					y: ufos[j].y
				});
				game.addChild(ufoDestroyVFX);
				LK.setTimeout(function () {
					ufoDestroyVFX.destroy();
				}, 100);
				ufos[j].destroy();
				ufos.splice(j, 1);
				score += 10;
				scoreTxt.setText(score);
				break;
			}
		}
	}
	for (var i = enemyBullets.length - 1; i >= 0; i--) {
		if (enemyBullets[i].intersects(jet)) {
			enemyBullets[i].destroy();
			enemyBullets.splice(i, 1);
			jet.destroy();
			LK.showGameOver();
			break;
		}
		// Check if enemy bullet intersects with hero bullet
		for (var j = heroBullets.length - 1; j >= 0; j--) {
			if (enemyBullets[i] && enemyBullets[i].intersects(heroBullets[j])) {
				// Destroy both bullets
				enemyBullets[i].destroy();
				enemyBullets.splice(i, 1);
				heroBullets[j].destroy();
				heroBullets.splice(j, 1);
				// Play bullet collision sound
				LK.getSound('BulletCollision').play();
				break;
			}
		}
		// Check if jet intersects with a health item
		for (var i = healthItems.length - 1; i >= 0; i--) {
			if (healthItems[i].intersects(jet)) {
				healthItems[i].destroy();
				healthItems.splice(i, 1);
				jet.health += 1;
				break;
			}
		}
	}
	// Spawn UFOs and health items periodically
	if (LK.ticks % 240 == 0) {
		spawnUFO();
		if (Math.random() < 0.1) {
			// 10% chance to spawn a health item
			var healthItem = new HealthItem();
			healthItem.x = Math.random() * 2048;
			healthItem.y = -healthItem.height;
			game.addChild(healthItem);
			healthItems.push(healthItem);
		}
	}
};
// Removed the code that makes the player shoot automatically
jet = game.addChild(new Jet());
jet.x = 2048 / 2;
jet.y = 2732 - 200;
jet.health = 3;
:quality(85)/https://cdn.frvr.ai/66863bd3def1c8edfaaea3e2.png%3F3) 
 Fighter jet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/66863cffdef1c8edfaaea3f8.png%3F3) 
 Ufo with green alien driving it. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/66863f2edef1c8edfaaea437.png%3F3) 
 Space with stars with earth background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/66864037def1c8edfaaea444.png%3F3) 
 Red round ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/6686407ddef1c8edfaaea44e.png%3F3) 
 Green round ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/668644b6def1c8edfaaea47b.png%3F3) 
 Pixel smoke. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/6686480adef1c8edfaaea4a1.png%3F3) 
 Red Heart with plus symbol at centre. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.