/**** * Classes ****/ // Bomb class representing the bombs to be avoided var Bomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('bomb', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; // Speed at which the bomb moves downwards // Update function to move the bomb self.update = function () { self.y += self.speed; }; }); // CollectiblePlane class representing the plane to be collected var CollectiblePlane = Container.expand(function () { var self = Container.call(this); var collectiblePlaneGraphics = self.attachAsset('collectiblePlane', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; // Speed at which the plane moves downwards // Add a text asset to the plane var planeText = new Text2('Seher', { size: 50, fill: 0x000000 }); planeText.anchor.set(0.5, 0); planeText.y = -collectiblePlaneGraphics.height; self.addChild(planeText); // Update function to move the plane self.update = function () { self.y += self.speed; }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Plane class representing the enemy planes var Plane = Container.expand(function () { var self = Container.call(this); var planeGraphics = self.attachAsset('plane', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; // Speed at which the plane moves downwards // Update function to move the plane self.update = function () { self.y += self.speed; }; }); // Player class representing the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); // Event handler for when the player is dragged self.down = function (x, y, obj) { // No action needed }; }); // PlayerCharacter class representing the player's selected character var PlayerCharacter = Container.expand(function () { var self = Container.call(this); var playerCharacterGraphics = self.attachAsset('playerCharacter', { anchorX: 0.5, anchorY: 0.5 }); var playerText = new Text2('Halim', { size: 50, fill: 0x000000 }); playerText.anchor.set(0.5, 0); playerText.y = -playerCharacterGraphics.height; self.addChild(playerText); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000033 // Change to dark blue for space theme }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0 })); // Initialize player and planes var player = game.addChild(new PlayerCharacter()); player.x = 2048 / 2; player.y = 2732 - 200; // Position player near the bottom of the screen var planes = []; var bombs = []; var score = 0; // Create score text var scoreTxt = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Function to spawn a new plane function spawnPlane() { var newPlane = new CollectiblePlane(); newPlane.x = Math.random() * 2048; // Random x position newPlane.y = -100; // Start above the screen planes.push(newPlane); game.addChild(newPlane); } // Handle game updates game.update = function () { // Update planes for (var i = planes.length - 1; i >= 0; i--) { planes[i].speed = 3 + score * 0.1; // Increase the speed of the plane as the score increases planes[i].update(); // Check for collision with player if (planes[i].intersects(player)) { score += 1; scoreTxt.setText('Score: ' + score); planes[i].destroy(); planes.splice(i, 1); } // Remove planes that are off-screen if (planes[i] && planes[i].y > 2732) { planes[i].destroy(); planes.splice(i, 1); } } // Spawn a new plane every 60 ticks if (LK.ticks % 60 == 0) { spawnPlane(); } // Spawn a new bomb every 120 ticks if (LK.ticks % 120 == 0) { var newBomb = new Bomb(); newBomb.x = Math.random() * 2048; // Random x position newBomb.y = -100; // Start above the screen bombs.push(newBomb); game.addChild(newBomb); } // Check for collision with bombs for (var i = bombs.length - 1; i >= 0; i--) { if (bombs[i].intersects(player)) { LK.showGameOver(); return; // Exit the update function to prevent further game updates after game over } } }; // Removed the player's movement on mouse click game.down = function (x, y, obj) { // No action needed }; game.move = function (x, y, obj) { if (x > 0 && x < 2048) { player.x += (x - player.x) * 0.1; } };
/****
* Classes
****/
// Bomb class representing the bombs to be avoided
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Speed at which the bomb moves downwards
// Update function to move the bomb
self.update = function () {
self.y += self.speed;
};
});
// CollectiblePlane class representing the plane to be collected
var CollectiblePlane = Container.expand(function () {
var self = Container.call(this);
var collectiblePlaneGraphics = self.attachAsset('collectiblePlane', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Speed at which the plane moves downwards
// Add a text asset to the plane
var planeText = new Text2('Seher', {
size: 50,
fill: 0x000000
});
planeText.anchor.set(0.5, 0);
planeText.y = -collectiblePlaneGraphics.height;
self.addChild(planeText);
// Update function to move the plane
self.update = function () {
self.y += self.speed;
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Plane class representing the enemy planes
var Plane = Container.expand(function () {
var self = Container.call(this);
var planeGraphics = self.attachAsset('plane', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Speed at which the plane moves downwards
// Update function to move the plane
self.update = function () {
self.y += self.speed;
};
});
// Player class representing the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
// Event handler for when the player is dragged
self.down = function (x, y, obj) {
// No action needed
};
});
// PlayerCharacter class representing the player's selected character
var PlayerCharacter = Container.expand(function () {
var self = Container.call(this);
var playerCharacterGraphics = self.attachAsset('playerCharacter', {
anchorX: 0.5,
anchorY: 0.5
});
var playerText = new Text2('Halim', {
size: 50,
fill: 0x000000
});
playerText.anchor.set(0.5, 0);
playerText.y = -playerCharacterGraphics.height;
self.addChild(playerText);
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000033 // Change to dark blue for space theme
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
// Initialize player and planes
var player = game.addChild(new PlayerCharacter());
player.x = 2048 / 2;
player.y = 2732 - 200; // Position player near the bottom of the screen
var planes = [];
var bombs = [];
var score = 0;
// Create score text
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn a new plane
function spawnPlane() {
var newPlane = new CollectiblePlane();
newPlane.x = Math.random() * 2048; // Random x position
newPlane.y = -100; // Start above the screen
planes.push(newPlane);
game.addChild(newPlane);
}
// Handle game updates
game.update = function () {
// Update planes
for (var i = planes.length - 1; i >= 0; i--) {
planes[i].speed = 3 + score * 0.1; // Increase the speed of the plane as the score increases
planes[i].update();
// Check for collision with player
if (planes[i].intersects(player)) {
score += 1;
scoreTxt.setText('Score: ' + score);
planes[i].destroy();
planes.splice(i, 1);
}
// Remove planes that are off-screen
if (planes[i] && planes[i].y > 2732) {
planes[i].destroy();
planes.splice(i, 1);
}
}
// Spawn a new plane every 60 ticks
if (LK.ticks % 60 == 0) {
spawnPlane();
}
// Spawn a new bomb every 120 ticks
if (LK.ticks % 120 == 0) {
var newBomb = new Bomb();
newBomb.x = Math.random() * 2048; // Random x position
newBomb.y = -100; // Start above the screen
bombs.push(newBomb);
game.addChild(newBomb);
}
// Check for collision with bombs
for (var i = bombs.length - 1; i >= 0; i--) {
if (bombs[i].intersects(player)) {
LK.showGameOver();
return; // Exit the update function to prevent further game updates after game over
}
}
};
// Removed the player's movement on mouse click
game.down = function (x, y, obj) {
// No action needed
};
game.move = function (x, y, obj) {
if (x > 0 && x < 2048) {
player.x += (x - player.x) * 0.1;
}
};