/**** 
* Classes
****/ 
var Bullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('bullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 20;
	self._move_migrated = function () {
		self.x += self.speed * Math.cos(self.angle);
		self.y += self.speed * Math.sin(self.angle);
		self.rotation += 0.1;
	};
});
var Enemy = Container.expand(function (hero) {
	var self = Container.call(this);
	var enemyGraphics = self.attachAsset('enemy', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self._move_migrated = function () {
		var dx = hero.x - self.x;
		var dy = hero.y - self.y;
		var distance = Math.sqrt(dx * dx + dy * dy);
		self.x += dx / distance * 1.8;
		self.y += dy / distance * 1.8;
	};
});
var Hero = Container.expand(function () {
	var self = Container.call(this);
	var heroGraphics = self.attachAsset('hero', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self._move_migrated = function () {
		if (self.targetPos) {
			var dx = self.targetPos.x - self.x;
			var dy = self.targetPos.y - self.y;
			var distance = Math.sqrt(dx * dx + dy * dy);
			if (distance > 5) {
				self.x += dx / distance * 10;
				self.y += dy / distance * 10;
			} else {
				self.x = self.targetPos.x;
				self.y = self.targetPos.y;
				self.targetPos = null;
			}
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
game.setBackgroundColor(0x008000);
var hero = game.addChild(new Hero());
hero.enemies = [];
var heroBullets = [];
var enemyBullets = [];
hero.x = 2048 / 2;
hero.y = 2732 / 2;
game.targetPos = null;
game.on('down', function (x, y, obj) {
	hero.targetPos = game.toLocal(obj.global);
});
var spawnEnemy = function spawnEnemy() {
	var side = Math.floor(Math.random() * 4);
	var enemy = new Enemy(hero);
	switch (side) {
		case 0:
			enemy.x = Math.random() * 2048;
			enemy.y = 0;
			break;
		case 1:
			enemy.x = 2048;
			enemy.y = Math.random() * 2732;
			break;
		case 2:
			enemy.x = Math.random() * 2048;
			enemy.y = 2732;
			break;
		case 3:
			enemy.x = 0;
			enemy.y = Math.random() * 2732;
			break;
	}
	hero.enemies.push(enemy);
	game.addChild(enemy);
};
LK.on('tick', function () {
	hero._move_migrated();
	for (var i = 0; i < heroBullets.length; i++) {
		heroBullets[i]._move_migrated();
	}
	for (var i = 0; i < enemyBullets.length; i++) {
		enemyBullets[i]._move_migrated();
	}
	for (var i = 0; i < hero.enemies.length; i++) {
		hero.enemies[i]._move_migrated();
		for (var j = 0; j < heroBullets.length; j++) {
			if (heroBullets[j].intersects(hero.enemies[i])) {
				heroBullets[j].destroy();
				heroBullets.splice(j, 1);
				hero.enemies[i].destroy();
				hero.enemies.splice(i, 1);
				i--;
				j--;
			}
		}
		if (hero.intersects(hero.enemies[i])) {
			LK.showGameOver();
		}
	}
	if (LK.ticks % 30 === 0) {
		spawnEnemy();
	}
	if (LK.ticks % 20 === 0 && hero.targetPos) {
		var bullet = new Bullet();
		bullet.x = hero.x;
		bullet.y = hero.y;
		var dx = hero.targetPos.x - hero.x;
		var dy = hero.targetPos.y - hero.y;
		bullet.angle = Math.atan2(dy, dx);
		heroBullets.push(bullet);
		game.addChild(bullet);
	}
}); /**** 
* Classes
****/ 
var Bullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.attachAsset('bullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 20;
	self._move_migrated = function () {
		self.x += self.speed * Math.cos(self.angle);
		self.y += self.speed * Math.sin(self.angle);
		self.rotation += 0.1;
	};
});
var Enemy = Container.expand(function (hero) {
	var self = Container.call(this);
	var enemyGraphics = self.attachAsset('enemy', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self._move_migrated = function () {
		var dx = hero.x - self.x;
		var dy = hero.y - self.y;
		var distance = Math.sqrt(dx * dx + dy * dy);
		self.x += dx / distance * 1.8;
		self.y += dy / distance * 1.8;
	};
});
var Hero = Container.expand(function () {
	var self = Container.call(this);
	var heroGraphics = self.attachAsset('hero', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self._move_migrated = function () {
		if (self.targetPos) {
			var dx = self.targetPos.x - self.x;
			var dy = self.targetPos.y - self.y;
			var distance = Math.sqrt(dx * dx + dy * dy);
			if (distance > 5) {
				self.x += dx / distance * 10;
				self.y += dy / distance * 10;
			} else {
				self.x = self.targetPos.x;
				self.y = self.targetPos.y;
				self.targetPos = null;
			}
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
game.setBackgroundColor(0x008000);
var hero = game.addChild(new Hero());
hero.enemies = [];
var heroBullets = [];
var enemyBullets = [];
hero.x = 2048 / 2;
hero.y = 2732 / 2;
game.targetPos = null;
game.on('down', function (x, y, obj) {
	hero.targetPos = game.toLocal(obj.global);
});
var spawnEnemy = function spawnEnemy() {
	var side = Math.floor(Math.random() * 4);
	var enemy = new Enemy(hero);
	switch (side) {
		case 0:
			enemy.x = Math.random() * 2048;
			enemy.y = 0;
			break;
		case 1:
			enemy.x = 2048;
			enemy.y = Math.random() * 2732;
			break;
		case 2:
			enemy.x = Math.random() * 2048;
			enemy.y = 2732;
			break;
		case 3:
			enemy.x = 0;
			enemy.y = Math.random() * 2732;
			break;
	}
	hero.enemies.push(enemy);
	game.addChild(enemy);
};
LK.on('tick', function () {
	hero._move_migrated();
	for (var i = 0; i < heroBullets.length; i++) {
		heroBullets[i]._move_migrated();
	}
	for (var i = 0; i < enemyBullets.length; i++) {
		enemyBullets[i]._move_migrated();
	}
	for (var i = 0; i < hero.enemies.length; i++) {
		hero.enemies[i]._move_migrated();
		for (var j = 0; j < heroBullets.length; j++) {
			if (heroBullets[j].intersects(hero.enemies[i])) {
				heroBullets[j].destroy();
				heroBullets.splice(j, 1);
				hero.enemies[i].destroy();
				hero.enemies.splice(i, 1);
				i--;
				j--;
			}
		}
		if (hero.intersects(hero.enemies[i])) {
			LK.showGameOver();
		}
	}
	if (LK.ticks % 30 === 0) {
		spawnEnemy();
	}
	if (LK.ticks % 20 === 0 && hero.targetPos) {
		var bullet = new Bullet();
		bullet.x = hero.x;
		bullet.y = hero.y;
		var dx = hero.targetPos.x - hero.x;
		var dy = hero.targetPos.y - hero.y;
		bullet.angle = Math.atan2(dy, dx);
		heroBullets.push(bullet);
		game.addChild(bullet);
	}
});
:quality(85)/https://cdn.frvr.ai/6554ca91a6947d02ef365c05.png%3F3) 
 vampire hunter pixel art Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/6554ce5aa6947d02ef365c41.png%3F3) 
 pixel art vampire, single sprite Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/6554d6a8a6947d02ef365c9b.png%3F3) 
 pixel art boomerang Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.