var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5);
self.speed = 20;
self.move = 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.createAsset('enemy', 'Enemy character', .5, .5);
self.move = 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.createAsset('hero', 'Hero character', .5, .5);
self.move = 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;
}
}
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
LK.stageContainer.setBackgroundColor(0x008000);
var hero = self.addChild(new Hero());
hero.enemies = [];
var heroBullets = [];
var enemyBullets = [];
hero.x = 2048 / 2;
hero.y = 2732 / 2;
self.targetPos = null;
stage.on('down', function (obj) {
hero.targetPos = obj.event.getLocalPosition(self);
});
var spawnEnemy = function () {
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);
self.addChild(enemy);
};
LK.on('tick', function () {
hero.move();
for (var i = 0; i < heroBullets.length; i++) {
heroBullets[i].move();
}
for (var i = 0; i < enemyBullets.length; i++) {
enemyBullets[i].move();
}
for (var i = 0; i < hero.enemies.length; i++) {
hero.enemies[i].move();
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);
self.addChild(bullet);
}
});
});
pixel art cross with blue accents Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a white orb. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a white orb with a halo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a pulsating white heart with a halo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a dark goo projectile with red highlights. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art tall blue fireball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of an evil fantasy sword facing downward. Minor red details. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
backgroundAmbient
Sound effect
heroHealed
Sound effect
pickupExperience
Sound effect
heroLeveled
Sound effect
weaponCrossImpact
Sound effect
heroImpact
Sound effect
enemyDeath
Sound effect
pickupWeapon
Sound effect
pickupCrucifix
Sound effect
weaponCrossLaunch
Sound effect
heroDeath
Sound effect
enemyRoar
Sound effect
clockChime
Sound effect