/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Coin = Container.expand(function () { var self = Container.call(this); self.coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.collected = false; // Floating animation self.animationOffset = Math.random() * Math.PI * 2; self.floatAmount = 20; self.update = function () { if (self.collected) { return; } self.x -= self.speed; // Floating animation self.y += Math.sin(LK.ticks * 0.1 + self.animationOffset) * 0.5; // Rotation animation self.rotation += 0.05; // Check collision with drone if (self.intersects(drone)) { self.collected = true; LK.setScore(LK.getScore() + 1); LK.getSound('score').play(); scoreTxt.setText(LK.getScore()); // Collection animation with tween tween(self, { scaleX: 2, scaleY: 2, alpha: 0 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); // Check if section should change updateGameSection(); } }; return self; }); var Drone = Container.expand(function () { var self = Container.call(this); // Current drone graphics self.droneGraphics = null; self.velocity = 0; self.gravity = 1; self.jumpPower = -12; // Set drone type based on current section self.setDroneType = function (section) { if (self.droneGraphics) { self.removeChild(self.droneGraphics); } var droneType = 'natureDrone'; if (section === 1) { droneType = 'militaryDrone'; } else if (section === 2) { droneType = 'futuristicDrone'; } else if (section === 3) { droneType = 'archeologicalDrone'; } self.droneGraphics = self.attachAsset(droneType, { anchorX: 0.5, anchorY: 0.5 }); }; self.flap = function () { self.velocity = self.jumpPower; LK.getSound('flap').play(); // Flap animation tween(self, { rotation: -0.3 }, { duration: 200 }); tween(self, { rotation: 0.3 }, { duration: 300, onFinish: function onFinish() { tween(self, { rotation: 0 }, { duration: 200 }); } }); }; self.update = function () { // Only apply physics if game has started if (gameStarted) { self.velocity += self.gravity; self.y += self.velocity; // Rotation based on velocity self.rotation = Math.min(Math.max(self.velocity * 0.05, -0.5), 0.8); } }; return self; }); var Obstacle = Container.expand(function () { var self = Container.call(this); self.topObstacle = null; self.bottomObstacle = null; self.gapHeight = 440; self.speed = 12; self.scored = false; self.createObstacle = function (section, gapY) { var obstacleType = 'treeObstacle'; if (section === 1) { obstacleType = 'barbedWireObstacle'; } else if (section === 2) { obstacleType = 'neonPoleObstacle'; } else if (section === 3) { obstacleType = 'stoneColumnObstacle'; } // Top obstacle self.topObstacle = self.attachAsset(obstacleType, { anchorX: 0.5, anchorY: 1 }); self.topObstacle.x = 0; self.topObstacle.y = gapY - self.gapHeight / 2; // Bottom obstacle self.bottomObstacle = self.attachAsset(obstacleType, { anchorX: 0.5, anchorY: 0 }); self.bottomObstacle.x = 0; self.bottomObstacle.y = gapY + self.gapHeight / 2; }; self.update = function () { self.x -= self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ // Sounds // Background shapes for each section // Obstacle assets for each section // Drone assets for each section // Game state variables var gameStarted = false; var gameSection = 0; // 0-3 for the four sections var obstacles = []; var coins = []; var obstacleSpawnTimer = 0; var backgroundGraphics = null; // Create drone var drone = game.addChild(new Drone()); drone.x = 400; drone.y = 1366; drone.velocity = 0; // Start with no velocity // Create background function updateBackground() { if (backgroundGraphics) { game.removeChild(backgroundGraphics); } var bgType = 'mountainBg'; if (gameSection === 1) { bgType = 'battlefieldBg'; } else if (gameSection === 2) { bgType = 'cyberpunkBg'; } else if (gameSection === 3) { bgType = 'desertBg'; } backgroundGraphics = LK.getAsset(bgType, { anchorX: 0, anchorY: 0, x: 0, y: 0 }); game.addChildAt(backgroundGraphics, 0); } // Initialize background and drone updateBackground(); drone.setDroneType(gameSection); // Create UI var scoreTxt = new Text2('0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var startPrompt = new Text2('TAP TO START', { size: 80, fill: 0xFFFFFF }); startPrompt.anchor.set(0.5, 0.5); LK.gui.center.addChild(startPrompt); // Game section management function updateGameSection() { var score = LK.getScore(); var newSection = Math.floor(score / 50) % 4; if (newSection !== gameSection) { gameSection = newSection; updateBackground(); drone.setDroneType(gameSection); // Increase difficulty slightly for (var i = 0; i < obstacles.length; i++) { obstacles[i].speed = 4 + Math.floor(score / 100) * 0.5; } } } // Obstacle spawning function spawnObstacle() { var obstacle = new Obstacle(); var gapY = 400 + Math.random() * (2732 - 800); obstacle.createObstacle(gameSection, gapY); obstacle.x = 2048 + 250; obstacle.speed = 4 + Math.floor(LK.getScore() / 100) * 0.5; obstacles.push(obstacle); game.addChild(obstacle); // Spawn coin in the gap var coin = new Coin(); coin.x = obstacle.x; coin.y = gapY; coin.speed = obstacle.speed; coins.push(coin); game.addChild(coin); } // Input handling game.down = function (x, y, obj) { if (!gameStarted) { gameStarted = true; startPrompt.visible = false; // Start with a flap to begin movement drone.flap(); return; } drone.flap(); }; // Main game loop game.update = function () { if (!gameStarted) { return; } // Check bounds collision if (drone.y < 0 || drone.y > 2732) { LK.getSound('crash').play(); LK.showGameOver(); return; } // Spawn obstacles obstacleSpawnTimer++; if (obstacleSpawnTimer >= 300) { // Spawn every 5 seconds at 60fps spawnObstacle(); obstacleSpawnTimer = 0; } // Update and check obstacle collisions for (var i = obstacles.length - 1; i >= 0; i--) { var obstacle = obstacles[i]; // Check collision with drone if (drone.intersects(obstacle.topObstacle) || drone.intersects(obstacle.bottomObstacle)) { LK.getSound('crash').play(); LK.showGameOver(); return; } // Remove off-screen obstacles if (obstacle.x < -200) { obstacle.destroy(); obstacles.splice(i, 1); } } // Update and cleanup coins for (var j = coins.length - 1; j >= 0; j--) { var coin = coins[j]; // Remove off-screen or collected coins if (coin.x < -100 || coin.collected) { if (!coin.collected) { coin.destroy(); } coins.splice(j, 1); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
self.coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.collected = false;
// Floating animation
self.animationOffset = Math.random() * Math.PI * 2;
self.floatAmount = 20;
self.update = function () {
if (self.collected) {
return;
}
self.x -= self.speed;
// Floating animation
self.y += Math.sin(LK.ticks * 0.1 + self.animationOffset) * 0.5;
// Rotation animation
self.rotation += 0.05;
// Check collision with drone
if (self.intersects(drone)) {
self.collected = true;
LK.setScore(LK.getScore() + 1);
LK.getSound('score').play();
scoreTxt.setText(LK.getScore());
// Collection animation with tween
tween(self, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
// Check if section should change
updateGameSection();
}
};
return self;
});
var Drone = Container.expand(function () {
var self = Container.call(this);
// Current drone graphics
self.droneGraphics = null;
self.velocity = 0;
self.gravity = 1;
self.jumpPower = -12;
// Set drone type based on current section
self.setDroneType = function (section) {
if (self.droneGraphics) {
self.removeChild(self.droneGraphics);
}
var droneType = 'natureDrone';
if (section === 1) {
droneType = 'militaryDrone';
} else if (section === 2) {
droneType = 'futuristicDrone';
} else if (section === 3) {
droneType = 'archeologicalDrone';
}
self.droneGraphics = self.attachAsset(droneType, {
anchorX: 0.5,
anchorY: 0.5
});
};
self.flap = function () {
self.velocity = self.jumpPower;
LK.getSound('flap').play();
// Flap animation
tween(self, {
rotation: -0.3
}, {
duration: 200
});
tween(self, {
rotation: 0.3
}, {
duration: 300,
onFinish: function onFinish() {
tween(self, {
rotation: 0
}, {
duration: 200
});
}
});
};
self.update = function () {
// Only apply physics if game has started
if (gameStarted) {
self.velocity += self.gravity;
self.y += self.velocity;
// Rotation based on velocity
self.rotation = Math.min(Math.max(self.velocity * 0.05, -0.5), 0.8);
}
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
self.topObstacle = null;
self.bottomObstacle = null;
self.gapHeight = 440;
self.speed = 12;
self.scored = false;
self.createObstacle = function (section, gapY) {
var obstacleType = 'treeObstacle';
if (section === 1) {
obstacleType = 'barbedWireObstacle';
} else if (section === 2) {
obstacleType = 'neonPoleObstacle';
} else if (section === 3) {
obstacleType = 'stoneColumnObstacle';
}
// Top obstacle
self.topObstacle = self.attachAsset(obstacleType, {
anchorX: 0.5,
anchorY: 1
});
self.topObstacle.x = 0;
self.topObstacle.y = gapY - self.gapHeight / 2;
// Bottom obstacle
self.bottomObstacle = self.attachAsset(obstacleType, {
anchorX: 0.5,
anchorY: 0
});
self.bottomObstacle.x = 0;
self.bottomObstacle.y = gapY + self.gapHeight / 2;
};
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Sounds
// Background shapes for each section
// Obstacle assets for each section
// Drone assets for each section
// Game state variables
var gameStarted = false;
var gameSection = 0; // 0-3 for the four sections
var obstacles = [];
var coins = [];
var obstacleSpawnTimer = 0;
var backgroundGraphics = null;
// Create drone
var drone = game.addChild(new Drone());
drone.x = 400;
drone.y = 1366;
drone.velocity = 0; // Start with no velocity
// Create background
function updateBackground() {
if (backgroundGraphics) {
game.removeChild(backgroundGraphics);
}
var bgType = 'mountainBg';
if (gameSection === 1) {
bgType = 'battlefieldBg';
} else if (gameSection === 2) {
bgType = 'cyberpunkBg';
} else if (gameSection === 3) {
bgType = 'desertBg';
}
backgroundGraphics = LK.getAsset(bgType, {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChildAt(backgroundGraphics, 0);
}
// Initialize background and drone
updateBackground();
drone.setDroneType(gameSection);
// Create UI
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var startPrompt = new Text2('TAP TO START', {
size: 80,
fill: 0xFFFFFF
});
startPrompt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(startPrompt);
// Game section management
function updateGameSection() {
var score = LK.getScore();
var newSection = Math.floor(score / 50) % 4;
if (newSection !== gameSection) {
gameSection = newSection;
updateBackground();
drone.setDroneType(gameSection);
// Increase difficulty slightly
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].speed = 4 + Math.floor(score / 100) * 0.5;
}
}
}
// Obstacle spawning
function spawnObstacle() {
var obstacle = new Obstacle();
var gapY = 400 + Math.random() * (2732 - 800);
obstacle.createObstacle(gameSection, gapY);
obstacle.x = 2048 + 250;
obstacle.speed = 4 + Math.floor(LK.getScore() / 100) * 0.5;
obstacles.push(obstacle);
game.addChild(obstacle);
// Spawn coin in the gap
var coin = new Coin();
coin.x = obstacle.x;
coin.y = gapY;
coin.speed = obstacle.speed;
coins.push(coin);
game.addChild(coin);
}
// Input handling
game.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
startPrompt.visible = false;
// Start with a flap to begin movement
drone.flap();
return;
}
drone.flap();
};
// Main game loop
game.update = function () {
if (!gameStarted) {
return;
}
// Check bounds collision
if (drone.y < 0 || drone.y > 2732) {
LK.getSound('crash').play();
LK.showGameOver();
return;
}
// Spawn obstacles
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= 300) {
// Spawn every 5 seconds at 60fps
spawnObstacle();
obstacleSpawnTimer = 0;
}
// Update and check obstacle collisions
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
// Check collision with drone
if (drone.intersects(obstacle.topObstacle) || drone.intersects(obstacle.bottomObstacle)) {
LK.getSound('crash').play();
LK.showGameOver();
return;
}
// Remove off-screen obstacles
if (obstacle.x < -200) {
obstacle.destroy();
obstacles.splice(i, 1);
}
}
// Update and cleanup coins
for (var j = coins.length - 1; j >= 0; j--) {
var coin = coins[j];
// Remove off-screen or collected coins
if (coin.x < -100 || coin.collected) {
if (!coin.collected) {
coin.destroy();
}
coins.splice(j, 1);
}
}
};
drone side view. In-Game asset. 2d. High contrast. No shadows
light brown mountain background. In-Game asset. 2d. High contrast. No shadows
barbed iron pole. In-Game asset. 2d. High contrast. No shadows
column pillar belonging to ancient Egypt. the top and bottom are the same. symmetrical. In-Game asset. 2d. High contrast. No shadows
neon turquoise pole. covered with neon pink frame. In-Game asset. 2d. High contrast. No shadows
World War II, gloomy weather, just ground. In-Game asset. 2d. High contrast. No shadows
cyberpunk city for back ground. Dark blue In-Game asset. 2d. High contrast. No shadows
ancient egypt for background. In-Game asset. 2d. High contrast. No shadows
wood pole rectangular flat. In-Game asset. 2d. High contrast. No shadows
drone side view military drone. light camouflage In-Game asset. 2d. High contrast. No shadows
drone side view drone. Silver Color. In-Game asset. 2d. High contrast. No shadows
drone side view drone. cyberpunk theme, has yellow light. neon green color In-Game asset. 2d. High contrast. No shadows
flat black framed silver coin In-Game asset. 2d. High contrast. No shadows