/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Bird class to represent the player character var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 1.5, anchorY: 1.5 }); self.speedY = 0; self.gravity = 0.5; self.flapStrength = -10; // Update function to apply gravity and move the bird self.update = function () { self.speedY += self.gravity; self.y += self.speedY; }; // Flap function to make the bird jump self.flap = function () { self.speedY = self.flapStrength; }; }); // 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; // Update function to move the wall self.update = function () { self.x += self.speedX; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background }); /**** * Game Code ****/ // Initialize variables var bird; var walls = []; var wallInterval; var score = 0; var scoreTxt; // Function to start the game function startGame() { // Create the bird bird = game.addChild(new Bird()); bird.x = 2048 / 4; bird.y = 2732 / 2; // Create score text scoreTxt = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create walls at intervals wallInterval = LK.setInterval(createWall, 2000); // Add event listeners game.down = function (x, y, obj) { bird.flap(); }; } // Function to create a new wall function createWall() { var wall = game.addChild(new Wall()); wall.x = 2048; wall.y = Math.random() * (2732 - 400) + 200; // Random y position walls.push(wall); } // Update function for the game game.update = function () { bird.update(); // Update walls for (var i = walls.length - 1; i >= 0; i--) { walls[i].update(); // Check for collision with bird if (bird.intersects(walls[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Remove walls that are off screen if (walls[i].x < -100) { walls[i].destroy(); walls.splice(i, 1); score++; scoreTxt.setText('Score: ' + score); } } // Check if bird is out of bounds if (bird.y < 0 || bird.y > 2732) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }; // Start the game startGame();
===================================================================
--- original.js
+++ change.js
@@ -1,109 +1,109 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Bird class to represent 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 to apply gravity and move the bird
- self.update = function () {
- self.speedY += self.gravity;
- self.y += self.speedY;
- };
- // Flap function to make the bird jump
- self.flap = function () {
- self.speedY = self.flapStrength;
- };
+ var self = Container.call(this);
+ var birdGraphics = self.attachAsset('bird', {
+ anchorX: 1.5,
+ anchorY: 1.5
+ });
+ self.speedY = 0;
+ self.gravity = 0.5;
+ self.flapStrength = -10;
+ // Update function to apply gravity and move the bird
+ self.update = function () {
+ self.speedY += self.gravity;
+ self.y += self.speedY;
+ };
+ // Flap function to make the bird jump
+ self.flap = function () {
+ self.speedY = self.flapStrength;
+ };
});
// 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;
- // Update function to move the wall
- self.update = function () {
- self.x += self.speedX;
- };
+ var self = Container.call(this);
+ var wallGraphics = self.attachAsset('wall', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = -5;
+ // Update function to move the wall
+ self.update = function () {
+ self.x += self.speedX;
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB // Light blue background
+ backgroundColor: 0x87CEEB // Light blue background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize variables
var bird;
var walls = [];
var wallInterval;
var score = 0;
var scoreTxt;
// Function to start the game
function startGame() {
- // Create the bird
- bird = game.addChild(new Bird());
- bird.x = 2048 / 4;
- bird.y = 2732 / 2;
- // Create score text
- scoreTxt = new Text2('Score: 0', {
- size: 100,
- fill: 0xFFFFFF
- });
- scoreTxt.anchor.set(0.5, 0);
- LK.gui.top.addChild(scoreTxt);
- // Create walls at intervals
- wallInterval = LK.setInterval(createWall, 2000);
- // Add event listeners
- game.down = function (x, y, obj) {
- bird.flap();
- };
+ // Create the bird
+ bird = game.addChild(new Bird());
+ bird.x = 2048 / 4;
+ bird.y = 2732 / 2;
+ // Create score text
+ scoreTxt = new Text2('Score: 0', {
+ size: 100,
+ fill: 0xFFFFFF
+ });
+ scoreTxt.anchor.set(0.5, 0);
+ LK.gui.top.addChild(scoreTxt);
+ // Create walls at intervals
+ wallInterval = LK.setInterval(createWall, 2000);
+ // Add event listeners
+ game.down = function (x, y, obj) {
+ bird.flap();
+ };
}
// Function to create a new wall
function createWall() {
- var wall = game.addChild(new Wall());
- wall.x = 2048;
- wall.y = Math.random() * (2732 - 400) + 200; // Random y position
- walls.push(wall);
+ var wall = game.addChild(new Wall());
+ wall.x = 2048;
+ wall.y = Math.random() * (2732 - 400) + 200; // Random y position
+ walls.push(wall);
}
// Update function for the game
game.update = function () {
- bird.update();
- // Update walls
- for (var i = walls.length - 1; i >= 0; i--) {
- walls[i].update();
- // Check for collision with bird
- if (bird.intersects(walls[i])) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- // Remove walls that are off screen
- if (walls[i].x < -100) {
- walls[i].destroy();
- walls.splice(i, 1);
- score++;
- scoreTxt.setText('Score: ' + score);
- }
- }
- // Check if bird is out of bounds
- if (bird.y < 0 || bird.y > 2732) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
+ bird.update();
+ // Update walls
+ for (var i = walls.length - 1; i >= 0; i--) {
+ walls[i].update();
+ // Check for collision with bird
+ if (bird.intersects(walls[i])) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ // Remove walls that are off screen
+ if (walls[i].x < -100) {
+ walls[i].destroy();
+ walls.splice(i, 1);
+ score++;
+ scoreTxt.setText('Score: ' + score);
+ }
+ }
+ // Check if bird is out of bounds
+ if (bird.y < 0 || bird.y > 2732) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
};
// Start the game
startGame();
\ No newline at end of file