/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Plane class representing both player and enemy planes var Plane = Container.expand(function () { var self = Container.call(this); var planeGraphics = self.attachAsset('plane', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Placeholder for update logic }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player plane var playerPlane = game.addChild(new Plane()); playerPlane.x = 2048 / 2; playerPlane.y = 2732 - 200; // Array to hold enemy planes var enemyPlanes = []; // Function to spawn enemy planes function spawnEnemyPlane() { var enemyPlane = new Plane(); enemyPlane.x = Math.random() * 2048; enemyPlane.y = -100; enemyPlanes.push(enemyPlane); game.addChild(enemyPlane); } // Function to handle game over function gameOver() { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Handle player movement var dragNode = null; // Define handleMove function function handleMove(x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; } } game.down = function (x, y, obj) { dragNode = playerPlane; handleMove(x, y, obj); }; game.move = function (x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; } }; game.up = function (x, y, obj) { dragNode = null; }; // Define handleMove function // Update game state game.update = function () { // Spawn enemy planes periodically if (LK.ticks % 60 == 0) { spawnEnemyPlane(); } // Update enemy planes for (var i = enemyPlanes.length - 1; i >= 0; i--) { var enemyPlane = enemyPlanes[i]; enemyPlane.y += 5; // Check for collision with player plane if (playerPlane.intersects(enemyPlane)) { gameOver(); } // Remove off-screen enemy planes if (enemyPlane.y > 2732 + 100) { enemyPlane.destroy(); enemyPlanes.splice(i, 1); } } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Plane class representing both player and enemy planes
var Plane = Container.expand(function () {
var self = Container.call(this);
var planeGraphics = self.attachAsset('plane', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Placeholder for update logic
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize player plane
var playerPlane = game.addChild(new Plane());
playerPlane.x = 2048 / 2;
playerPlane.y = 2732 - 200;
// Array to hold enemy planes
var enemyPlanes = [];
// Function to spawn enemy planes
function spawnEnemyPlane() {
var enemyPlane = new Plane();
enemyPlane.x = Math.random() * 2048;
enemyPlane.y = -100;
enemyPlanes.push(enemyPlane);
game.addChild(enemyPlane);
}
// Function to handle game over
function gameOver() {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Handle player movement
var dragNode = null;
// Define handleMove function
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
}
game.down = function (x, y, obj) {
dragNode = playerPlane;
handleMove(x, y, obj);
};
game.move = function (x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Define handleMove function
// Update game state
game.update = function () {
// Spawn enemy planes periodically
if (LK.ticks % 60 == 0) {
spawnEnemyPlane();
}
// Update enemy planes
for (var i = enemyPlanes.length - 1; i >= 0; i--) {
var enemyPlane = enemyPlanes[i];
enemyPlane.y += 5;
// Check for collision with player plane
if (playerPlane.intersects(enemyPlane)) {
gameOver();
}
// Remove off-screen enemy planes
if (enemyPlane.y > 2732 + 100) {
enemyPlane.destroy();
enemyPlanes.splice(i, 1);
}
}
};