/****
* Classes
****/
// 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;
};
});
// IronMeteorite class
var IronMeteorite = Container.expand(function () {
var self = Container.call(this);
var ironMeteoriteGraphics = self.attachAsset('iron_meteorite', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = score >= 100 ? 3 : 1.5 + Math.floor(score / 50) * 0.075;
self.health = 2; // Add health property
self.update = function () {
self.y += self.speed;
};
});
// Meteorite class
var Meteorite = Container.expand(function () {
var self = Container.call(this);
var meteoriteGraphics = self.attachAsset('meteorite', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = score >= 100 ? 3 : 1.5 + Math.floor(score / 50) * 0.075;
self.health = 1; // Add health property
self.update = function () {
self.y += self.speed;
};
});
//<Assets used in the game will automatically appear here>
// Spaceship class
var Spaceship = Container.expand(function () {
var self = Container.call(this);
var spaceshipGraphics = self.attachAsset('spaceship', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Spaceship update logic
self.y = 2732 - 200; // Fix y position to the bottom layer
};
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - spaceshipGraphics.height / 2;
bullets.push(bullet);
game.addChild(bullet);
};
});
// StonyIronMeteorite class
var StonyIronMeteorite = Container.expand(function () {
var self = Container.call(this);
var stonyIronMeteoriteGraphics = self.attachAsset('stony_iron_meteorite', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = score >= 100 ? 3 : 1.5 + Math.floor(score / 50) * 0.075;
self.health = 3; // Add health property
self.update = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = game.attachAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
});
game.addChild(background);
var spaceship;
var bullets = [];
var bricks = [];
var score = 0;
var lives = 3; // Initialize lives to 3
var scoreTxt;
var livesTxt;
function initializeGame() {
spaceship = game.addChild(new Spaceship());
spaceship.x = 2048 / 2;
spaceship.y = 2732 - 200; // Initialize y position to the bottom layer
bullets = [];
bricks = [];
score = 0;
scoreTxt = new Text2('0', {
size: 60,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
livesTxt = new Text2('Lives: 3', {
size: 60,
fill: "#ffffff"
});
livesTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(livesTxt);
}
initializeGame();
game.down = function (x, y, obj) {
spaceship.x = x;
spaceship.y = 2732 - 200; // Fix y position to the bottom layer
spaceship.shoot();
function handleMove(x, y, obj) {
// Placeholder for move handling logic
}
handleMove(x, y, obj); // Ensure move handling is called
};
game.update = function () {
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
if (bullets[i].destroyed || bullets[i].y < -bullets[i].height) {
game.removeChild(bullets[i]);
bullets.splice(i, 1);
}
}
for (var j = bricks.length - 1; j >= 0; j--) {
bricks[j].update();
if (bricks[j].destroyed || bricks[j].y > 2732 + bricks[j].height) {
game.removeChild(bricks[j]);
bricks.splice(j, 1);
}
}
if (LK.ticks % 60 == 0) {
var meteorite;
var meteoriteType = Math.floor(Math.random() * 3);
if (score >= 40 && meteoriteType == 2) {
meteorite = new StonyIronMeteorite();
} else if (score >= 20 && meteoriteType >= 1) {
meteorite = new IronMeteorite();
} else {
meteorite = new Meteorite();
}
meteorite.x = Math.random() * 2048;
meteorite.y = -50;
bricks.push(meteorite);
game.addChild(meteorite);
}
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = bricks.length - 1; l >= 0; l--) {
if (bullets[k] && bricks[l] && bullets[k].intersects(bricks[l])) {
bullets[k].destroy();
game.removeChild(bullets[k]);
bullets.splice(k, 1);
bricks[l].health -= 1; // Decrease health
if (bricks[l].health <= 0) {
bricks[l].destroy();
game.removeChild(bricks[l]);
bricks.splice(l, 1);
score++;
scoreTxt.setText(score);
}
break;
}
}
}
for (var m = bricks.length - 1; m >= 0; m--) {
if (bricks[m] && bricks[m].intersects(spaceship)) {
bricks[m].destroy();
game.removeChild(bricks[m]);
bricks.splice(m, 1);
lives -= 1; // Decrease the number of lives
livesTxt.setText('Lives: ' + lives); // Update the lives text
if (lives <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}
// handleMove call removed as it is redundant
};
spaceship facing upwards. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
laser being fired upwards. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
meteorite. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Iron Meteorite which is slightly shining. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.