/****
* Classes
****/
var Bonus = Container.expand(function () {
var self = Container.call(this);
var bonusGraphics = self.attachAsset('bonus', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 5 + 2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
// Laser class
var Laser = Container.expand(function () {
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 5 + 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Player update logic if needed
};
});
// PowerUp class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 5 + 2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 5 + 1;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize arrays and variables
var lasers = [];
var powerUps = [];
var stars = [];
var bonuses = [];
var player = game.addChild(new Player());
var bonusActive = false;
player.x = 2048 / 2;
player.y = 2732 - 200;
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffff00",
// Yellow color
fontWeight: 'bold',
stroke: '#808080',
// Gray outline
strokeThickness: 12,
dropShadow: true,
dropShadowColor: '#000000',
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle player movement
var dragNode = null;
// Define the handleMove function
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
}
game.down = function (x, y, obj) {
dragNode = player;
handleMove(x, y, obj);
};
game.move = handleMove;
game.up = function (x, y, obj) {
dragNode = null;
};
// Update game state
game.update = function () {
// Update lasers
for (var i = lasers.length - 1; i >= 0; i--) {
lasers[i].update();
if (lasers[i].intersects(player)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update stars
for (var k = stars.length - 1; k >= 0; k--) {
stars[k].update();
if (stars[k].intersects(player)) {
// Handle star collection if needed
}
}
if (LK.ticks % 20 == 0) {
var newStar = new Star();
newStar.x = Math.random() * 2048;
newStar.y = -50;
stars.push(newStar);
game.addChild(newStar);
}
for (var b = bonuses.length - 1; b >= 0; b--) {
bonuses[b].update();
if (bonuses[b].intersects(player)) {
// Handle bonus collection
bonuses[b].destroy();
bonuses.splice(b, 1);
// Slow down lasers
bonusActive = true;
for (var i = 0; i < lasers.length; i++) {
lasers[i].speed = 1;
}
// Restore laser speed after 10 seconds
LK.setTimeout(function () {
for (var i = 0; i < lasers.length; i++) {
lasers[i].speed = Math.random() * 5 + 3;
}
bonusActive = false;
for (var i = 0; i < lasers.length; i++) {
lasers[i].speed = Math.random() * 5 + 3;
}
}, 10000);
// Reset laser spawn frequency
LK.setTimeout(function () {
bonusActive = false;
}, 10000);
}
}
if (LK.ticks > 1000 && LK.ticks % 2000 == 0) {
var newBonus = new Bonus();
newBonus.x = Math.random() * 2048;
newBonus.y = -50;
bonuses.push(newBonus);
game.addChild(newBonus);
}
for (var j = powerUps.length - 1; j >= 0; j--) {
powerUps[j].update();
if (powerUps[j].intersects(player)) {
score += 10;
scoreTxt.setText(score);
powerUps[j].destroy();
powerUps.splice(j, 1);
LK.getSound('powerUpSound').play();
}
}
// Spawn lasers
if (LK.ticks % (bonusActive ? 60 : 30) == 0) {
var newLaser = new Laser();
newLaser.x = Math.random() * 2048;
newLaser.y = -50;
if (bonusActive) {
newLaser.speed = 1;
}
lasers.push(newLaser);
game.addChild(newLaser);
LK.getSound('laserSound').play();
}
// Spawn power-ups
if (LK.ticks % 300 == 0) {
var newPowerUp = new PowerUp();
newPowerUp.x = Math.random() * 2048;
newPowerUp.y = -50;
powerUps.push(newPowerUp);
game.addChild(newPowerUp);
}
};
монета.. 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.
шар с надписью bonus.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.