var BombCountdown = Container.expand(function (initialTime) {
	var self = Container.call(this);
	self.timeRemaining = initialTime;
	self.countdownText = new Text2(self.timeRemaining.toString(), {
		size: 100,
		fill: '#ffffff'
	});
	self.countdownText.anchor.set(0.5);
	self.addChild(self.countdownText);
	self.update = function (delta) {
		self.timeRemaining -= delta;
		if (self.timeRemaining < 0) self.timeRemaining = 0;
		self.countdownText.setText('Next bomb in: ' + Math.ceil(self.timeRemaining).toString());
	};
});
var BombPickup = Container.expand(function () {
	var self = Container.call(this);
	self.bombGraphics = self.createAsset('bombPickup', 'Bomb Pickup', 0.5, 0.5);
	self.bombGraphics.scale.set(1.3);
});
var Star = Container.expand(function (speed) {
	var self = Container.call(this);
	self.starGraphics = self.createAsset('star', 'White Round Star', 0.5, 0.5);
	self.speed = speed;
	self.move = function () {
		self.y += self.speed;
		if (self.y > 2732) {
			self.y = -self.starGraphics.height;
			self.x = Math.random() * 2048;
		}
	};
});
var HealthPickup = Container.expand(function () {
	var self = Container.call(this);
	self.pickupGraphics = self.createAsset('healthPickup', 'Health Pickup', 0.5, 0.5);
	self.pickupGraphics.scale.set(1.3);
});
var HealthBar = Container.expand(function (maxHealth, currentHealth) {
	var self = Container.call(this);
	self.maxHealth = maxHealth;
	self.currentHealth = currentHealth;
	self.background = self.createAsset('healthBarBackground', 'Health Bar Background', 0, 0.5);
	self.background.scale.set(2, 0.125);
	self.foreground = self.createAsset('healthBarForeground', 'Health Bar Foreground', 0, 0.5);
	self.foreground.scale.set(2, 0.125);
	self.updateHealth = function (newHealth) {
		self.currentHealth = newHealth;
		self.foreground.scale.x = self.currentHealth / self.maxHealth;
	};
});
var Bullet = Container.expand(function () {
	var self = Container.call(this);
	self.bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5);
	self.bulletGraphics.scale.set(0.2);
	var speed = 20;
	self.direction = 0;
	self.move = function () {
		self.x += Math.cos(self.direction) * speed;
		self.y += Math.sin(self.direction) * speed;
		if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
			if (self.parent && self.parent.bullets && self.parent.bullets.includes(self)) {
				self.parent.bullets.splice(self.parent.bullets.indexOf(self), 1);
				self.destroy();
			}
		}
	};
	self.hit = function (enemy) {
		if (self.parent && self.parent.enemies && self.parent.enemies.includes(enemy)) {
			enemy.enemyGraphics.scale.x /= 1.2;
			enemy.enemyGraphics.scale.y /= 1.2;
			if (enemy.enemyGraphics.scale.x < 0.8 || enemy.enemyGraphics.scale.y < 0.8) {
				self.parent.enemies.splice(self.parent.enemies.indexOf(enemy), 1);
				self.parent.score += 10;
				self.parent.scoreText.setText('Score: ' + self.parent.score.toString());
				enemy.destroy();
				if (self.parent) {
					self.parent.score += 10;
					self.parent.scoreText.setText('Score: ' + self.parent.score.toString());
				}
				if (self.parent && self.parent.bullets && self.parent.bullets.includes(self)) {
					self.parent.bullets.splice(self.parent.bullets.indexOf(self), 1);
					self.destroy();
				}
			}
		}
	};
});
var Hero = Container.expand(function () {
	var self = Container.call(this);
	self.health = 100;
	var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
	heroGraphics.scale.set(1);
	heroGraphics.rotation = Math.PI / 2;
	self.bullets = [];
	self.move = function () {
		for (var i = 0; i < self.bullets.length; i++) {
			self.bullets[i].move();
		}
	};
	self.lastDamageTime = 0;
	self.reduceHealth = function (amount) {
		var currentTime = LK.ticks;
		if (currentTime - self.lastDamageTime >= 15) {
			self.health -= amount * 2;
			if (self.health < 0) self.health = 0;
			self.healthBar.updateHealth(self.health);
			self.lastDamageTime = currentTime;
		}
	};
	self.lastShootTime = 0;
	self.shoot = function () {
		var currentTime = LK.ticks;
		if (currentTime - self.lastShootTime >= 6) {
			var nearestEnemy = self.parent.findNearestEnemy(self.x, self.y);
			if (nearestEnemy) {
				var bullet = new Bullet();
				bullet.x = self.x;
				bullet.y = self.y;
				bullet.direction = Math.atan2(nearestEnemy.y - self.y, nearestEnemy.x - self.x);
				self.rotation = bullet.direction;
				self.bullets.push(bullet);
				self.parent.addChild(bullet);
				bullet.move();
				self.lastShootTime = currentTime;
			}
		}
	};
	self.trackMovement = function (event) {
		var pos = event.getLocalPosition(self.parent);
		self.x = pos.x;
		self.y = pos.y;
		self.healthBar.x = self.x - self.healthBar.width / 2;
		self.healthBar.y = self.y - heroGraphics.height / 2 - 10;
	};
});
var YellowEnemy = Container.expand(function () {
	var self = Container.call(this);
	self.enemyGraphics = self.createAsset('yellowEnemy', 'Yellow Enemy character', .5, .5);
	var direction = Math.random() * Math.PI * 2;
	var speed = 2 * (0.8 + Math.random() * 1);
	self.move = function () {
		if (self.parent && self.parent.hero && self.parent.hero.x === self.parent.hero.lastX && self.parent.hero.y === self.parent.hero.lastY) {
			direction = Math.atan2(self.parent.hero.y - self.y, self.parent.hero.x - self.x);
		}
		if (direction < 0) direction += 2 * Math.PI;
		if (direction > 2 * Math.PI) direction -= 2 * Math.PI;
		self.x += Math.cos(direction) * speed;
		self.y += Math.sin(direction) * speed;
		direction += (Math.random() - 0.5) * 0.1;
		self.enemyGraphics.rotation = direction;
		var margin = 100;
		if (self.x < margin) {
			self.x = margin;
			direction = 0;
		} else if (self.x > 2048 - margin) {
			self.x = 2048 - margin;
			direction = Math.PI;
		}
		if (self.y < margin) {
			self.y = margin;
			direction = Math.PI / 2;
		} else if (self.y > 2732 - margin) {
			self.y = 2732 - margin;
			direction = 3 * Math.PI / 2;
		}
		if (self.enemyGraphics.scale.x < 0.8 || self.enemyGraphics.scale.y < 0.8) {
			self.destroy();
		}
	};
	self.grow = function () {
		if (self.enemyGraphics.scale.x < 5 && self.enemyGraphics.scale.y < 5) {
			self.enemyGraphics.scale.x *= 1.2;
			self.enemyGraphics.scale.y *= 1.2;
		}
	};
	LK.setInterval(self.grow, 1500);
});
var Game = Container.expand(function () {
	var self = Container.call(this);
	self.spawnBombPickup = function () {
		var bombPickup = new BombPickup();
		bombPickup.x = Math.random() * (2048 - bombPickup.bombGraphics.width) + bombPickup.bombGraphics.width / 2;
		bombPickup.y = Math.random() * (2732 - bombPickup.bombGraphics.height) + bombPickup.bombGraphics.height / 2;
		self.bombPickups.push(bombPickup);
		self.addChild(bombPickup);
	};
	self.bombCountdown = new BombCountdown(30);
	self.bombCountdown.x = 2048 / 2 - 100 - 400 - 200 + 100;
	self.bombCountdown.y = 50;
	self.bombCountdown.countdownText.anchor.set(0.5, 0);
	self.addChild(self.bombCountdown);
	LK.setInterval(self.spawnBombPickup, 30000);
	self.checkForBombPickup = function (hero, bombPickups) {
		for (var i = bombPickups.length - 1; i >= 0; i--) {
			var pickup = bombPickups[i];
			if (hero.intersects(pickup)) {
				while (self.enemies.length > 0) {
					var enemy = self.enemies.pop();
					self.score += 10;
					self.scoreText.setText('Score: ' + self.score.toString());
					enemy.destroy();
				}
				self.bombCountdown.timeRemaining = 30;
				self.bombCountdown.update(0);
				pickup.destroy();
				bombPickups.splice(i, 1);
			}
		}
	};
	self.checkForHealthPickup = function (hero, healthPickups) {
		for (var i = healthPickups.length - 1; i >= 0; i--) {
			var pickup = healthPickups[i];
			if (hero.intersects(pickup)) {
				hero.health = hero.healthBar.maxHealth * 2;
				hero.healthBar.updateHealth(hero.health);
				pickup.destroy();
				healthPickups.splice(i, 1);
			}
		}
	};
	self.spawnHealthPickup = function () {
		var healthPickup = new HealthPickup();
		healthPickup.x = Math.random() * (2048 - healthPickup.pickupGraphics.width) + healthPickup.pickupGraphics.width / 2;
		healthPickup.y = Math.random() * (2732 - healthPickup.pickupGraphics.height) + healthPickup.pickupGraphics.height / 2;
		self.healthPickups.push(healthPickup);
		self.addChild(healthPickup);
	};
	self.findNearestEnemy = function (x, y) {
		var nearestEnemy = null;
		var nearestDistance = Infinity;
		for (var i = 0; i < self.enemies.length; i++) {
			var dx = x - self.enemies[i].x;
			var dy = y - self.enemies[i].y;
			var distanceSquared = dx * dx + dy * dy;
			if (distanceSquared < nearestDistance * nearestDistance) {
				nearestDistance = Math.sqrt(distanceSquared);
				nearestEnemy = self.enemies[i];
			}
		}
		return nearestEnemy;
	};
	LK.on('tick', function () {
		self.bombCountdown.update(1 / 60);
		hero.move();
		for (var i = 0; i < self.enemies.length; i++) {
			self.enemies[i].move();
		}
		for (var i = 0; i < self.enemies.length; i++) {
			if (hero.intersects(self.enemies[i]) && LK.ticks - hero.lastDamageTime >= 15) {
				hero.reduceHealth(10);
				if (hero.health <= 0) {
					LK.showGameOver();
					return;
				}
			}
		}
		self.checkForHealthPickup(hero, self.healthPickups);
		self.checkForBombPickup(hero, self.bombPickups);
		if (hero.health <= hero.healthBar.maxHealth * 0.40 && self.healthPickups.length === 0) {
			self.spawnHealthPickup();
		}
		hero.shoot();
		for (var i = 0; i < hero.bullets.length; i++) {
			for (var j = 0; j < self.enemies.length; j++) {
				if (hero.bullets[i] && hero.bullets[i].intersects(self.enemies[j])) {
					hero.bullets[i].hit(self.enemies[j]);
					hero.bullets[i].destroy();
					hero.bullets.splice(i, 1);
					i--;
				}
			}
			if (hero.bullets[i] && (hero.bullets[i].x < 0 || hero.bullets[i].x > 2048 || hero.bullets[i].y < 0 || hero.bullets[i].y > 2732)) {
				hero.bullets[i].destroy();
				hero.bullets.splice(i, 1);
				i--;
			}
		}
	});
	self.stars = [];
	for (var i = 0; i < 100; i++) {
		var starSpeed = 0.5 + Math.random() * 2;
		var star = new Star(starSpeed);
		star.x = Math.random() * 2048;
		star.y = Math.random() * 2732;
		self.stars.push(star);
		self.addChild(star);
	}
	var hero = self.addChild(new Hero());
	self.score = 0;
	self.scoreText = new Text2('Score: ' + self.score.toString(), {
		size: 100,
		fill: '#ffffff'
	});
	self.scoreText.anchor.set(0.5, 0);
	self.scoreText.x = 2048 / 2 + 700;
	self.scoreText.y = 50;
	self.addChild(self.scoreText);
	hero.healthBar = self.addChild(new HealthBar(hero.health, hero.health));
	self.enemies = [];
	self.score = 0;
	self.healthPickups = [];
	self.bombPickups = [];
	hero.x = 2048 / 2;
	hero.y = 2732 / 2;
	LK.on('tick', function () {
		for (var i = 0; i < self.stars.length; i++) {
			self.stars[i].move();
		}
		hero.move();
		for (var i = 0; i < self.enemies.length; i++) {
			self.enemies[i].move();
		}
	});
	LK.stage.on('move', function (obj) {
		hero.trackMovement(obj.event);
	});
	var enemySpawnCounter = 0;
	var spawnEnemy = LK.setInterval(function () {
		if (self.enemies.length < 50) {
			var enemy = new YellowEnemy();
			var side = Math.floor(Math.random() * 4);
			switch (side) {
				case 0:
					enemy.x = Math.random() * 2048;
					enemy.y = -enemy.enemyGraphics.height;
					break;
				case 1:
					enemy.x = 2048 + enemy.enemyGraphics.width;
					enemy.y = Math.random() * 2732;
					break;
				case 2:
					enemy.x = Math.random() * 2048;
					enemy.y = 2732 + enemy.enemyGraphics.height;
					break;
				case 3:
					enemy.x = -enemy.enemyGraphics.width;
					enemy.y = Math.random() * 2732;
					break;
			}
			self.enemies.push(enemy);
			self.addChild(enemy);
			enemySpawnCounter++;
		}
	}, 325);
});
 var BombCountdown = Container.expand(function (initialTime) {
	var self = Container.call(this);
	self.timeRemaining = initialTime;
	self.countdownText = new Text2(self.timeRemaining.toString(), {
		size: 100,
		fill: '#ffffff'
	});
	self.countdownText.anchor.set(0.5);
	self.addChild(self.countdownText);
	self.update = function (delta) {
		self.timeRemaining -= delta;
		if (self.timeRemaining < 0) self.timeRemaining = 0;
		self.countdownText.setText('Next bomb in: ' + Math.ceil(self.timeRemaining).toString());
	};
});
var BombPickup = Container.expand(function () {
	var self = Container.call(this);
	self.bombGraphics = self.createAsset('bombPickup', 'Bomb Pickup', 0.5, 0.5);
	self.bombGraphics.scale.set(1.3);
});
var Star = Container.expand(function (speed) {
	var self = Container.call(this);
	self.starGraphics = self.createAsset('star', 'White Round Star', 0.5, 0.5);
	self.speed = speed;
	self.move = function () {
		self.y += self.speed;
		if (self.y > 2732) {
			self.y = -self.starGraphics.height;
			self.x = Math.random() * 2048;
		}
	};
});
var HealthPickup = Container.expand(function () {
	var self = Container.call(this);
	self.pickupGraphics = self.createAsset('healthPickup', 'Health Pickup', 0.5, 0.5);
	self.pickupGraphics.scale.set(1.3);
});
var HealthBar = Container.expand(function (maxHealth, currentHealth) {
	var self = Container.call(this);
	self.maxHealth = maxHealth;
	self.currentHealth = currentHealth;
	self.background = self.createAsset('healthBarBackground', 'Health Bar Background', 0, 0.5);
	self.background.scale.set(2, 0.125);
	self.foreground = self.createAsset('healthBarForeground', 'Health Bar Foreground', 0, 0.5);
	self.foreground.scale.set(2, 0.125);
	self.updateHealth = function (newHealth) {
		self.currentHealth = newHealth;
		self.foreground.scale.x = self.currentHealth / self.maxHealth;
	};
});
var Bullet = Container.expand(function () {
	var self = Container.call(this);
	self.bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5);
	self.bulletGraphics.scale.set(0.2);
	var speed = 20;
	self.direction = 0;
	self.move = function () {
		self.x += Math.cos(self.direction) * speed;
		self.y += Math.sin(self.direction) * speed;
		if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
			if (self.parent && self.parent.bullets && self.parent.bullets.includes(self)) {
				self.parent.bullets.splice(self.parent.bullets.indexOf(self), 1);
				self.destroy();
			}
		}
	};
	self.hit = function (enemy) {
		if (self.parent && self.parent.enemies && self.parent.enemies.includes(enemy)) {
			enemy.enemyGraphics.scale.x /= 1.2;
			enemy.enemyGraphics.scale.y /= 1.2;
			if (enemy.enemyGraphics.scale.x < 0.8 || enemy.enemyGraphics.scale.y < 0.8) {
				self.parent.enemies.splice(self.parent.enemies.indexOf(enemy), 1);
				self.parent.score += 10;
				self.parent.scoreText.setText('Score: ' + self.parent.score.toString());
				enemy.destroy();
				if (self.parent) {
					self.parent.score += 10;
					self.parent.scoreText.setText('Score: ' + self.parent.score.toString());
				}
				if (self.parent && self.parent.bullets && self.parent.bullets.includes(self)) {
					self.parent.bullets.splice(self.parent.bullets.indexOf(self), 1);
					self.destroy();
				}
			}
		}
	};
});
var Hero = Container.expand(function () {
	var self = Container.call(this);
	self.health = 100;
	var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
	heroGraphics.scale.set(1);
	heroGraphics.rotation = Math.PI / 2;
	self.bullets = [];
	self.move = function () {
		for (var i = 0; i < self.bullets.length; i++) {
			self.bullets[i].move();
		}
	};
	self.lastDamageTime = 0;
	self.reduceHealth = function (amount) {
		var currentTime = LK.ticks;
		if (currentTime - self.lastDamageTime >= 15) {
			self.health -= amount * 2;
			if (self.health < 0) self.health = 0;
			self.healthBar.updateHealth(self.health);
			self.lastDamageTime = currentTime;
		}
	};
	self.lastShootTime = 0;
	self.shoot = function () {
		var currentTime = LK.ticks;
		if (currentTime - self.lastShootTime >= 6) {
			var nearestEnemy = self.parent.findNearestEnemy(self.x, self.y);
			if (nearestEnemy) {
				var bullet = new Bullet();
				bullet.x = self.x;
				bullet.y = self.y;
				bullet.direction = Math.atan2(nearestEnemy.y - self.y, nearestEnemy.x - self.x);
				self.rotation = bullet.direction;
				self.bullets.push(bullet);
				self.parent.addChild(bullet);
				bullet.move();
				self.lastShootTime = currentTime;
			}
		}
	};
	self.trackMovement = function (event) {
		var pos = event.getLocalPosition(self.parent);
		self.x = pos.x;
		self.y = pos.y;
		self.healthBar.x = self.x - self.healthBar.width / 2;
		self.healthBar.y = self.y - heroGraphics.height / 2 - 10;
	};
});
var YellowEnemy = Container.expand(function () {
	var self = Container.call(this);
	self.enemyGraphics = self.createAsset('yellowEnemy', 'Yellow Enemy character', .5, .5);
	var direction = Math.random() * Math.PI * 2;
	var speed = 2 * (0.8 + Math.random() * 1);
	self.move = function () {
		if (self.parent && self.parent.hero && self.parent.hero.x === self.parent.hero.lastX && self.parent.hero.y === self.parent.hero.lastY) {
			direction = Math.atan2(self.parent.hero.y - self.y, self.parent.hero.x - self.x);
		}
		if (direction < 0) direction += 2 * Math.PI;
		if (direction > 2 * Math.PI) direction -= 2 * Math.PI;
		self.x += Math.cos(direction) * speed;
		self.y += Math.sin(direction) * speed;
		direction += (Math.random() - 0.5) * 0.1;
		self.enemyGraphics.rotation = direction;
		var margin = 100;
		if (self.x < margin) {
			self.x = margin;
			direction = 0;
		} else if (self.x > 2048 - margin) {
			self.x = 2048 - margin;
			direction = Math.PI;
		}
		if (self.y < margin) {
			self.y = margin;
			direction = Math.PI / 2;
		} else if (self.y > 2732 - margin) {
			self.y = 2732 - margin;
			direction = 3 * Math.PI / 2;
		}
		if (self.enemyGraphics.scale.x < 0.8 || self.enemyGraphics.scale.y < 0.8) {
			self.destroy();
		}
	};
	self.grow = function () {
		if (self.enemyGraphics.scale.x < 5 && self.enemyGraphics.scale.y < 5) {
			self.enemyGraphics.scale.x *= 1.2;
			self.enemyGraphics.scale.y *= 1.2;
		}
	};
	LK.setInterval(self.grow, 1500);
});
var Game = Container.expand(function () {
	var self = Container.call(this);
	self.spawnBombPickup = function () {
		var bombPickup = new BombPickup();
		bombPickup.x = Math.random() * (2048 - bombPickup.bombGraphics.width) + bombPickup.bombGraphics.width / 2;
		bombPickup.y = Math.random() * (2732 - bombPickup.bombGraphics.height) + bombPickup.bombGraphics.height / 2;
		self.bombPickups.push(bombPickup);
		self.addChild(bombPickup);
	};
	self.bombCountdown = new BombCountdown(30);
	self.bombCountdown.x = 2048 / 2 - 100 - 400 - 200 + 100;
	self.bombCountdown.y = 50;
	self.bombCountdown.countdownText.anchor.set(0.5, 0);
	self.addChild(self.bombCountdown);
	LK.setInterval(self.spawnBombPickup, 30000);
	self.checkForBombPickup = function (hero, bombPickups) {
		for (var i = bombPickups.length - 1; i >= 0; i--) {
			var pickup = bombPickups[i];
			if (hero.intersects(pickup)) {
				while (self.enemies.length > 0) {
					var enemy = self.enemies.pop();
					self.score += 10;
					self.scoreText.setText('Score: ' + self.score.toString());
					enemy.destroy();
				}
				self.bombCountdown.timeRemaining = 30;
				self.bombCountdown.update(0);
				pickup.destroy();
				bombPickups.splice(i, 1);
			}
		}
	};
	self.checkForHealthPickup = function (hero, healthPickups) {
		for (var i = healthPickups.length - 1; i >= 0; i--) {
			var pickup = healthPickups[i];
			if (hero.intersects(pickup)) {
				hero.health = hero.healthBar.maxHealth * 2;
				hero.healthBar.updateHealth(hero.health);
				pickup.destroy();
				healthPickups.splice(i, 1);
			}
		}
	};
	self.spawnHealthPickup = function () {
		var healthPickup = new HealthPickup();
		healthPickup.x = Math.random() * (2048 - healthPickup.pickupGraphics.width) + healthPickup.pickupGraphics.width / 2;
		healthPickup.y = Math.random() * (2732 - healthPickup.pickupGraphics.height) + healthPickup.pickupGraphics.height / 2;
		self.healthPickups.push(healthPickup);
		self.addChild(healthPickup);
	};
	self.findNearestEnemy = function (x, y) {
		var nearestEnemy = null;
		var nearestDistance = Infinity;
		for (var i = 0; i < self.enemies.length; i++) {
			var dx = x - self.enemies[i].x;
			var dy = y - self.enemies[i].y;
			var distanceSquared = dx * dx + dy * dy;
			if (distanceSquared < nearestDistance * nearestDistance) {
				nearestDistance = Math.sqrt(distanceSquared);
				nearestEnemy = self.enemies[i];
			}
		}
		return nearestEnemy;
	};
	LK.on('tick', function () {
		self.bombCountdown.update(1 / 60);
		hero.move();
		for (var i = 0; i < self.enemies.length; i++) {
			self.enemies[i].move();
		}
		for (var i = 0; i < self.enemies.length; i++) {
			if (hero.intersects(self.enemies[i]) && LK.ticks - hero.lastDamageTime >= 15) {
				hero.reduceHealth(10);
				if (hero.health <= 0) {
					LK.showGameOver();
					return;
				}
			}
		}
		self.checkForHealthPickup(hero, self.healthPickups);
		self.checkForBombPickup(hero, self.bombPickups);
		if (hero.health <= hero.healthBar.maxHealth * 0.40 && self.healthPickups.length === 0) {
			self.spawnHealthPickup();
		}
		hero.shoot();
		for (var i = 0; i < hero.bullets.length; i++) {
			for (var j = 0; j < self.enemies.length; j++) {
				if (hero.bullets[i] && hero.bullets[i].intersects(self.enemies[j])) {
					hero.bullets[i].hit(self.enemies[j]);
					hero.bullets[i].destroy();
					hero.bullets.splice(i, 1);
					i--;
				}
			}
			if (hero.bullets[i] && (hero.bullets[i].x < 0 || hero.bullets[i].x > 2048 || hero.bullets[i].y < 0 || hero.bullets[i].y > 2732)) {
				hero.bullets[i].destroy();
				hero.bullets.splice(i, 1);
				i--;
			}
		}
	});
	self.stars = [];
	for (var i = 0; i < 100; i++) {
		var starSpeed = 0.5 + Math.random() * 2;
		var star = new Star(starSpeed);
		star.x = Math.random() * 2048;
		star.y = Math.random() * 2732;
		self.stars.push(star);
		self.addChild(star);
	}
	var hero = self.addChild(new Hero());
	self.score = 0;
	self.scoreText = new Text2('Score: ' + self.score.toString(), {
		size: 100,
		fill: '#ffffff'
	});
	self.scoreText.anchor.set(0.5, 0);
	self.scoreText.x = 2048 / 2 + 700;
	self.scoreText.y = 50;
	self.addChild(self.scoreText);
	hero.healthBar = self.addChild(new HealthBar(hero.health, hero.health));
	self.enemies = [];
	self.score = 0;
	self.healthPickups = [];
	self.bombPickups = [];
	hero.x = 2048 / 2;
	hero.y = 2732 / 2;
	LK.on('tick', function () {
		for (var i = 0; i < self.stars.length; i++) {
			self.stars[i].move();
		}
		hero.move();
		for (var i = 0; i < self.enemies.length; i++) {
			self.enemies[i].move();
		}
	});
	LK.stage.on('move', function (obj) {
		hero.trackMovement(obj.event);
	});
	var enemySpawnCounter = 0;
	var spawnEnemy = LK.setInterval(function () {
		if (self.enemies.length < 50) {
			var enemy = new YellowEnemy();
			var side = Math.floor(Math.random() * 4);
			switch (side) {
				case 0:
					enemy.x = Math.random() * 2048;
					enemy.y = -enemy.enemyGraphics.height;
					break;
				case 1:
					enemy.x = 2048 + enemy.enemyGraphics.width;
					enemy.y = Math.random() * 2732;
					break;
				case 2:
					enemy.x = Math.random() * 2048;
					enemy.y = 2732 + enemy.enemyGraphics.height;
					break;
				case 3:
					enemy.x = -enemy.enemyGraphics.width;
					enemy.y = Math.random() * 2732;
					break;
			}
			self.enemies.push(enemy);
			self.addChild(enemy);
			enemySpawnCounter++;
		}
	}, 325);
});
 amoeba Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Green equilateral triangle, fills the entire picture space in width and height Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 square box viewed from above. White with a large Red Cross Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Purple bomb Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 space image stylised gas clouds, black and white image, low contrast