/**** * Classes ****/ // Alien class representing enemy characters var Alien = Container.expand(function () { var self = Container.call(this); var alienGraphics = self.attachAsset('alien', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { // Update logic for alien // Calculate the direction vector between the alien and the player var dx = hero.x - self.x; var dy = hero.y - self.y; var magnitude = Math.sqrt(dx * dx + dy * dy); // Normalize the direction vector dx /= magnitude; dy /= magnitude; // Move the alien towards the player var newX = self.x + dx * self.speed; var newY = self.y + dy * self.speed; // Check if the alien would intersect the wall if (!self.intersects(wall)) { self.x = newX; self.y = newY; } }; }); // Barrier class representing the barrier in front of the command base var Barrier = Container.expand(function () { var self = Container.call(this); var barrierGraphics = self.attachAsset('barrier', { anchorX: 0.5, anchorY: 0.5 }); self.health = 20; // Initialize the barrier with 20 health }); // Bullet class for projectiles 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; }; }); // CommandBase class representing the target to destroy var CommandBase = Container.expand(function () { var self = Container.call(this); var baseGraphics = self.attachAsset('commandBase', { anchorX: 0.5, anchorY: 0.5 }); }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Hero class representing the player character var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Update logic for hero }; }); // Wall class representing a barrier that blocks aliens but allows bullets var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('barrier', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize game elements var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0 })); var hero = game.addChild(new Hero()); hero.x = 1024; hero.y = 2400; var commandBase = game.addChild(new CommandBase()); commandBase.x = 1024; commandBase.y = 200; // Initialize the barrier and position it in front of the command base var barrier = game.addChild(new Barrier()); barrier.x = 1024; barrier.y = 180; var wall = game.addChild(new Wall()); wall.x = 1024; wall.y = 1500; // Position the wall at a specific Y coordinate var aliens = []; var bullets = []; var commandBaseHits = 0; // New variable to keep track of the number of times the command base has been shot var playerHits = 0; // New variable to keep track of the number of times the player has been hit by aliens // Function to handle movement function handleMove(x, y, obj) { hero.x = x; hero.y = y; } // Function to handle shooting function shoot() { var bullet = new Bullet(); bullet.x = hero.x; bullet.y = hero.y; bullets.push(bullet); game.addChild(bullet); } // Function to spawn aliens function spawnAlien() { for (var i = 0; i < 3; i++) { // Spawn 3 aliens at a time var alien = new Alien(); alien.x = Math.random() * 2048; alien.y = 0; aliens.push(alien); game.addChild(alien); } } // Game update loop game.update = function () { // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; bullet.update(); if (bullet.y < 0) { bullet.destroy(); bullets.splice(i, 1); } } // Update aliens for (var j = aliens.length - 1; j >= 0; j--) { var alien = aliens[j]; alien.update(); if (alien.y > 2732) { alien.destroy(); aliens.splice(j, 1); } } // Check for collisions for (var k = bullets.length - 1; k >= 0; k--) { var bullet = bullets[k]; for (var l = aliens.length - 1; l >= 0; l--) { var alien = aliens[l]; if (bullet.intersects(alien)) { bullet.destroy(); alien.destroy(); bullets.splice(k, 1); aliens.splice(l, 1); break; } } // Check if bullet hits the barrier if (bullet.intersects(barrier)) { bullet.destroy(); bullets.splice(k, 1); barrier.health--; // Decrement the barrier's health if (barrier.health <= 0) { barrier.destroy(); // Destroy the barrier if its health reaches 0 } } else if (bullet.intersects(commandBase)) { bullet.destroy(); bullets.splice(k, 1); commandBaseHits++; // Increment the commandBaseHits variable } } // Check if player has been hit by an alien for (var m = aliens.length - 1; m >= 0; m--) { var alien = aliens[m]; if (alien.intersects(hero)) { alien.destroy(); aliens.splice(m, 1); playerHits++; // Increment the playerHits variable break; } } // Check if command base has been shot 25 times if (commandBaseHits >= 25) { LK.showGameOver(); } // Check if player has been hit by 3 aliens if (playerHits >= 3) { LK.showGameOver(); } }; // Event listeners game.move = handleMove; game.down = function (x, y, obj) { shoot(); }; // Spawn aliens at intervals LK.setInterval(spawnAlien, 2000);
/****
* Classes
****/
// Alien class representing enemy characters
var Alien = Container.expand(function () {
var self = Container.call(this);
var alienGraphics = self.attachAsset('alien', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
// Update logic for alien
// Calculate the direction vector between the alien and the player
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var magnitude = Math.sqrt(dx * dx + dy * dy);
// Normalize the direction vector
dx /= magnitude;
dy /= magnitude;
// Move the alien towards the player
var newX = self.x + dx * self.speed;
var newY = self.y + dy * self.speed;
// Check if the alien would intersect the wall
if (!self.intersects(wall)) {
self.x = newX;
self.y = newY;
}
};
});
// Barrier class representing the barrier in front of the command base
var Barrier = Container.expand(function () {
var self = Container.call(this);
var barrierGraphics = self.attachAsset('barrier', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 20; // Initialize the barrier with 20 health
});
// Bullet class for projectiles
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;
};
});
// CommandBase class representing the target to destroy
var CommandBase = Container.expand(function () {
var self = Container.call(this);
var baseGraphics = self.attachAsset('commandBase', {
anchorX: 0.5,
anchorY: 0.5
});
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Hero class representing the player character
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Update logic for hero
};
});
// Wall class representing a barrier that blocks aliens but allows bullets
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('barrier', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game elements
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
var hero = game.addChild(new Hero());
hero.x = 1024;
hero.y = 2400;
var commandBase = game.addChild(new CommandBase());
commandBase.x = 1024;
commandBase.y = 200;
// Initialize the barrier and position it in front of the command base
var barrier = game.addChild(new Barrier());
barrier.x = 1024;
barrier.y = 180;
var wall = game.addChild(new Wall());
wall.x = 1024;
wall.y = 1500; // Position the wall at a specific Y coordinate
var aliens = [];
var bullets = [];
var commandBaseHits = 0; // New variable to keep track of the number of times the command base has been shot
var playerHits = 0; // New variable to keep track of the number of times the player has been hit by aliens
// Function to handle movement
function handleMove(x, y, obj) {
hero.x = x;
hero.y = y;
}
// Function to handle shooting
function shoot() {
var bullet = new Bullet();
bullet.x = hero.x;
bullet.y = hero.y;
bullets.push(bullet);
game.addChild(bullet);
}
// Function to spawn aliens
function spawnAlien() {
for (var i = 0; i < 3; i++) {
// Spawn 3 aliens at a time
var alien = new Alien();
alien.x = Math.random() * 2048;
alien.y = 0;
aliens.push(alien);
game.addChild(alien);
}
}
// Game update loop
game.update = function () {
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
bullet.update();
if (bullet.y < 0) {
bullet.destroy();
bullets.splice(i, 1);
}
}
// Update aliens
for (var j = aliens.length - 1; j >= 0; j--) {
var alien = aliens[j];
alien.update();
if (alien.y > 2732) {
alien.destroy();
aliens.splice(j, 1);
}
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
var bullet = bullets[k];
for (var l = aliens.length - 1; l >= 0; l--) {
var alien = aliens[l];
if (bullet.intersects(alien)) {
bullet.destroy();
alien.destroy();
bullets.splice(k, 1);
aliens.splice(l, 1);
break;
}
}
// Check if bullet hits the barrier
if (bullet.intersects(barrier)) {
bullet.destroy();
bullets.splice(k, 1);
barrier.health--; // Decrement the barrier's health
if (barrier.health <= 0) {
barrier.destroy(); // Destroy the barrier if its health reaches 0
}
} else if (bullet.intersects(commandBase)) {
bullet.destroy();
bullets.splice(k, 1);
commandBaseHits++; // Increment the commandBaseHits variable
}
}
// Check if player has been hit by an alien
for (var m = aliens.length - 1; m >= 0; m--) {
var alien = aliens[m];
if (alien.intersects(hero)) {
alien.destroy();
aliens.splice(m, 1);
playerHits++; // Increment the playerHits variable
break;
}
}
// Check if command base has been shot 25 times
if (commandBaseHits >= 25) {
LK.showGameOver();
}
// Check if player has been hit by 3 aliens
if (playerHits >= 3) {
LK.showGameOver();
}
};
// Event listeners
game.move = handleMove;
game.down = function (x, y, obj) {
shoot();
};
// Spawn aliens at intervals
LK.setInterval(spawnAlien, 2000);
a high tech alien command base. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a weaponazized alien. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a city that is wartorn and has many explosoins and brocken buildings. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows