/**** 
* Classes
****/
var BossBullet = Container.expand(function (vx, vy) {
	var self = Container.call(this);
	var bulletGraphics = LK.getAsset('bossBullet', {});
	bulletGraphics.anchor.set(0.5, 0.5);
	self.addChild(bulletGraphics);
	self.vx = vx;
	self.vy = vy;
	self.move = function () {
		self.x += self.vx;
		self.y += self.vy;
	};
});
var Bullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = LK.getAsset('bullet', {});
	bulletGraphics.anchor.set(0.5, 0.5);
	self.addChild(bulletGraphics);
});
var Enemy = Container.expand(function (isBoss, enemyType) {
	var self = Container.call(this);
	isBoss = isBoss || false;
	enemyType = enemyType || 'enemy1';
	var enemyGraphics;
	if (isBoss) {
		enemyGraphics = LK.getAsset('boss', {});
	} else {
		switch (enemyType) {
			case 'enemy1':
				enemyGraphics = LK.getAsset('enemy1', {});
				break;
			case 'enemy2':
				enemyGraphics = LK.getAsset('enemy2', {});
				break;
			case 'enemy3':
				enemyGraphics = LK.getAsset('enemy3', {});
				break;
			case 'enemy4':
				enemyGraphics = LK.getAsset('enemy4', {});
				break;
			case 'enemy5':
				enemyGraphics = LK.getAsset('enemy5', {});
				break;
			default:
				enemyGraphics = LK.getAsset('enemy1', {});
		}
	}
	enemyGraphics.anchor.set(0.5, 0.5);
	self.healthBar = new HealthBar(isBoss ? 500 : 50);
	self.healthBar.y = -enemyGraphics.height / 2 - self.healthBar.height - 5;
	self.healthBar.x = -self.healthBar.width / 2;
	self.addChild(self.healthBar);
	self.addChild(enemyGraphics);
	self.state = "flyingIntoScreen";
	self.flyInY = isBoss ? 2732 / 4 : Math.random() * (2732 / 2 - 100) + 50;
	self.angle = 0;
	self.shootCounter = Math.random() * 100;
	self.shoot = function (heroX, heroY, container) {
		var dx = heroX - self.x;
		var dy = heroY - self.y;
		var distance = Math.sqrt(dx * dx + dy * dy);
		var speedMultiplier = 1 + container.score * 0.001;
		var vx = 7 * speedMultiplier * dx / distance;
		var vy = 7 * speedMultiplier * dy / distance;
		var enemyBullet = isBoss ? new BossBullet(vx, vy) : new EnemyBullet(vx, vy);
		enemyBullet.x = self.x;
		enemyBullet.y = self.y + enemyGraphics.height / 2;
		return enemyBullet;
	};
	self.move = function (speed) {
		if (self.state === "flyingIntoScreen") {
			self.y += speed;
			if (self.y >= self.flyInY) {
				self.state = "circularPattern";
			}
		} else if (self.state === "circularPattern") {
			self.angle += 0.025;
			self.x += Math.cos(self.angle) * speed;
			self.y += Math.sin(2 * self.angle) * speed * 0.5;
		}
	};
});
var EnemyBullet = Container.expand(function (vx, vy) {
	var self = Container.call(this);
	var bulletGraphics = LK.getAsset('enemyBullet', {});
	bulletGraphics.anchor.set(0.5, 0.5);
	self.addChild(bulletGraphics);
	self.vx = vx;
	self.vy = vy;
	self.move = function () {
		self.x += self.vx;
		self.y += self.vy;
	};
});
var HealthBar = Container.expand(function (maxHealth) {
	var self = Container.call(this);
	self.maxHealth = maxHealth;
	self.currentHealth = maxHealth;
	self.isDead = function () {
		return self.currentHealth <= 0;
	};
	self.bar = LK.getAsset('healthBar', {});
	self.bar.width = maxHealth === 500 ? 400 : 100;
	self.bar.height = maxHealth === 500 ? 20 : 10;
	self.addChild(self.bar);
	self.updateHealth = function (health) {
		self.currentHealth = health;
		self.bar.scale.x = self.currentHealth / self.maxHealth;
	};
});
var Hero = Container.expand(function () {
	var self = Container.call(this);
	self.doubleCannon = false;
	self.doubleCannonPowerUpCount = 0;
	var heroGraphics = LK.getAsset('hero', {});
	heroGraphics.anchor.set(0.5, 0.5);
	self.healthBar = new HealthBar(100);
	self.healthBar.y = -heroGraphics.height / 2 - self.healthBar.height - 5;
	self.healthBar.x = -self.healthBar.width / 2;
	self.addChild(self.healthBar);
	self.addChild(heroGraphics);
	self.moveTowards = function (target, speed) {
		var dx = target.x - self.x;
		var dy = target.y - self.y;
		var distance = Math.sqrt(dx * dx + dy * dy);
		if (distance > speed) {
			self.x += dx * speed / distance;
			self.y += dy * speed / distance;
		} else {
			self.x = target.x;
			self.y = target.y;
		}
	};
	self.fireBullet = function () {
		var bullets = [];
		for (var i = 0; i < 5; i++) {
			var bullet = new Bullet();
			bullet.x = self.x + i * 20 - 40;
			bullet.y = self.y - heroGraphics.height / 2;
			bullets.push(bullet);
		}
		return bullets;
	};
});
var PowerUp = Container.expand(function (type) {
	var self = Container.call(this);
	self.type = type;
	var powerUpGraphics = self.type === 'doubleCannon' ? LK.getAsset('doubleCannonPowerUp', {}) : LK.getAsset('powerUp', {});
	powerUpGraphics.anchor.set(0.5, 0.5);
	self.addChild(powerUpGraphics);
	self.speed = 3;
	self.move = function () {
		self.y += self.speed;
	};
});
var StarField = Container.expand(function () {
	var self = Container.call(this);
	self.stars = [];
	var numberOfStars = 300;
	for (var i = 0; i < numberOfStars; i++) {
		var star = LK.getAsset('star', {});
		star.anchor.set(0.5, 0.5);
		star.x = Math.random() * 2048;
		star.y = Math.random() * 2732;
		star.speed = Math.random() * 2 + 0.5;
		star.alpha = Math.random() * 0.5 + 0.5;
		self.addChild(star);
		self.stars.push(star);
	}
	self.update = function () {
		for (var i = 0; i < self.stars.length; i++) {
			var star = self.stars[i];
			star.y += star.speed;
			if (star.y > 2732) {
				star.y -= 2732;
			}
		}
	};
});
/**** 
* Initialize Game
****/
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/
var scoreText = new Text2('0', {
	size: 150,
	font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
	fill: "#ffffff"
});
scoreText.anchor.set(.5, 0);
LK.gui.top.addChild(scoreText);
game.powerUpIcons = new Container();
game.powerUpIcons.x = 2048 - 100;
game.powerUpIcons.y = 2732 - 100;
game.addChild(game.powerUpIcons);
var starField = game.addChild(new StarField());
game.score = 0;
var hero = game.addChild(new Hero());
hero.x = 1024;
hero.y = 2420;
var enemies = [];
var bullets = [];
var enemyBullets = [];
var spawnEnemy = function spawnEnemy(x, y, isBoss, enemyType) {
	var enemy = new Enemy(isBoss, enemyType);
	enemy.x = x;
	enemy.y = y;
	game.addChild(enemy);
	enemies.push(enemy);
};
var fireBullet = function fireBullet() {
	var bullet = hero.fireBullet();
	game.addChild(bullet);
	bullets.push(bullet);
};
var currentWave = 1;
var spawnWave = function spawnWave() {
	var enemyType = 'enemy' + ((currentWave - 1) % 5 + 1);
	for (var i = 0; i < 5 + Math.floor(currentWave / 2); i++) {
		var x = Math.random() * (2048 - 100) + 50;
		spawnEnemy(x, -100, false, enemyType);
	}
};
var spawnPowerUp = function spawnPowerUp() {
	var x = Math.random() * (2048 - 100) + 50;
	var powerUp = new PowerUp(Math.random() < 0.5 ? 'doubleCannon' : 'default');
	powerUp.x = x;
	powerUp.y = -100;
	game.addChild(powerUp);
	powerUps.push(powerUp);
};
var powerUps = [];
var checkPowerUpCollision = function checkPowerUpCollision() {
	for (var i = 0; i < powerUps.length; i++) {
		var powerUp = powerUps[i];
		if (hero.intersects(powerUp)) {
			game.removeChild(powerUp);
			powerUps.splice(i, 1);
			if (powerUp.type === 'doubleCannon') {
				hero.doubleCannon = true;
				hero.doubleCannonPowerUpCount++;
				var powerUpIcon = LK.getAsset('doubleCannonPowerUp', {});
				powerUpIcon.anchor.set(0.5, 0.5);
				powerUpIcon.x = -85 * game.powerUpIcons.children.length;
				game.powerUpIcons.addChild(powerUpIcon);
				LK.setTimeout(function () {
					hero.doubleCannonPowerUpCount--;
					if (hero.doubleCannonPowerUpCount === 0) {
						hero.doubleCannon = false;
					}
					game.powerUpIcons.removeChild(powerUpIcon);
					game.powerUpIcons.children.forEach(function (icon, index) {
						icon.x = -50 * index;
					});
				}, 15000);
			} else {
				heroSpeed *= 2;
				var powerUpIcon = LK.getAsset('powerUp', {});
				powerUpIcon.anchor.set(0.5, 0.5);
				powerUpIcon.x = -50 * game.powerUpIcons.children.length;
				game.powerUpIcons.addChild(powerUpIcon);
				LK.setTimeout(function () {
					heroSpeed /= 2;
					game.powerUpIcons.removeChild(powerUpIcon);
					game.powerUpIcons.children.forEach(function (icon, index) {
						icon.x = -50 * index;
					});
				}, 15000);
			}
		}
	}
};
spawnWave();
currentWave++;
var spawnBoss = function spawnBoss() {
	var x = 1024;
	var y = -100;
	spawnEnemy(x, y, true, 'boss');
};
var autoFire = LK.setInterval(function () {
	var bulletsFired = hero.fireBullet();
	bulletsFired.forEach(function (bullet) {
		game.addChild(bullet);
		bullets.push(bullet);
	});
}, 600);
var targetPosition = {
	x: hero.x,
	y: hero.y
};
game.on('move', function (obj) {
	var event = obj.event;
	var pos = event.getLocalPosition(game);
	targetPosition.x = pos.x;
	targetPosition.y = pos.y;
});
var heroSpeed = 15;
function resetGame() {
	bullets.forEach(function (bullet) {
		game.removeChild(bullet);
	});
	enemyBullets.forEach(function (bullet) {
		game.removeChild(bullet);
	});
	enemies.forEach(function (enemy) {
		game.removeChild(enemy);
	});
	bullets = [];
	enemyBullets = [];
	enemies = [];
	hero.x = 1024;
	hero.y = 2420;
	hero.healthBar.updateHealth(hero.healthBar.maxHealth);
	game.score = 0;
	currentWave = 1;
	spawnWave();
}
LK.on('tick', function () {
	hero.moveTowards(targetPosition, heroSpeed);
	hero.x = Math.min(Math.max(hero.x, 0), 2048);
	hero.y = Math.min(Math.max(hero.y, 0), 2732);
});
LK.on('tick', function () {
	starField.update();
	for (var i = 0; i < powerUps.length; i++) {
		powerUps[i].move();
		if (powerUps[i].y > 2732 || powerUps[i].x < 0 || powerUps[i].x > 2048) {
			game.removeChild(powerUps[i]);
			powerUps.splice(i, 1);
			i--;
		}
	}
	checkPowerUpCollision();
	if (Math.random() < 0.001) {
		spawnPowerUp();
	}
	for (var i = 0; i < enemies.length; i++) {
		enemies[i].move(5 + game.score * 0.001);
	}
	for (var i = 0; i < enemies.length; i++) {
		enemies[i].move(5);
		enemies[i].shootCounter--;
		if (enemies[i].shootCounter <= 0) {
			var enemyBullet = enemies[i].shoot(hero.x, hero.y, game);
			game.addChild(enemyBullet);
			enemyBullets.push(enemyBullet);
			enemies[i].shootCounter = (enemies[i].isBoss ? 50 : 100) + Math.random() * 100;
		}
	}
	for (var j = 0; j < enemyBullets.length; j++) {
		enemyBullets[j].move();
		if (enemyBullets[j].x >= hero.x - hero.width / 2 && enemyBullets[j].x <= hero.x + hero.width / 2 && enemyBullets[j].y >= hero.y - hero.height / 2 && enemyBullets[j].y <= hero.y + hero.height / 2) {
			hero.healthBar.updateHealth(hero.healthBar.currentHealth - 10);
			game.removeChild(enemyBullets[j]);
			enemyBullets.splice(j, 1);
			if (hero.healthBar.isDead()) {
				resetGame();
				return;
			}
		}
		if (enemyBullets[j] && enemyBullets[j].y > 2732 + 30) {
			game.removeChild(enemyBullets[j]);
			enemyBullets.splice(j, 1);
			j--;
		}
	}
	function checkBulletCollision(bulletsArray, targetArray, onHitCallback) {
		for (var j = 0; j < bulletsArray.length; j++) {
			bulletsArray[j].y -= 10;
			if (bulletsArray[j].y < -30 || bulletsArray[j].y > 2732 || bulletsArray[j].x < 0 || bulletsArray[j].x > 2048) {
				game.removeChild(bulletsArray[j]);
				bulletsArray.splice(j, 1);
				j--;
			} else {
				for (var k = targetArray.length - 1; k >= 0; k--) {
					var target = targetArray[k];
					if (target.intersects(bulletsArray[j])) {
						game.removeChild(bulletsArray[j]);
						bulletsArray.splice(j, 1);
						j--;
						onHitCallback(target, k);
						break;
					}
				}
			}
		}
	}
	checkBulletCollision(bullets, enemies, function (enemy, index) {
		enemy.healthBar.updateHealth(enemy.healthBar.currentHealth - 10);
		if (enemy.healthBar.isDead()) {
			game.removeChild(enemy);
			enemies.splice(index, 1);
			game.score += 10 * currentWave;
			if (enemies.length === 0) {
				if (currentWave % 5 === 0) {
					spawnBoss();
				} else {
					spawnWave();
				}
				currentWave++;
			}
			scoreText.setText(game.score);
		}
	});
}); /**** 
* Classes
****/
var BossBullet = Container.expand(function (vx, vy) {
	var self = Container.call(this);
	var bulletGraphics = LK.getAsset('bossBullet', {});
	bulletGraphics.anchor.set(0.5, 0.5);
	self.addChild(bulletGraphics);
	self.vx = vx;
	self.vy = vy;
	self.move = function () {
		self.x += self.vx;
		self.y += self.vy;
	};
});
var Bullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = LK.getAsset('bullet', {});
	bulletGraphics.anchor.set(0.5, 0.5);
	self.addChild(bulletGraphics);
});
var Enemy = Container.expand(function (isBoss, enemyType) {
	var self = Container.call(this);
	isBoss = isBoss || false;
	enemyType = enemyType || 'enemy1';
	var enemyGraphics;
	if (isBoss) {
		enemyGraphics = LK.getAsset('boss', {});
	} else {
		switch (enemyType) {
			case 'enemy1':
				enemyGraphics = LK.getAsset('enemy1', {});
				break;
			case 'enemy2':
				enemyGraphics = LK.getAsset('enemy2', {});
				break;
			case 'enemy3':
				enemyGraphics = LK.getAsset('enemy3', {});
				break;
			case 'enemy4':
				enemyGraphics = LK.getAsset('enemy4', {});
				break;
			case 'enemy5':
				enemyGraphics = LK.getAsset('enemy5', {});
				break;
			default:
				enemyGraphics = LK.getAsset('enemy1', {});
		}
	}
	enemyGraphics.anchor.set(0.5, 0.5);
	self.healthBar = new HealthBar(isBoss ? 500 : 50);
	self.healthBar.y = -enemyGraphics.height / 2 - self.healthBar.height - 5;
	self.healthBar.x = -self.healthBar.width / 2;
	self.addChild(self.healthBar);
	self.addChild(enemyGraphics);
	self.state = "flyingIntoScreen";
	self.flyInY = isBoss ? 2732 / 4 : Math.random() * (2732 / 2 - 100) + 50;
	self.angle = 0;
	self.shootCounter = Math.random() * 100;
	self.shoot = function (heroX, heroY, container) {
		var dx = heroX - self.x;
		var dy = heroY - self.y;
		var distance = Math.sqrt(dx * dx + dy * dy);
		var speedMultiplier = 1 + container.score * 0.001;
		var vx = 7 * speedMultiplier * dx / distance;
		var vy = 7 * speedMultiplier * dy / distance;
		var enemyBullet = isBoss ? new BossBullet(vx, vy) : new EnemyBullet(vx, vy);
		enemyBullet.x = self.x;
		enemyBullet.y = self.y + enemyGraphics.height / 2;
		return enemyBullet;
	};
	self.move = function (speed) {
		if (self.state === "flyingIntoScreen") {
			self.y += speed;
			if (self.y >= self.flyInY) {
				self.state = "circularPattern";
			}
		} else if (self.state === "circularPattern") {
			self.angle += 0.025;
			self.x += Math.cos(self.angle) * speed;
			self.y += Math.sin(2 * self.angle) * speed * 0.5;
		}
	};
});
var EnemyBullet = Container.expand(function (vx, vy) {
	var self = Container.call(this);
	var bulletGraphics = LK.getAsset('enemyBullet', {});
	bulletGraphics.anchor.set(0.5, 0.5);
	self.addChild(bulletGraphics);
	self.vx = vx;
	self.vy = vy;
	self.move = function () {
		self.x += self.vx;
		self.y += self.vy;
	};
});
var HealthBar = Container.expand(function (maxHealth) {
	var self = Container.call(this);
	self.maxHealth = maxHealth;
	self.currentHealth = maxHealth;
	self.isDead = function () {
		return self.currentHealth <= 0;
	};
	self.bar = LK.getAsset('healthBar', {});
	self.bar.width = maxHealth === 500 ? 400 : 100;
	self.bar.height = maxHealth === 500 ? 20 : 10;
	self.addChild(self.bar);
	self.updateHealth = function (health) {
		self.currentHealth = health;
		self.bar.scale.x = self.currentHealth / self.maxHealth;
	};
});
var Hero = Container.expand(function () {
	var self = Container.call(this);
	self.doubleCannon = false;
	self.doubleCannonPowerUpCount = 0;
	var heroGraphics = LK.getAsset('hero', {});
	heroGraphics.anchor.set(0.5, 0.5);
	self.healthBar = new HealthBar(100);
	self.healthBar.y = -heroGraphics.height / 2 - self.healthBar.height - 5;
	self.healthBar.x = -self.healthBar.width / 2;
	self.addChild(self.healthBar);
	self.addChild(heroGraphics);
	self.moveTowards = function (target, speed) {
		var dx = target.x - self.x;
		var dy = target.y - self.y;
		var distance = Math.sqrt(dx * dx + dy * dy);
		if (distance > speed) {
			self.x += dx * speed / distance;
			self.y += dy * speed / distance;
		} else {
			self.x = target.x;
			self.y = target.y;
		}
	};
	self.fireBullet = function () {
		var bullets = [];
		for (var i = 0; i < 5; i++) {
			var bullet = new Bullet();
			bullet.x = self.x + i * 20 - 40;
			bullet.y = self.y - heroGraphics.height / 2;
			bullets.push(bullet);
		}
		return bullets;
	};
});
var PowerUp = Container.expand(function (type) {
	var self = Container.call(this);
	self.type = type;
	var powerUpGraphics = self.type === 'doubleCannon' ? LK.getAsset('doubleCannonPowerUp', {}) : LK.getAsset('powerUp', {});
	powerUpGraphics.anchor.set(0.5, 0.5);
	self.addChild(powerUpGraphics);
	self.speed = 3;
	self.move = function () {
		self.y += self.speed;
	};
});
var StarField = Container.expand(function () {
	var self = Container.call(this);
	self.stars = [];
	var numberOfStars = 300;
	for (var i = 0; i < numberOfStars; i++) {
		var star = LK.getAsset('star', {});
		star.anchor.set(0.5, 0.5);
		star.x = Math.random() * 2048;
		star.y = Math.random() * 2732;
		star.speed = Math.random() * 2 + 0.5;
		star.alpha = Math.random() * 0.5 + 0.5;
		self.addChild(star);
		self.stars.push(star);
	}
	self.update = function () {
		for (var i = 0; i < self.stars.length; i++) {
			var star = self.stars[i];
			star.y += star.speed;
			if (star.y > 2732) {
				star.y -= 2732;
			}
		}
	};
});
/**** 
* Initialize Game
****/
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/
var scoreText = new Text2('0', {
	size: 150,
	font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
	fill: "#ffffff"
});
scoreText.anchor.set(.5, 0);
LK.gui.top.addChild(scoreText);
game.powerUpIcons = new Container();
game.powerUpIcons.x = 2048 - 100;
game.powerUpIcons.y = 2732 - 100;
game.addChild(game.powerUpIcons);
var starField = game.addChild(new StarField());
game.score = 0;
var hero = game.addChild(new Hero());
hero.x = 1024;
hero.y = 2420;
var enemies = [];
var bullets = [];
var enemyBullets = [];
var spawnEnemy = function spawnEnemy(x, y, isBoss, enemyType) {
	var enemy = new Enemy(isBoss, enemyType);
	enemy.x = x;
	enemy.y = y;
	game.addChild(enemy);
	enemies.push(enemy);
};
var fireBullet = function fireBullet() {
	var bullet = hero.fireBullet();
	game.addChild(bullet);
	bullets.push(bullet);
};
var currentWave = 1;
var spawnWave = function spawnWave() {
	var enemyType = 'enemy' + ((currentWave - 1) % 5 + 1);
	for (var i = 0; i < 5 + Math.floor(currentWave / 2); i++) {
		var x = Math.random() * (2048 - 100) + 50;
		spawnEnemy(x, -100, false, enemyType);
	}
};
var spawnPowerUp = function spawnPowerUp() {
	var x = Math.random() * (2048 - 100) + 50;
	var powerUp = new PowerUp(Math.random() < 0.5 ? 'doubleCannon' : 'default');
	powerUp.x = x;
	powerUp.y = -100;
	game.addChild(powerUp);
	powerUps.push(powerUp);
};
var powerUps = [];
var checkPowerUpCollision = function checkPowerUpCollision() {
	for (var i = 0; i < powerUps.length; i++) {
		var powerUp = powerUps[i];
		if (hero.intersects(powerUp)) {
			game.removeChild(powerUp);
			powerUps.splice(i, 1);
			if (powerUp.type === 'doubleCannon') {
				hero.doubleCannon = true;
				hero.doubleCannonPowerUpCount++;
				var powerUpIcon = LK.getAsset('doubleCannonPowerUp', {});
				powerUpIcon.anchor.set(0.5, 0.5);
				powerUpIcon.x = -85 * game.powerUpIcons.children.length;
				game.powerUpIcons.addChild(powerUpIcon);
				LK.setTimeout(function () {
					hero.doubleCannonPowerUpCount--;
					if (hero.doubleCannonPowerUpCount === 0) {
						hero.doubleCannon = false;
					}
					game.powerUpIcons.removeChild(powerUpIcon);
					game.powerUpIcons.children.forEach(function (icon, index) {
						icon.x = -50 * index;
					});
				}, 15000);
			} else {
				heroSpeed *= 2;
				var powerUpIcon = LK.getAsset('powerUp', {});
				powerUpIcon.anchor.set(0.5, 0.5);
				powerUpIcon.x = -50 * game.powerUpIcons.children.length;
				game.powerUpIcons.addChild(powerUpIcon);
				LK.setTimeout(function () {
					heroSpeed /= 2;
					game.powerUpIcons.removeChild(powerUpIcon);
					game.powerUpIcons.children.forEach(function (icon, index) {
						icon.x = -50 * index;
					});
				}, 15000);
			}
		}
	}
};
spawnWave();
currentWave++;
var spawnBoss = function spawnBoss() {
	var x = 1024;
	var y = -100;
	spawnEnemy(x, y, true, 'boss');
};
var autoFire = LK.setInterval(function () {
	var bulletsFired = hero.fireBullet();
	bulletsFired.forEach(function (bullet) {
		game.addChild(bullet);
		bullets.push(bullet);
	});
}, 600);
var targetPosition = {
	x: hero.x,
	y: hero.y
};
game.on('move', function (obj) {
	var event = obj.event;
	var pos = event.getLocalPosition(game);
	targetPosition.x = pos.x;
	targetPosition.y = pos.y;
});
var heroSpeed = 15;
function resetGame() {
	bullets.forEach(function (bullet) {
		game.removeChild(bullet);
	});
	enemyBullets.forEach(function (bullet) {
		game.removeChild(bullet);
	});
	enemies.forEach(function (enemy) {
		game.removeChild(enemy);
	});
	bullets = [];
	enemyBullets = [];
	enemies = [];
	hero.x = 1024;
	hero.y = 2420;
	hero.healthBar.updateHealth(hero.healthBar.maxHealth);
	game.score = 0;
	currentWave = 1;
	spawnWave();
}
LK.on('tick', function () {
	hero.moveTowards(targetPosition, heroSpeed);
	hero.x = Math.min(Math.max(hero.x, 0), 2048);
	hero.y = Math.min(Math.max(hero.y, 0), 2732);
});
LK.on('tick', function () {
	starField.update();
	for (var i = 0; i < powerUps.length; i++) {
		powerUps[i].move();
		if (powerUps[i].y > 2732 || powerUps[i].x < 0 || powerUps[i].x > 2048) {
			game.removeChild(powerUps[i]);
			powerUps.splice(i, 1);
			i--;
		}
	}
	checkPowerUpCollision();
	if (Math.random() < 0.001) {
		spawnPowerUp();
	}
	for (var i = 0; i < enemies.length; i++) {
		enemies[i].move(5 + game.score * 0.001);
	}
	for (var i = 0; i < enemies.length; i++) {
		enemies[i].move(5);
		enemies[i].shootCounter--;
		if (enemies[i].shootCounter <= 0) {
			var enemyBullet = enemies[i].shoot(hero.x, hero.y, game);
			game.addChild(enemyBullet);
			enemyBullets.push(enemyBullet);
			enemies[i].shootCounter = (enemies[i].isBoss ? 50 : 100) + Math.random() * 100;
		}
	}
	for (var j = 0; j < enemyBullets.length; j++) {
		enemyBullets[j].move();
		if (enemyBullets[j].x >= hero.x - hero.width / 2 && enemyBullets[j].x <= hero.x + hero.width / 2 && enemyBullets[j].y >= hero.y - hero.height / 2 && enemyBullets[j].y <= hero.y + hero.height / 2) {
			hero.healthBar.updateHealth(hero.healthBar.currentHealth - 10);
			game.removeChild(enemyBullets[j]);
			enemyBullets.splice(j, 1);
			if (hero.healthBar.isDead()) {
				resetGame();
				return;
			}
		}
		if (enemyBullets[j] && enemyBullets[j].y > 2732 + 30) {
			game.removeChild(enemyBullets[j]);
			enemyBullets.splice(j, 1);
			j--;
		}
	}
	function checkBulletCollision(bulletsArray, targetArray, onHitCallback) {
		for (var j = 0; j < bulletsArray.length; j++) {
			bulletsArray[j].y -= 10;
			if (bulletsArray[j].y < -30 || bulletsArray[j].y > 2732 || bulletsArray[j].x < 0 || bulletsArray[j].x > 2048) {
				game.removeChild(bulletsArray[j]);
				bulletsArray.splice(j, 1);
				j--;
			} else {
				for (var k = targetArray.length - 1; k >= 0; k--) {
					var target = targetArray[k];
					if (target.intersects(bulletsArray[j])) {
						game.removeChild(bulletsArray[j]);
						bulletsArray.splice(j, 1);
						j--;
						onHitCallback(target, k);
						break;
					}
				}
			}
		}
	}
	checkBulletCollision(bullets, enemies, function (enemy, index) {
		enemy.healthBar.updateHealth(enemy.healthBar.currentHealth - 10);
		if (enemy.healthBar.isDead()) {
			game.removeChild(enemy);
			enemies.splice(index, 1);
			game.score += 10 * currentWave;
			if (enemies.length === 0) {
				if (currentWave % 5 === 0) {
					spawnBoss();
				} else {
					spawnWave();
				}
				currentWave++;
			}
			scoreText.setText(game.score);
		}
	});
});
:quality(85)/https://cdn.frvr.ai/0eb07d5b-de12-4036-9216-a80581031ecc_br_transparent_trim.png%3F3) 
 Alien enemy, adopted to space, flying down Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
