/****
* Classes
****/
// Bomb class
var Bomb = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
// Bomb update logic
};
});
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -15;
self.update = function () {
self.y += self.speed;
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
});
//<Assets used in the game will automatically appear here>
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Hero update logic
};
});
// RobotDog class
var RobotDog = Container.expand(function () {
var self = Container.call(this);
var robotDogGraphics = self.attachAsset('robotDog', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.direction = 1;
self.update = function () {
self.y += self.speed;
self.x += self.direction * 5;
if (self.x > 2048 - 75 || self.x < 75) {
self.direction *= -1;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize hero
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 200;
// Initialize arrays for bullets and enemies
var bullets = [];
var enemies = [];
var robotDogs = [];
// Initialize bomb and hit streak counter
var bomb = null;
var hitStreak = 0;
// Score display
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle move events
function handleMove(x, y, obj) {
hero.x = x;
hero.y = y;
}
game.move = handleMove;
// Handle shooting
game.down = function (x, y, obj) {
var newBullet = new Bullet();
newBullet.x = hero.x;
newBullet.y = hero.y;
bullets.push(newBullet);
game.addChild(newBullet);
};
// Update game state
game.update = function () {
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
if (bullets[i].y < -50) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (enemies[j].y > 2732 + 50) {
enemies[j].destroy();
enemies.splice(j, 1);
LK.setScore(LK.getScore() - 5);
scoreTxt.setText(LK.getScore());
if (LK.getScore() >= 150) {
LK.showGameOver();
} else if (LK.getScore() <= -500) {
LK.showGameOver();
}
}
}
// Update robotDogs
for (var m = robotDogs.length - 1; m >= 0; m--) {
robotDogs[m].update();
if (robotDogs[m].y > 2732 + 50) {
robotDogs[m].destroy();
robotDogs.splice(m, 1);
LK.setScore(LK.getScore() - 5);
scoreTxt.setText(LK.getScore());
}
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = enemies.length - 1; l >= 0; l--) {
if (bullets[k].intersects(enemies[l])) {
bullets[k].destroy();
enemies[l].destroy();
bullets.splice(k, 1);
enemies.splice(l, 1);
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
hitStreak++;
if (hitStreak == 5) {
bomb = new Bomb();
game.addChild(bomb);
}
break;
}
}
for (var n = robotDogs.length - 1; n >= 0; n--) {
if (bullets[k] && bullets[k].intersects(robotDogs[n])) {
bullets[k].destroy();
robotDogs[n].destroy();
bullets.splice(k, 1);
robotDogs.splice(n, 1);
LK.setScore(LK.getScore() + 2);
scoreTxt.setText(LK.getScore());
break;
}
}
}
// Clear the board when bomb is triggered
if (bomb) {
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].destroy();
enemies.splice(i, 1);
}
for (var i = robotDogs.length - 1; i >= 0; i--) {
robotDogs[i].destroy();
robotDogs.splice(i, 1);
}
bomb.destroy();
bomb = null;
hitStreak = 0;
}
// Spawn enemies
if (LK.ticks % 60 == 0) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * 2048;
newEnemy.y = -50;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
// Spawn robotDogs
if (LK.ticks % 120 == 0) {
var newRobotDog = new RobotDog();
newRobotDog.x = Math.random() * 2048;
newRobotDog.y = -50;
robotDogs.push(newRobotDog);
game.addChild(newRobotDog);
}
};
Large Bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Humanoid robots. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Badass marine with a green muscle T-shirt and a red bandana and a big cigar hanging from his mouth. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Rabid Robot Dog. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.