/**** * Classes ****/ var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = LK.getAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(bulletGraphics); self.speed = 10; self.move = function () { self.y -= self.speed; }; }); var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = LK.getAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(bulletGraphics); self.speed = 5; self.move = function () { self.x += self.speedX; self.y += self.speedY; }; }); var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = LK.getAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(heroGraphics); }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = LK.getAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(enemyGraphics); self.speed = 6; self.targetY = Math.random() * (2732 / 3); self.move = function () { if (self.y < self.targetY) { self.y += self.speed; } self.x += Math.sin(LK.ticks / 30) * 5; if (self.x < 0) { self.x = 0; } if (self.x > 2048 - enemyGraphics.width) { self.x = 2048 - enemyGraphics.width; } }; }); var StarField = Container.expand(function () { var self = Container.call(this); var starGraphics = LK.getAsset('star', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(starGraphics); self.speed = Math.random() * 2 + 1; self.alpha = self.speed / 3; self.move = function () { self.y += self.speed; if (self.y > 2732) { self.y = -100; self.x = Math.random() * 2048; self.speed = Math.random() * 2 + 1; self.alpha = self.speed / 3; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var starField = []; for (var i = 0; i < 100; i++) { var star = new StarField(); star.x = Math.random() * 2048; star.y = Math.random() * 2732; starField.push(star); game.addChild(star); } var hero = game.addChild(new Hero()); hero.x = 1024; hero.y = 2400; var enemies = []; var heroBullets = []; var enemyBullets = []; var score = 0; var currentWave = 0; var allEnemiesKilled = true; var scoreText = new Text2('0', { size: 100, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma", fill: "#ffffff" }); scoreText.anchor.set(0.5, 0); LK.gui.topCenter.addChild(scoreText); function spawnWave() { for (var i = 0; i < currentWave + 3; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = -100 - i * 100; enemies.push(enemy); game.addChild(enemy); } allEnemiesKilled = false; } function fireHeroBullet() { var bullet = new HeroBullet(); bullet.x = hero.x; bullet.y = hero.y - 50; heroBullets.push(bullet); game.addChild(bullet); } function fireEnemyBullet(enemy) { var bullet = new EnemyBullet(); bullet.x = enemy.x; bullet.y = enemy.y + 50; var angle = Math.atan2(hero.y - bullet.y, hero.x - bullet.x); bullet.speedX = bullet.speed * Math.cos(angle); bullet.speedY = bullet.speed * Math.sin(angle); enemyBullets.push(bullet); game.addChild(bullet); } function updateGameObjects() { enemies.forEach(function (enemy, index) { enemy.move(); if (enemy.y > 2732) { enemy.destroy(); enemies.splice(index, 1); } }); heroBullets.forEach(function (bullet, index) { bullet.move(); if (bullet.y < 0) { bullet.destroy(); heroBullets.splice(index, 1); } }); enemyBullets.forEach(function (bullet, index) { bullet.move(); if (bullet.y > 2732) { bullet.destroy(); enemyBullets.splice(index, 1); } }); } function checkCollisions() { // Check collisions between hero bullets and enemies heroBullets.forEach(function (heroBullet, hIndex) { enemies.forEach(function (enemy, eIndex) { if (heroBullet.intersects(enemy)) { heroBullet.destroy(); heroBullets.splice(hIndex, 1); enemy.destroy(); enemies.splice(eIndex, 1); score += 100; LK.setScore(score); scoreText.setText(score); if (enemies.length === 0) { allEnemiesKilled = true; } } }); }); // Check collisions between enemy bullets and hero enemyBullets.forEach(function (enemyBullet, index) { if (enemyBullet.intersects(hero)) { enemyBullet.destroy(); enemyBullets.splice(index, 1); LK.showGameOver(); // Handle hero hit by enemy bullet } }); } var targetPosition = { x: hero.x, y: hero.y }; game.on('down', function (obj) { targetPosition = obj.event.getLocalPosition(game); }); game.on('move', function (obj) { targetPosition = obj.event.getLocalPosition(game); }); function moveHeroTowardsTarget() { var dx = targetPosition.x - hero.x; var dy = targetPosition.y - hero.y; var distance = Math.sqrt(dx * dx + dy * dy); var maxSpeed = 15; if (distance > maxSpeed) { var angle = Math.atan2(dy, dx); hero.x += maxSpeed * Math.cos(angle); hero.y += maxSpeed * Math.sin(angle); } else { hero.x = targetPosition.x; hero.y = targetPosition.y; } } function handleTick() { moveHeroTowardsTarget(); updateGameObjects(); checkCollisions(); starField.forEach(function (star) { star.move(); }); if (allEnemiesKilled) { currentWave++; spawnWave(); } if (LK.ticks % 30 === 0) { fireHeroBullet(); } enemies.forEach(function (enemy, index) { if (LK.ticks % 90 === 0) { fireEnemyBullet(enemy); } if (LK.ticks % 180 === 0 && index % 2 === 0) { fireEnemyBullet(enemy); } }); } LK.on('tick', handleTick);
/****
* Classes
****/
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = LK.getAsset('heroBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(bulletGraphics);
self.speed = 10;
self.move = function () {
self.y -= self.speed;
};
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = LK.getAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(bulletGraphics);
self.speed = 5;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
};
});
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = LK.getAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(heroGraphics);
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = LK.getAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(enemyGraphics);
self.speed = 6;
self.targetY = Math.random() * (2732 / 3);
self.move = function () {
if (self.y < self.targetY) {
self.y += self.speed;
}
self.x += Math.sin(LK.ticks / 30) * 5;
if (self.x < 0) {
self.x = 0;
}
if (self.x > 2048 - enemyGraphics.width) {
self.x = 2048 - enemyGraphics.width;
}
};
});
var StarField = Container.expand(function () {
var self = Container.call(this);
var starGraphics = LK.getAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(starGraphics);
self.speed = Math.random() * 2 + 1;
self.alpha = self.speed / 3;
self.move = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
self.speed = Math.random() * 2 + 1;
self.alpha = self.speed / 3;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var starField = [];
for (var i = 0; i < 100; i++) {
var star = new StarField();
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
starField.push(star);
game.addChild(star);
}
var hero = game.addChild(new Hero());
hero.x = 1024;
hero.y = 2400;
var enemies = [];
var heroBullets = [];
var enemyBullets = [];
var score = 0;
var currentWave = 0;
var allEnemiesKilled = true;
var scoreText = new Text2('0', {
size: 100,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
fill: "#ffffff"
});
scoreText.anchor.set(0.5, 0);
LK.gui.topCenter.addChild(scoreText);
function spawnWave() {
for (var i = 0; i < currentWave + 3; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -100 - i * 100;
enemies.push(enemy);
game.addChild(enemy);
}
allEnemiesKilled = false;
}
function fireHeroBullet() {
var bullet = new HeroBullet();
bullet.x = hero.x;
bullet.y = hero.y - 50;
heroBullets.push(bullet);
game.addChild(bullet);
}
function fireEnemyBullet(enemy) {
var bullet = new EnemyBullet();
bullet.x = enemy.x;
bullet.y = enemy.y + 50;
var angle = Math.atan2(hero.y - bullet.y, hero.x - bullet.x);
bullet.speedX = bullet.speed * Math.cos(angle);
bullet.speedY = bullet.speed * Math.sin(angle);
enemyBullets.push(bullet);
game.addChild(bullet);
}
function updateGameObjects() {
enemies.forEach(function (enemy, index) {
enemy.move();
if (enemy.y > 2732) {
enemy.destroy();
enemies.splice(index, 1);
}
});
heroBullets.forEach(function (bullet, index) {
bullet.move();
if (bullet.y < 0) {
bullet.destroy();
heroBullets.splice(index, 1);
}
});
enemyBullets.forEach(function (bullet, index) {
bullet.move();
if (bullet.y > 2732) {
bullet.destroy();
enemyBullets.splice(index, 1);
}
});
}
function checkCollisions() {
// Check collisions between hero bullets and enemies
heroBullets.forEach(function (heroBullet, hIndex) {
enemies.forEach(function (enemy, eIndex) {
if (heroBullet.intersects(enemy)) {
heroBullet.destroy();
heroBullets.splice(hIndex, 1);
enemy.destroy();
enemies.splice(eIndex, 1);
score += 100;
LK.setScore(score);
scoreText.setText(score);
if (enemies.length === 0) {
allEnemiesKilled = true;
}
}
});
});
// Check collisions between enemy bullets and hero
enemyBullets.forEach(function (enemyBullet, index) {
if (enemyBullet.intersects(hero)) {
enemyBullet.destroy();
enemyBullets.splice(index, 1);
LK.showGameOver();
// Handle hero hit by enemy bullet
}
});
}
var targetPosition = {
x: hero.x,
y: hero.y
};
game.on('down', function (obj) {
targetPosition = obj.event.getLocalPosition(game);
});
game.on('move', function (obj) {
targetPosition = obj.event.getLocalPosition(game);
});
function moveHeroTowardsTarget() {
var dx = targetPosition.x - hero.x;
var dy = targetPosition.y - hero.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var maxSpeed = 15;
if (distance > maxSpeed) {
var angle = Math.atan2(dy, dx);
hero.x += maxSpeed * Math.cos(angle);
hero.y += maxSpeed * Math.sin(angle);
} else {
hero.x = targetPosition.x;
hero.y = targetPosition.y;
}
}
function handleTick() {
moveHeroTowardsTarget();
updateGameObjects();
checkCollisions();
starField.forEach(function (star) {
star.move();
});
if (allEnemiesKilled) {
currentWave++;
spawnWave();
}
if (LK.ticks % 30 === 0) {
fireHeroBullet();
}
enemies.forEach(function (enemy, index) {
if (LK.ticks % 90 === 0) {
fireEnemyBullet(enemy);
}
if (LK.ticks % 180 === 0 && index % 2 === 0) {
fireEnemyBullet(enemy);
}
});
}
LK.on('tick', handleTick);
Single space torpedo flying upwards Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Single enemy slime bullet flying downwards. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
single alien enemy spaceship facing down, looking like space alien adopted to living in space. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Hero spaceship facing upwards, with a single cannon in the center. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.