/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Bird class representing the player character var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); self.speedY = 0; self.gravity = 0.5; self.flapStrength = -10; // Update function for bird movement self.update = function () { self.speedY += self.gravity; self.y += self.speedY; // Prevent bird from going off-screen if (self.y > 2732 - birdGraphics.height / 2) { self.y = 2732 - birdGraphics.height / 2; self.speedY = 0; } if (self.y < birdGraphics.height / 2) { self.y = birdGraphics.height / 2; self.speedY = 0; } }; // Flap function to make the bird jump self.flap = function () { self.speedY = self.flapStrength; LK.getSound('flap').play(); }; }); // Pipe class representing obstacles var Pipe = Container.expand(function () { var self = Container.call(this); var pipeGraphics = self.attachAsset('pipe', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = -5; // Update function for pipe movement self.update = function () { self.x += self.speedX; // Remove pipe if it goes off-screen if (self.x < -pipeGraphics.width / 2) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Initialize score var score = 0; // Create score text var scoreText = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // Function to update score function updateScore() { score += 1; scoreText.setText('Score: ' + score); } var bird = new Bird(); bird.x = 2048 / 4; bird.y = 2732 / 2; game.addChild(bird); // Array to hold pipes var pipes = []; // Function to create a new pipe function createPipe() { var pipe = new Pipe(); pipe.x = 2048 + pipe.width / 2; pipe.y = Math.random() * (2732 - 400) + 200; // Random y position pipes.push(pipe); game.addChild(pipe); } // Timer to create pipes at intervals var pipeTimer = LK.setInterval(createPipe, 2000); // Game update function game.update = function () { bird.update(); // Update pipes for (var i = pipes.length - 1; i >= 0; i--) { pipes[i].update(); if (pipes[i].x < -pipes[i].width / 2) { pipes.splice(i, 1); } // Check if bird has passed a pipe for (var k = 0; k < pipes.length; k++) { if (pipes[k].x < bird.x && !pipes[k].passed) { pipes[k].passed = true; updateScore(); } } } // Check for collisions for (var j = 0; j < pipes.length; j++) { if (bird.intersects(pipes[j])) { LK.effects.flashScreen(0xff0000, 1000); score = 0; scoreText.setText('Score: 0'); LK.showGameOver(); break; } } }; // Handle touch input for bird flap game.down = function (x, y, obj) { bird.flap(); }; // Google Play Store publishing code // Please replace 'YOUR_PACKAGE_NAME' and 'YOUR_PUBLIC_KEY' with your actual package name and public key var playStore = new GooglePlayStore('YOUR_PACKAGE_NAME', 'YOUR_PUBLIC_KEY'); playStore.publish(game); // FRVR publishing code FRVR.Game.publish(game);
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Bird class representing the player character
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedY = 0;
self.gravity = 0.5;
self.flapStrength = -10;
// Update function for bird movement
self.update = function () {
self.speedY += self.gravity;
self.y += self.speedY;
// Prevent bird from going off-screen
if (self.y > 2732 - birdGraphics.height / 2) {
self.y = 2732 - birdGraphics.height / 2;
self.speedY = 0;
}
if (self.y < birdGraphics.height / 2) {
self.y = birdGraphics.height / 2;
self.speedY = 0;
}
};
// Flap function to make the bird jump
self.flap = function () {
self.speedY = self.flapStrength;
LK.getSound('flap').play();
};
});
// Pipe class representing obstacles
var Pipe = Container.expand(function () {
var self = Container.call(this);
var pipeGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = -5;
// Update function for pipe movement
self.update = function () {
self.x += self.speedX;
// Remove pipe if it goes off-screen
if (self.x < -pipeGraphics.width / 2) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Initialize score
var score = 0;
// Create score text
var scoreText = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Function to update score
function updateScore() {
score += 1;
scoreText.setText('Score: ' + score);
}
var bird = new Bird();
bird.x = 2048 / 4;
bird.y = 2732 / 2;
game.addChild(bird);
// Array to hold pipes
var pipes = [];
// Function to create a new pipe
function createPipe() {
var pipe = new Pipe();
pipe.x = 2048 + pipe.width / 2;
pipe.y = Math.random() * (2732 - 400) + 200; // Random y position
pipes.push(pipe);
game.addChild(pipe);
}
// Timer to create pipes at intervals
var pipeTimer = LK.setInterval(createPipe, 2000);
// Game update function
game.update = function () {
bird.update();
// Update pipes
for (var i = pipes.length - 1; i >= 0; i--) {
pipes[i].update();
if (pipes[i].x < -pipes[i].width / 2) {
pipes.splice(i, 1);
}
// Check if bird has passed a pipe
for (var k = 0; k < pipes.length; k++) {
if (pipes[k].x < bird.x && !pipes[k].passed) {
pipes[k].passed = true;
updateScore();
}
}
}
// Check for collisions
for (var j = 0; j < pipes.length; j++) {
if (bird.intersects(pipes[j])) {
LK.effects.flashScreen(0xff0000, 1000);
score = 0;
scoreText.setText('Score: 0');
LK.showGameOver();
break;
}
}
};
// Handle touch input for bird flap
game.down = function (x, y, obj) {
bird.flap();
};
// Google Play Store publishing code
// Please replace 'YOUR_PACKAGE_NAME' and 'YOUR_PUBLIC_KEY' with your actual package name and public key
var playStore = new GooglePlayStore('YOUR_PACKAGE_NAME', 'YOUR_PUBLIC_KEY');
playStore.publish(game);
// FRVR publishing code
FRVR.Game.publish(game);