/****
* Classes
****/
var Bullet = Container.expand(function (x, y) {
var self = Container.call(this);
self.speed = -15;
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.update = function () {
self.y += self.speed;
if (self.y < 0) {
self.destroy();
}
};
return self;
});
//<Write entity 'classes' with empty functions for important behavior here>
var Hero = Container.expand(function () {
var self = Container.call(this);
self.speed = 10;
self.health = 100;
self.shootCooldown = 0;
self.update = function () {
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
};
self.shoot = function () {
if (self.shootCooldown === 0) {
var bullet = new Bullet(self.x, self.y - 50);
game.addChild(bullet);
bullets.push(bullet);
self.shootCooldown = 30; // Cooldown period
}
};
return self;
});
var Galaktion = Hero.expand(function () {
var self = Hero.call(this);
var galaktionGraphics = self.attachAsset('galaktion', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Adrian = Hero.expand(function () {
var self = Hero.call(this);
var adrianGraphics = self.attachAsset('adrian', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Scythian = Container.expand(function () {
var self = Container.call(this);
self.speed = 5;
var scythianGraphics = self.attachAsset('scythian', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
//<Write game logic code here, including initializing arrays and variables>
//<Assets used in the game will automatically appear here>
var galaktion = game.addChild(new Galaktion());
galaktion.x = 1024;
galaktion.y = 2400;
var adrian = game.addChild(new Adrian());
adrian.x = 1024;
adrian.y = 2600;
var scythians = [];
var bullets = [];
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.down = function (x, y, obj) {
if (y < 1366) {
galaktion.shoot();
} else {
adrian.shoot();
}
};
game.update = function () {
galaktion.update();
adrian.update();
for (var i = scythians.length - 1; i >= 0; i--) {
scythians[i].update();
if (scythians[i].intersects(galaktion) || scythians[i].intersects(adrian)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
for (var k = scythians.length - 1; k >= 0; k--) {
if (bullets[j].intersects(scythians[k])) {
scythians[k].destroy();
bullets[j].destroy();
scythians.splice(k, 1);
bullets.splice(j, 1);
score++;
scoreTxt.setText('Score: ' + score);
break;
}
}
}
if (LK.ticks % 60 == 0) {
var scythian = new Scythian();
scythian.x = Math.random() * 2048;
scythian.y = -100;
game.addChild(scythian);
scythians.push(scythian);
}
};