/**** * Classes ****/ // BigTarget class for larger targets that require multiple hits var BigTarget = Container.expand(function () { var self = Container.call(this); var targetGraphics = self.attachAsset('bigTarget', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1; // Slower speed for big targets self.hitPoints = 5; // Number of hits required to destroy self.update = function () { self.y += self.speed; if (self.y > 2732 + 50) { self.destroy(); } }; self.hit = function () { self.hitPoints--; if (self.hitPoints <= 0) { self.destroy(); return true; // Return true if destroyed } return false; // Return false if not yet destroyed }; }); // Assets will be automatically initialized by the LK engine based on their usage in the code. // Bullet class for the player's shots var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; // Speed of the bullet self.update = function () { self.y += self.speed; if (self.y < -50) { self.destroy(); } }; }); // FighterPlane class for the player's plane var FighterPlane = Container.expand(function () { var self = Container.call(this); var planeGraphics = self.attachAsset('fighterPlane', { anchorX: 0.5, anchorY: 0.5 }); self.x = 2048 / 2; // Center the plane horizontally self.y = 2732 - 200; // Position the plane near the bottom of the screen self.health = 100; // Initialize health // Method to shoot bullets self.shoot = function () { var newBullet = new Bullet(); newBullet.x = self.x; newBullet.y = self.y - 50; // Position bullet in front of the plane bullets.push(newBullet); game.addChild(newBullet); }; }); // HealthBar class for displaying health var HealthBar = Container.expand(function () { var self = Container.call(this); var barGraphics = self.attachAsset('healthBar', { anchorX: 0.5, anchorY: 0.5 }); self.updateHealth = function (health) { barGraphics.scaleX = health / 100; // Scale based on health percentage }; }); // Missile class for enemy missiles var Missile = Container.expand(function () { var self = Container.call(this); var missileGraphics = self.attachAsset('missile', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; // Speed of the missile self.update = function () { self.y += self.speed; if (self.y > 2732 + 50) { self.destroy(); } }; }); // Target class for the targets to be hit var Target = Container.expand(function () { var self = Container.call(this); var targetGraphics = self.attachAsset('target', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; // Speed of the target self.update = function () { self.y += self.speed; if (self.y > 2732 + 50) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Function to spawn a new big target function spawnBigTarget() { var newBigTarget = new BigTarget(); newBigTarget.x = Math.random() * 2048; newBigTarget.y = -100; // Start higher to give more time to react bigTargets.push(newBigTarget); game.addChild(newBigTarget); } // Initialize variables var bullets = []; var targets = []; var bigTargets = []; var missiles = []; var score = 0; var fighterPlane = new FighterPlane(); game.addChild(fighterPlane); // Create score display var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize health bar var healthBar = new HealthBar(); healthBar.x = 50; // Position health bar at the top left corner healthBar.y = 50; // Keep health bar at the top of the screen game.addChild(healthBar); // Function to spawn a new target function spawnTarget() { var newTarget = new Target(); newTarget.x = Math.random() * 2048; newTarget.y = -50; targets.push(newTarget); game.addChild(newTarget); } // Function to handle continuous shooting LK.setInterval(function () { fighterPlane.shoot(); }, 500); // Shoot every 500ms // Game update loop game.update = function () { // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { bullets[i].update(); for (var j = targets.length - 1; j >= 0; j--) { if (bullets[i].intersects(targets[j])) { bullets[i].destroy(); targets[j].destroy(); bullets.splice(i, 1); targets.splice(j, 1); score++; scoreTxt.setText(score); break; } } } // Update targets for (var k = targets.length - 1; k >= 0; k--) { targets[k].update(); // Targets shoot missiles periodically, limited to one every 5 seconds if (LK.ticks % 430 === 0) { // 5 seconds at 60 FPS if (!targets[k].lastMissileTime || LK.ticks - targets[k].lastMissileTime >= 300) { var newMissile = new Missile(); newMissile.x = targets[k].x; newMissile.y = targets[k].y + 50; // Position missile below the target game.addChild(newMissile); targets[k].lastMissileTime = LK.ticks; } } } // Update big targets for (var l = bigTargets.length - 1; l >= 0; l--) { bigTargets[l].update(); for (var m = bullets.length - 1; m >= 0; m--) { if (bullets[m].intersects(bigTargets[l])) { bullets[m].destroy(); bullets.splice(m, 1); if (bigTargets[l].hit()) { bigTargets.splice(l, 1); score += 5; // Extra points for destroying big target scoreTxt.setText(score); break; } } } } // Update missiles for (var n = missiles.length - 1; n >= 0; n--) { missiles[n].update(); if (missiles[n].intersects(fighterPlane)) { missiles[n].destroy(); missiles.splice(n, 1); // Reduce health fighterPlane.health = Math.max(0, fighterPlane.health - 20); healthBar.updateHealth(fighterPlane.health); // Flash screen and show explosion if health is zero if (fighterPlane.health <= 0) { LK.effects.flashScreen(0xff0000, 1000); // Create explosion effect var explosion = LK.getAsset('explosion', { anchorX: 0.5, anchorY: 0.5 }); explosion.x = fighterPlane.x; explosion.y = fighterPlane.y; game.addChild(explosion); // Remove fighter plane fighterPlane.destroy(); // Show game over LK.showGameOver(); } } } // Keep health bar at the top left corner healthBar.x = 50; healthBar.y = 50; // Spawn new targets periodically if (LK.ticks % 121 === 0) { spawnTarget(); } // Spawn big targets periodically if (LK.ticks % 300 === 0) { spawnBigTarget(); } }; // Handle touch events for shooting and moving the plane game.down = function (x, y, obj) { // Move the plane horizontally based on touch position fighterPlane.x = x; // shoot(x, y); // Removed as continuous shooting is handled by setInterval };
/****
* Classes
****/
// BigTarget class for larger targets that require multiple hits
var BigTarget = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('bigTarget', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1; // Slower speed for big targets
self.hitPoints = 5; // Number of hits required to destroy
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + 50) {
self.destroy();
}
};
self.hit = function () {
self.hitPoints--;
if (self.hitPoints <= 0) {
self.destroy();
return true; // Return true if destroyed
}
return false; // Return false if not yet destroyed
};
});
// Assets will be automatically initialized by the LK engine based on their usage in the code.
// Bullet class for the player's shots
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10; // Speed of the bullet
self.update = function () {
self.y += self.speed;
if (self.y < -50) {
self.destroy();
}
};
});
// FighterPlane class for the player's plane
var FighterPlane = Container.expand(function () {
var self = Container.call(this);
var planeGraphics = self.attachAsset('fighterPlane', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2; // Center the plane horizontally
self.y = 2732 - 200; // Position the plane near the bottom of the screen
self.health = 100; // Initialize health
// Method to shoot bullets
self.shoot = function () {
var newBullet = new Bullet();
newBullet.x = self.x;
newBullet.y = self.y - 50; // Position bullet in front of the plane
bullets.push(newBullet);
game.addChild(newBullet);
};
});
// HealthBar class for displaying health
var HealthBar = Container.expand(function () {
var self = Container.call(this);
var barGraphics = self.attachAsset('healthBar', {
anchorX: 0.5,
anchorY: 0.5
});
self.updateHealth = function (health) {
barGraphics.scaleX = health / 100; // Scale based on health percentage
};
});
// Missile class for enemy missiles
var Missile = Container.expand(function () {
var self = Container.call(this);
var missileGraphics = self.attachAsset('missile', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Speed of the missile
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + 50) {
self.destroy();
}
};
});
// Target class for the targets to be hit
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2; // Speed of the target
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + 50) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Function to spawn a new big target
function spawnBigTarget() {
var newBigTarget = new BigTarget();
newBigTarget.x = Math.random() * 2048;
newBigTarget.y = -100; // Start higher to give more time to react
bigTargets.push(newBigTarget);
game.addChild(newBigTarget);
}
// Initialize variables
var bullets = [];
var targets = [];
var bigTargets = [];
var missiles = [];
var score = 0;
var fighterPlane = new FighterPlane();
game.addChild(fighterPlane);
// Create score display
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize health bar
var healthBar = new HealthBar();
healthBar.x = 50; // Position health bar at the top left corner
healthBar.y = 50; // Keep health bar at the top of the screen
game.addChild(healthBar);
// Function to spawn a new target
function spawnTarget() {
var newTarget = new Target();
newTarget.x = Math.random() * 2048;
newTarget.y = -50;
targets.push(newTarget);
game.addChild(newTarget);
}
// Function to handle continuous shooting
LK.setInterval(function () {
fighterPlane.shoot();
}, 500); // Shoot every 500ms
// Game update loop
game.update = function () {
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
for (var j = targets.length - 1; j >= 0; j--) {
if (bullets[i].intersects(targets[j])) {
bullets[i].destroy();
targets[j].destroy();
bullets.splice(i, 1);
targets.splice(j, 1);
score++;
scoreTxt.setText(score);
break;
}
}
}
// Update targets
for (var k = targets.length - 1; k >= 0; k--) {
targets[k].update();
// Targets shoot missiles periodically, limited to one every 5 seconds
if (LK.ticks % 430 === 0) {
// 5 seconds at 60 FPS
if (!targets[k].lastMissileTime || LK.ticks - targets[k].lastMissileTime >= 300) {
var newMissile = new Missile();
newMissile.x = targets[k].x;
newMissile.y = targets[k].y + 50; // Position missile below the target
game.addChild(newMissile);
targets[k].lastMissileTime = LK.ticks;
}
}
}
// Update big targets
for (var l = bigTargets.length - 1; l >= 0; l--) {
bigTargets[l].update();
for (var m = bullets.length - 1; m >= 0; m--) {
if (bullets[m].intersects(bigTargets[l])) {
bullets[m].destroy();
bullets.splice(m, 1);
if (bigTargets[l].hit()) {
bigTargets.splice(l, 1);
score += 5; // Extra points for destroying big target
scoreTxt.setText(score);
break;
}
}
}
}
// Update missiles
for (var n = missiles.length - 1; n >= 0; n--) {
missiles[n].update();
if (missiles[n].intersects(fighterPlane)) {
missiles[n].destroy();
missiles.splice(n, 1);
// Reduce health
fighterPlane.health = Math.max(0, fighterPlane.health - 20);
healthBar.updateHealth(fighterPlane.health);
// Flash screen and show explosion if health is zero
if (fighterPlane.health <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
// Create explosion effect
var explosion = LK.getAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
explosion.x = fighterPlane.x;
explosion.y = fighterPlane.y;
game.addChild(explosion);
// Remove fighter plane
fighterPlane.destroy();
// Show game over
LK.showGameOver();
}
}
}
// Keep health bar at the top left corner
healthBar.x = 50;
healthBar.y = 50;
// Spawn new targets periodically
if (LK.ticks % 121 === 0) {
spawnTarget();
}
// Spawn big targets periodically
if (LK.ticks % 300 === 0) {
spawnBigTarget();
}
};
// Handle touch events for shooting and moving the plane
game.down = function (x, y, obj) {
// Move the plane horizontally based on touch position
fighterPlane.x = x;
// shoot(x, y); // Removed as continuous shooting is handled by setInterval
};
Missile 2d of a fighter plane. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d view of a fighter plane top view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cargo plane from top view (2d) of orange colour. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A small real missile 2d view View of whole body vertically. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Explosion in 2d game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.