/**** * Classes ****/ // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.shoot = function () { var bullet = new HeroBullet(); bullet.x = self.x; bullet.y = self.y - self.height / 2; game.addChild(bullet); heroBullets.push(bullet); }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.move = function () { self.y += 2; if (self.y > 2732 + self.height) { self.destroy(); enemies.splice(enemies.indexOf(self), 1); } }; self.shoot = function () { var bullet = new EnemyBullet(); bullet.x = self.x; bullet.y = self.y + self.height / 2; game.addChild(bullet); enemyBullets.push(bullet); }; }); // HeroBullet class var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.move = function () { self.y -= 10; if (self.y < -self.height) { self.destroy(); heroBullets.splice(heroBullets.indexOf(self), 1); } }; }); // EnemyBullet class var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.move = function () { self.y += 5; if (self.y > 2732 + self.height) { self.destroy(); enemyBullets.splice(enemyBullets.indexOf(self), 1); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize hero // Define the assets for the hero, enemy robots, and bullets var hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 100; // Initialize enemy and bullet arrays var enemies = []; var heroBullets = []; var enemyBullets = []; // Handle shooting game.on('down', function (obj) { hero.shoot(); }); // Game tick event LK.on('tick', function () { // Move hero bullets for (var i = heroBullets.length - 1; i >= 0; i--) { heroBullets[i].move(); } // Move enemy bullets for (var j = enemyBullets.length - 1; j >= 0; j--) { enemyBullets[j].move(); } // Move enemies and randomly shoot for (var k = enemies.length - 1; k >= 0; k--) { enemies[k].move(); if (Math.random() < 0.01) { enemies[k].shoot(); } } // Spawn enemies if (LK.ticks % 120 == 0) { var enemy = new Enemy(); enemy.x = Math.random() * (2048 - enemy.width) + enemy.width / 2; enemy.y = -enemy.height; game.addChild(enemy); enemies.push(enemy); } // Check for collisions between hero bullets and enemies for (var h = heroBullets.length - 1; h >= 0; h--) { for (var e = enemies.length - 1; e >= 0; e--) { if (heroBullets[h].intersects(enemies[e])) { heroBullets[h].destroy(); heroBullets.splice(h, 1); enemies[e].destroy(); enemies.splice(e, 1); break; } } } // Check for collisions between enemy bullets and hero for (var eb = enemyBullets.length - 1; eb >= 0; eb--) { if (enemyBullets[eb].intersects(hero)) { // Flash screen red for 1 second (1000ms) to show damage taken LK.effects.flashScreen(0xff0000, 1000); // Show game over LK.showGameOver(); break; } } });
/****
* Classes
****/
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function () {
var bullet = new HeroBullet();
bullet.x = self.x;
bullet.y = self.y - self.height / 2;
game.addChild(bullet);
heroBullets.push(bullet);
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
self.y += 2;
if (self.y > 2732 + self.height) {
self.destroy();
enemies.splice(enemies.indexOf(self), 1);
}
};
self.shoot = function () {
var bullet = new EnemyBullet();
bullet.x = self.x;
bullet.y = self.y + self.height / 2;
game.addChild(bullet);
enemyBullets.push(bullet);
};
});
// HeroBullet class
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('heroBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
self.y -= 10;
if (self.y < -self.height) {
self.destroy();
heroBullets.splice(heroBullets.indexOf(self), 1);
}
};
});
// EnemyBullet class
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function () {
self.y += 5;
if (self.y > 2732 + self.height) {
self.destroy();
enemyBullets.splice(enemyBullets.indexOf(self), 1);
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize hero
// Define the assets for the hero, enemy robots, and bullets
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 100;
// Initialize enemy and bullet arrays
var enemies = [];
var heroBullets = [];
var enemyBullets = [];
// Handle shooting
game.on('down', function (obj) {
hero.shoot();
});
// Game tick event
LK.on('tick', function () {
// Move hero bullets
for (var i = heroBullets.length - 1; i >= 0; i--) {
heroBullets[i].move();
}
// Move enemy bullets
for (var j = enemyBullets.length - 1; j >= 0; j--) {
enemyBullets[j].move();
}
// Move enemies and randomly shoot
for (var k = enemies.length - 1; k >= 0; k--) {
enemies[k].move();
if (Math.random() < 0.01) {
enemies[k].shoot();
}
}
// Spawn enemies
if (LK.ticks % 120 == 0) {
var enemy = new Enemy();
enemy.x = Math.random() * (2048 - enemy.width) + enemy.width / 2;
enemy.y = -enemy.height;
game.addChild(enemy);
enemies.push(enemy);
}
// Check for collisions between hero bullets and enemies
for (var h = heroBullets.length - 1; h >= 0; h--) {
for (var e = enemies.length - 1; e >= 0; e--) {
if (heroBullets[h].intersects(enemies[e])) {
heroBullets[h].destroy();
heroBullets.splice(h, 1);
enemies[e].destroy();
enemies.splice(e, 1);
break;
}
}
}
// Check for collisions between enemy bullets and hero
for (var eb = enemyBullets.length - 1; eb >= 0; eb--) {
if (enemyBullets[eb].intersects(hero)) {
// Flash screen red for 1 second (1000ms) to show damage taken
LK.effects.flashScreen(0xff0000, 1000);
// Show game over
LK.showGameOver();
break;
}
}
});
Blue,laser like. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Golden badge shaped. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Red ufo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Big version of enemy and only dies after shot four times rest of features are from original enemies. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Red bullet facing towards the bottom of the game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Like a big animated explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Looks exactly like a realistic rocket. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Imagined cosmic planet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A golden glowing ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.