/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Define the 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; }; }); // Define the Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemyShipSmall', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.hp = 200; self.damage = 1; self.update = function () { self.y += self.speed; }; }); // Define the LargeEnemy class var LargeEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemyShipLarge', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1; self.hp = 600; self.damage = 4; self.update = function () { self.y += self.speed; }; }); // Define the MediumEnemy class var MediumEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemyShipMedium', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.hp = 400; self.damage = 2; self.update = function () { self.y += self.speed; }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Define the Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('playerShip', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Player update logic can be added here }; }); // Define the SmallEnemy class var SmallEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemyShipSmall', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.hp = 100; self.update = function () { self.y += self.speed; }; }); // Define the StarBackground class var StarBackground = Container.expand(function () { var self = Container.call(this); var starBackgroundGraphics = self.attachAsset('starBackground', { anchorX: 0.5, anchorY: 0 }); self.speed = .5; self.update = function () { self.y += self.speed; if (self.y >= 2732) { self.y = -2732; } }; }); // Define the ScoreChange class var ScoreChange = Text2.expand(function (fillValue) { var self = Text2.call(this, '', { size: 100, fill: fillValue }); self.anchor.set(0.5, 0); self.alpha = 1; self.update = function () { if (self.alpha > 0) { self.alpha -= 0.01; self.y += 1; } else { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x030303 //Init game with black background }); /**** * Game Code ****/ //<Assets used in the game will automatically appear here> // Initialize score counter var score = 0; var scoreText = new Text2(score.toString(), { size: 100, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // Initialize player // Initialize star background var starBackground1 = game.addChild(new StarBackground()); starBackground1.x = 2048 / 2; starBackground1.y = 2732 / 2; var starBackground2 = game.addChild(new StarBackground()); starBackground2.x = 2048 / 2; starBackground2.y = -2732 / 2; var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 200; // Arrays to keep track of bullets and enemies var bullets = []; var enemies = []; // Handle player movement game.move = function (x, y, obj) { player.x = x; player.y = y; }; // Spawn enemies at intervals var enemySpawnInterval = LK.setInterval(function () { var enemyTypes = [Enemy, Enemy, Enemy, Enemy, Enemy, Enemy, MediumEnemy, MediumEnemy, MediumEnemy, LargeEnemy]; var randomEnemy = enemyTypes[Math.floor(Math.random() * enemyTypes.length)]; var enemy = new randomEnemy(); enemy.x = Math.random() * 2048; enemy.y = -50; enemies.push(enemy); game.addChild(enemy); }, Math.floor(Math.random() * 2000) + 500); // Fire bullets at intervals var bulletFireInterval = LK.setInterval(function () { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; bullets.push(bullet); game.addChild(bullet); }, 300); // Update game state game.update = function () { // Update star backgrounds starBackground1.update(); starBackground2.update(); // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; bullet.update(); if (bullet.y < -50) { bullet.destroy(); bullets.splice(i, 1); } } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { var enemy = enemies[j]; enemy.update(); if (enemy.y > 2732 + 50) { var oldScore = score; score -= enemy.damage; // Reduce score by enemy's damage scoreText.setText(score.toString()); // Update score text var scoreChange = new ScoreChange(score - oldScore > 0 ? 0x00FF00 : 0xFF0000); scoreChange.setText((score - oldScore).toString()); scoreChange.x = 1024; scoreChange.y = scoreText.y + scoreText.height + 30; game.addChild(scoreChange); if (score < 1) { LK.showGameOver(); } enemy.destroy(); enemies.splice(j, 1); } } // Check for collisions for (var k = bullets.length - 1; k >= 0; k--) { var bullet = bullets[k]; for (var l = enemies.length - 1; l >= 0; l--) { var enemy = enemies[l]; if (bullet.intersects(enemy)) { bullet.destroy(); bullets.splice(k, 1); // Add sparkles animation at the point of intersection var sparkles = LK.getAsset('sparkles', { anchorX: 0.5, anchorY: 0.5, x: enemy.x, y: enemy.y }); game.addChild(sparkles); tween(sparkles, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { sparkles.destroy(); } }); enemy.hp -= 100; // Reduce enemy HP by 40 if (enemy.hp <= 0) { // If enemy HP is 0 or less, destroy it enemy.destroy(); enemies.splice(l, 1); // Increase score by enemy's damage and update score text var oldScore = score; score += enemy.damage; scoreText.setText(score.toString()); var scoreChange = new ScoreChange(score - oldScore > 0 ? 0x00FF00 : 0xFF0000); var plusSign = score - oldScore > 0 ? '+' : ''; scoreChange.setText(plusSign + (score - oldScore).toString()); scoreChange.x = 1024; scoreChange.y = scoreText.y + scoreText.height + 30; game.addChild(scoreChange); } break; } } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Define the 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;
};
});
// Define the Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyShipSmall', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.hp = 200;
self.damage = 1;
self.update = function () {
self.y += self.speed;
};
});
// Define the LargeEnemy class
var LargeEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyShipLarge', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1;
self.hp = 600;
self.damage = 4;
self.update = function () {
self.y += self.speed;
};
});
// Define the MediumEnemy class
var MediumEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyShipMedium', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.hp = 400;
self.damage = 2;
self.update = function () {
self.y += self.speed;
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define the Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('playerShip', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Player update logic can be added here
};
});
// Define the SmallEnemy class
var SmallEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyShipSmall', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.hp = 100;
self.update = function () {
self.y += self.speed;
};
});
// Define the StarBackground class
var StarBackground = Container.expand(function () {
var self = Container.call(this);
var starBackgroundGraphics = self.attachAsset('starBackground', {
anchorX: 0.5,
anchorY: 0
});
self.speed = .5;
self.update = function () {
self.y += self.speed;
if (self.y >= 2732) {
self.y = -2732;
}
};
});
// Define the ScoreChange class
var ScoreChange = Text2.expand(function (fillValue) {
var self = Text2.call(this, '', {
size: 100,
fill: fillValue
});
self.anchor.set(0.5, 0);
self.alpha = 1;
self.update = function () {
if (self.alpha > 0) {
self.alpha -= 0.01;
self.y += 1;
} else {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x030303 //Init game with black background
});
/****
* Game Code
****/
//<Assets used in the game will automatically appear here>
// Initialize score counter
var score = 0;
var scoreText = new Text2(score.toString(), {
size: 100,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Initialize player
// Initialize star background
var starBackground1 = game.addChild(new StarBackground());
starBackground1.x = 2048 / 2;
starBackground1.y = 2732 / 2;
var starBackground2 = game.addChild(new StarBackground());
starBackground2.x = 2048 / 2;
starBackground2.y = -2732 / 2;
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 200;
// Arrays to keep track of bullets and enemies
var bullets = [];
var enemies = [];
// Handle player movement
game.move = function (x, y, obj) {
player.x = x;
player.y = y;
};
// Spawn enemies at intervals
var enemySpawnInterval = LK.setInterval(function () {
var enemyTypes = [Enemy, Enemy, Enemy, Enemy, Enemy, Enemy, MediumEnemy, MediumEnemy, MediumEnemy, LargeEnemy];
var randomEnemy = enemyTypes[Math.floor(Math.random() * enemyTypes.length)];
var enemy = new randomEnemy();
enemy.x = Math.random() * 2048;
enemy.y = -50;
enemies.push(enemy);
game.addChild(enemy);
}, Math.floor(Math.random() * 2000) + 500);
// Fire bullets at intervals
var bulletFireInterval = LK.setInterval(function () {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullets.push(bullet);
game.addChild(bullet);
}, 300);
// Update game state
game.update = function () {
// Update star backgrounds
starBackground1.update();
starBackground2.update();
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
bullet.update();
if (bullet.y < -50) {
bullet.destroy();
bullets.splice(i, 1);
}
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
enemy.update();
if (enemy.y > 2732 + 50) {
var oldScore = score;
score -= enemy.damage; // Reduce score by enemy's damage
scoreText.setText(score.toString()); // Update score text
var scoreChange = new ScoreChange(score - oldScore > 0 ? 0x00FF00 : 0xFF0000);
scoreChange.setText((score - oldScore).toString());
scoreChange.x = 1024;
scoreChange.y = scoreText.y + scoreText.height + 30;
game.addChild(scoreChange);
if (score < 1) {
LK.showGameOver();
}
enemy.destroy();
enemies.splice(j, 1);
}
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
var bullet = bullets[k];
for (var l = enemies.length - 1; l >= 0; l--) {
var enemy = enemies[l];
if (bullet.intersects(enemy)) {
bullet.destroy();
bullets.splice(k, 1);
// Add sparkles animation at the point of intersection
var sparkles = LK.getAsset('sparkles', {
anchorX: 0.5,
anchorY: 0.5,
x: enemy.x,
y: enemy.y
});
game.addChild(sparkles);
tween(sparkles, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
sparkles.destroy();
}
});
enemy.hp -= 100; // Reduce enemy HP by 40
if (enemy.hp <= 0) {
// If enemy HP is 0 or less, destroy it
enemy.destroy();
enemies.splice(l, 1);
// Increase score by enemy's damage and update score text
var oldScore = score;
score += enemy.damage;
scoreText.setText(score.toString());
var scoreChange = new ScoreChange(score - oldScore > 0 ? 0x00FF00 : 0xFF0000);
var plusSign = score - oldScore > 0 ? '+' : '';
scoreChange.setText(plusSign + (score - oldScore).toString());
scoreChange.x = 1024;
scoreChange.y = scoreText.y + scoreText.height + 30;
game.addChild(scoreChange);
}
break;
}
}
}
};
alien space ship. top-down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a missile with the trail. the missile is pointing to the top, and the trail goes down. no background, top-down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
top-down view, spaceship in the shape of a fighter jet. pointed upwards. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
explosion VFX, transparent. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows