/**** * Classes ****/ // Assets will be automatically created based on usage in the code. // Bird class var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); self.gravity = 0.25; self.lift = -6; self.velocity = 0; self.flap = function () { self.velocity += self.lift; }; self.update = function () { self.velocity += self.gravity; self.y += self.velocity; if (self.y > 2732 - birdGraphics.height / 2) { self.y = 2732 - birdGraphics.height / 2; self.velocity = 0; } if (self.y < birdGraphics.height / 2) { self.y = birdGraphics.height / 2; self.velocity = 0; } }; }); // Cloud class var Cloud = Container.expand(function () { var self = Container.call(this); var cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -2; self.move = function () { self.x += self.speed; }; }); // Pipe class var Pipe = Container.expand(function (isTop, height) { var self = Container.call(this); var pipeGraphics = self.attachAsset(isTop ? 'pipeTop' : 'pipeBottom', { anchorX: 0.5, anchorY: isTop ? 1 : 0 }); self.height = height; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background to simulate sky }); /**** * Game Code ****/ var bird; var pipes = []; var gap = 400; var pipeWidth = 148; // Assuming a pipe width, since it's not specified var pipeInterval = 1800; // Time in milliseconds between pipe spawns var lastPipeTime = 0; // Initialize bird function initBird() { bird = new Bird(); bird.x = 2048 / 4; bird.y = 2732 / 2; game.addChild(bird); } // Initialize clouds var clouds = []; for (var i = 0; i < 5; i++) { var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * 2732; clouds.push(cloud); game.addChild(cloud); } // Function to add pipes function addPipe() { var topPipeHeight = Math.floor(Math.random() * (2732 - gap)) + 100; // Random height for top pipe var bottomPipeHeight = 2732 - topPipeHeight - gap; var topPipe = new Pipe(true, topPipeHeight); topPipe.x = 2048; topPipe.y = 0; pipes.push(topPipe); game.addChild(topPipe); var bottomPipe = new Pipe(false, bottomPipeHeight); bottomPipe.x = 2048; bottomPipe.y = 2732 - bottomPipeHeight; pipes.push(bottomPipe); game.addChild(bottomPipe); } // Function to update pipes function updatePipes() { for (var i = pipes.length - 1; i >= 0; i--) { pipes[i].x -= 5; if (pipes[i].x + pipeWidth < 0) { pipes[i].destroy(); pipes.splice(i, 1); // Increase score when bird passes a pipe score++; } } } // Function to check collision function checkCollision() { for (var i = 0; i < pipes.length; i++) { if (bird.intersects(pipes[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); // Display the score when the game is over console.log("Score: " + score); } } } // Initialize game elements initBird(); // Initialize score var score = 0; // Touch event to make the bird flap game.on('down', function () { bird.flap(); }); // Game tick event LK.on('tick', function () { var currentTime = Date.now(); if (currentTime - lastPipeTime > pipeInterval) { addPipe(); lastPipeTime = currentTime; } bird.update(); updatePipes(); checkCollision(); // Update clouds for (var i = clouds.length - 1; i >= 0; i--) { clouds[i].move(); if (clouds[i].x < -200) { clouds[i].x = 2048; clouds[i].y = Math.random() * 2732; } } });
===================================================================
--- original.js
+++ change.js
@@ -27,8 +27,20 @@
self.velocity = 0;
}
};
});
+// Cloud class
+var Cloud = Container.expand(function () {
+ var self = Container.call(this);
+ var cloudGraphics = self.attachAsset('cloud', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -2;
+ self.move = function () {
+ self.x += self.speed;
+ };
+});
// Pipe class
var Pipe = Container.expand(function (isTop, height) {
var self = Container.call(this);
var pipeGraphics = self.attachAsset(isTop ? 'pipeTop' : 'pipeBottom', {
@@ -60,8 +72,17 @@
bird.x = 2048 / 4;
bird.y = 2732 / 2;
game.addChild(bird);
}
+// Initialize clouds
+var clouds = [];
+for (var i = 0; i < 5; i++) {
+ var cloud = new Cloud();
+ cloud.x = Math.random() * 2048;
+ cloud.y = Math.random() * 2732;
+ clouds.push(cloud);
+ game.addChild(cloud);
+}
// Function to add pipes
function addPipe() {
var topPipeHeight = Math.floor(Math.random() * (2732 - gap)) + 100; // Random height for top pipe
var bottomPipeHeight = 2732 - topPipeHeight - gap;
@@ -116,5 +137,13 @@
}
bird.update();
updatePipes();
checkCollision();
+ // Update clouds
+ for (var i = clouds.length - 1; i >= 0; i--) {
+ clouds[i].move();
+ if (clouds[i].x < -200) {
+ clouds[i].x = 2048;
+ clouds[i].y = Math.random() * 2732;
+ }
+ }
});
\ No newline at end of file
A yellow bird. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A green pipe facing upwards. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Clouds. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.