/****
* Classes
****/
// Define the Space Ranger class
var SpaceRanger = Container.expand(function () {
var self = Container.call(this);
var rangerGraphics = self.createAsset('spaceRanger', 'Space Ranger', 0.5, 0.5);
self.speed = 5;
self.moveLeft = function () {
self.x = Math.max(self.width / 2, self.x - self.speed);
};
self.moveRight = function () {
self.x = Math.min(2048 - self.width / 2, self.x + self.speed);
};
self.moveUp = function () {
self.y = Math.max(self.height / 2, self.y - self.speed);
};
self.moveDown = function () {
self.y = Math.min(2732 - self.height / 2, self.y + self.speed);
};
});
// Define the Meteor class
var Meteor = Container.expand(function () {
var self = Container.call(this);
var meteorGraphics = self.createAsset('meteor', 'Meteor', 0.5, 0.5);
self.speed = 3;
self.move = function () {
self.y += self.speed;
};
});
// Define the Alien class
var Alien = Container.expand(function () {
var self = Container.call(this);
var alienGraphics = self.createAsset('alien', 'Alien', 0.5, 0.5);
self.speed = 2;
self.move = function () {
self.y += self.speed;
};
});
// Define the HeroBullet class
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('heroBullet', 'Hero Bullet', 0.5, 0.5);
self.speed = -10;
self.move = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize important asset arrays
var meteors = [];
var aliens = [];
var heroBullets = [];
// Create the Space Ranger
var spaceRanger = game.addChild(new SpaceRanger());
spaceRanger.x = 2048 / 2;
spaceRanger.y = 2732 - 200; // Start position near the bottom of the screen
// Touch event handling
function handleTouchMove(obj) {
var touchPos = obj.event.getLocalPosition(game);
spaceRanger.x = touchPos.x;
spaceRanger.y = touchPos.y;
}
game.on('move', handleTouchMove);
// Game tick event
LK.on('tick', function () {
// Move all meteors
for (var i = meteors.length - 1; i >= 0; i--) {
meteors[i].move();
if (meteors[i].y > 2732 + meteors[i].height / 2) {
meteors[i].destroy();
meteors.splice(i, 1);
}
}
// Move all aliens
for (var j = aliens.length - 1; j >= 0; j--) {
aliens[j].move();
if (aliens[j].y > 2732 + aliens[j].height / 2) {
aliens[j].destroy();
aliens.splice(j, 1);
}
}
// Move all hero bullets
for (var k = heroBullets.length - 1; k >= 0; k--) {
heroBullets[k].move();
if (heroBullets[k].y < -heroBullets[k].height / 2) {
heroBullets[k].destroy();
heroBullets.splice(k, 1);
}
}
// Collision detection between hero bullets and aliens
for (var l = heroBullets.length - 1; l >= 0; l--) {
for (var m = aliens.length - 1; m >= 0; m--) {
if (heroBullets[l].intersects(aliens[m])) {
heroBullets[l].destroy();
heroBullets.splice(l, 1);
aliens[m].destroy();
aliens.splice(m, 1);
break;
}
}
}
// Collision detection between space ranger and meteors/aliens
for (var n = 0; n < meteors.length; n++) {
if (spaceRanger.intersects(meteors[n])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
for (var o = 0; o < aliens.length; o++) {
if (spaceRanger.intersects(aliens[o])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
// Spawn meteors and aliens
if (LK.ticks % 120 == 0) {
var newMeteor = new Meteor();
newMeteor.x = Math.random() * 2048;
newMeteor.y = -newMeteor.height / 2;
meteors.push(newMeteor);
game.addChild(newMeteor);
}
if (LK.ticks % 240 == 0) {
var newAlien = new Alien();
newAlien.x = Math.random() * 2048;
newAlien.y = -newAlien.height / 2;
aliens.push(newAlien);
game.addChild(newAlien);
}
// Fire hero bullets
if (LK.ticks % 30 == 0) {
var newHeroBullet = new HeroBullet();
newHeroBullet.x = spaceRanger.x;
newHeroBullet.y = spaceRanger.y - spaceRanger.height / 2;
heroBullets.push(newHeroBullet);
game.addChild(newHeroBullet);
}
});
military spaceship flies upward. 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.
ракета, снаряд летит вверх. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
energy ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
alien ship, flying saucer. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
alien spaceship heading down. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
alien spaceship heading down. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
alien spaceship heading down. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
alien spaceship heading down. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
сердце. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
lightning. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.