/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Bird class to represent the player 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.3; self.flapStrength = -15; self.update = function () { self.speedY += self.gravity; self.y += self.speedY; // Check for collision with top and bottom of the screen if (self.y < 0) { self.y = 0; self.speedY = 0; } else if (self.y > 2732 - self.height) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver("Oh no! Our birdie decided to become an ostrich! Your score was ".concat(LK.getScore(), ". ")); } }; self.flap = function () { self.speedY = self.flapStrength; }; }); // Floor class to represent the ground var Floor = Container.expand(function () { var self = Container.call(this); var floorGraphics = self.attachAsset('floor', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // The floor doesn't move, so no need to update anything }; }); // Fruit class to represent the collectible items var Fruit = Container.expand(function () { var self = Container.call(this); var fruitGraphics = self.attachAsset('fruit', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = -5; self.update = function () { self.x += self.speedX; // Reset fruit position if it goes off screen if (self.x < -fruitGraphics.width) { self.x = 2048 + fruitGraphics.width; self.y = Math.random() * 2000 + 200; } }; }); // Wall class to represent the obstacles var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = -5; self.update = function () { self.x += self.speedX; // Reset wall position if it goes off screen if (self.x < -wallGraphics.width) { self.x = 2048 + wallGraphics.width; self.y = Math.random() * 2000 + 200; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Initialize bird var bird = new Bird(); bird.x = 2048 / 4; bird.y = 2732 / 2; game.addChild(bird); // Initialize floor var floor = new Floor(); floor.x = 2048 / 2; floor.y = 2732 - floor.height / 2; game.addChild(floor); // Initialize walls var walls = []; for (var i = 0; i < 3; i++) { var wall = new Wall(); wall.x = 2048 + i * 700; wall.y = Math.random() * 2000 + 200; walls.push(wall); game.addChild(wall); } // Initialize fruits var fruits = []; for (var i = 0; i < 5; i++) { var fruit = new Fruit(); fruit.x = 2048 + i * 500; fruit.y = Math.random() * 2000 + 200; fruits.push(fruit); game.addChild(fruit); } // Handle game updates game.update = function () { bird.update(); walls.forEach(function (wall) { wall.update(); // Check for collision with bird if (bird.intersects(wall)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver("Oops! Looks like our birdie forgot how to fly! Your score was ".concat(LK.getScore(), ". ")); } }); fruits.forEach(function (fruit) { fruit.update(); // Check for collision with bird if (bird.intersects(fruit)) { // Increase score by 1 LK.setScore(LK.getScore() + 1); // Reset fruit position fruit.x = 2048 + fruit.width; fruit.y = Math.random() * 2000 + 200; } }); }; // Handle touch input for flapping game.down = function (x, y, obj) { bird.flap(); };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Bird class to represent the player
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.3;
self.flapStrength = -15;
self.update = function () {
self.speedY += self.gravity;
self.y += self.speedY;
// Check for collision with top and bottom of the screen
if (self.y < 0) {
self.y = 0;
self.speedY = 0;
} else if (self.y > 2732 - self.height) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver("Oh no! Our birdie decided to become an ostrich! Your score was ".concat(LK.getScore(), ". "));
}
};
self.flap = function () {
self.speedY = self.flapStrength;
};
});
// Floor class to represent the ground
var Floor = Container.expand(function () {
var self = Container.call(this);
var floorGraphics = self.attachAsset('floor', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// The floor doesn't move, so no need to update anything
};
});
// Fruit class to represent the collectible items
var Fruit = Container.expand(function () {
var self = Container.call(this);
var fruitGraphics = self.attachAsset('fruit', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = -5;
self.update = function () {
self.x += self.speedX;
// Reset fruit position if it goes off screen
if (self.x < -fruitGraphics.width) {
self.x = 2048 + fruitGraphics.width;
self.y = Math.random() * 2000 + 200;
}
};
});
// Wall class to represent the obstacles
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = -5;
self.update = function () {
self.x += self.speedX;
// Reset wall position if it goes off screen
if (self.x < -wallGraphics.width) {
self.x = 2048 + wallGraphics.width;
self.y = Math.random() * 2000 + 200;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Initialize bird
var bird = new Bird();
bird.x = 2048 / 4;
bird.y = 2732 / 2;
game.addChild(bird);
// Initialize floor
var floor = new Floor();
floor.x = 2048 / 2;
floor.y = 2732 - floor.height / 2;
game.addChild(floor);
// Initialize walls
var walls = [];
for (var i = 0; i < 3; i++) {
var wall = new Wall();
wall.x = 2048 + i * 700;
wall.y = Math.random() * 2000 + 200;
walls.push(wall);
game.addChild(wall);
}
// Initialize fruits
var fruits = [];
for (var i = 0; i < 5; i++) {
var fruit = new Fruit();
fruit.x = 2048 + i * 500;
fruit.y = Math.random() * 2000 + 200;
fruits.push(fruit);
game.addChild(fruit);
}
// Handle game updates
game.update = function () {
bird.update();
walls.forEach(function (wall) {
wall.update();
// Check for collision with bird
if (bird.intersects(wall)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver("Oops! Looks like our birdie forgot how to fly! Your score was ".concat(LK.getScore(), ". "));
}
});
fruits.forEach(function (fruit) {
fruit.update();
// Check for collision with bird
if (bird.intersects(fruit)) {
// Increase score by 1
LK.setScore(LK.getScore() + 1);
// Reset fruit position
fruit.x = 2048 + fruit.width;
fruit.y = Math.random() * 2000 + 200;
}
});
};
// Handle touch input for flapping
game.down = function (x, y, obj) {
bird.flap();
};