:quality(85)/https://cdn.frvr.ai/4b339a57-4cb8-4ffe-b3ec-33616412d750_tr_transparent_trim.png%3F3) 
 Alien enemy boss, adopted to space, flying down Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
:quality(85)/https://cdn.frvr.ai/65d8d5e51c48391c14373b7b.png%3F3) 
 a spacex starshiip rocket. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65d8d6a61c48391c14373b91.png%3F3) 
 the shape of CALIFORNIA. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/671b7306-1c05-46b1-942f-6eda281976db_tr_transparent_trim.png%3F3) 
 Alien enemy, adopted to space, flying down Game Texture. In-Game asset. 2d. Pixelart. blank background. Low detail. High contrast.
:quality(85)/https://cdn.frvr.ai/9d7c35db-06d3-4008-8d6e-0b211a0d43f7_tl_transparent_trim.png%3F3) 
 Dark circular power up with three bright yellow arrows pointing upwards. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
:quality(85)/https://cdn.frvr.ai/a49d1637-8f47-470d-8c8f-6a61f3640fae_bl_transparent_trim.png%3F3) 
 Dark circular power up indicating double cannons. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
:quality(85)/https://cdn.frvr.ai/e5a8ad2b-4f1a-42fc-8348-039033cedf30_br_transparent_trim.png%3F3) 
 Create a 2D top-down view pixel art image of a bullet for a space shooter game. The bullet should be facing upward, as it will be used as a projectile fired from the hero spaceship towards enemies in the game. The design should be sleek and give off a sense of motion. Please provide the image on a white background. Game Texture. In-Game asset. 2d. Pixelart. blank background. Low detail. High contrast.
:quality(85)/https://cdn.frvr.ai/eba8262f-3c8c-4239-a383-0ba0c296e904_tl_transparent_trim.png%3F3) 
 Single alien slime bullet, round. Game Texture. In-Game asset. 2d. Pixelart. blank background. Low detail. High contrast.
:quality(85)/https://cdn.frvr.ai/fef6f48b-edbc-4784-bd4a-e0f2e572c6ad_br_transparent_trim.png%3F3) 
 Single alien boss slime bullet, round Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.