/**** * Classes ****/ //<Write imports for supported plugins here> // Bird class to handle position, movement, and drawing var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); self.yVelocity = 0; self.gravity = 0.5; self.lift = -10; self.lastX = self.x; self.update = function () { self.yVelocity += self.gravity; self.y += self.yVelocity; if (self.y > 2732 - birdGraphics.height / 2) { self.y = 2732 - birdGraphics.height / 2; self.yVelocity = 0; } }; self.flap = function () { self.yVelocity = self.lift; LK.getSound('jump').play(); }; }); // Pipe class to handle position and movement var Pipe = Container.expand(function () { var self = Container.call(this); var pipeGraphicsTop = self.attachAsset('pipe', { anchorX: 0.5, anchorY: 1, height: (2732 - 400) / 2 }); var pipeGraphicsBottom = self.attachAsset('pipe', { anchorX: 0.5, anchorY: 0, height: (2732 - 400) / 2 }); pipeGraphicsBottom.y = pipeGraphicsTop.height; self.speed = -5; self.update = function () { self.x += self.speed; if (self.x < -pipeGraphicsTop.width / 2) { self.x = 2048 + pipeGraphicsTop.width / 2; pipeGraphicsTop.height = (2732 - 400) / 2; pipeGraphicsBottom.height = (2732 - 400) / 2; pipeGraphicsBottom.y = pipeGraphicsTop.height + 200; LK.getSound('score').play(); } }; }); // Create a Text2 object to display the score var ScoreText = Text2.expand(function () { var self = Text2.call(this, '0', { size: 150, fill: 0xFFFFFF }); self.anchor.set(0.5, 0); self.update = function () { self.setText(LK.getScore()); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xFFDAB9 // Peach background }); /**** * Game Code ****/ // Define assets for the bird and pipes var bird = game.addChild(new Bird()); bird.x = 2048 / 4; bird.y = 2732 / 2; var pipes = []; for (var i = 0; i < 3; i++) { var pipe = game.addChild(new Pipe()); pipe.x = 2048 + i * 700; pipe.y = Math.random() * (2732 - 400) + 200; pipes.push(pipe); } // Add the ScoreText object to the game GUI var scoreText = LK.gui.top.addChild(new ScoreText()); scoreText.x = 2048 / 2; scoreText.y = 50; game.down = function (x, y, obj) { bird.flap(); }; game.update = function () { bird.update(); for (var i = 0; i < pipes.length; i++) { pipes[i].update(); if (bird.intersects(pipes[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } else if (bird.x > pipes[i].x && bird.lastX <= pipes[i].x) { LK.setScore(LK.getScore() + 1); LK.getSound('score').play(); scoreText.update(); // Update the score text when the bird passes through a pipe } bird.lastX = bird.x; } // Update the ScoreText object every game tick scoreText.update(); if (bird.y >= 2732 - bird.height / 2) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } };
===================================================================
--- original.js
+++ change.js
@@ -46,10 +46,11 @@
self.update = function () {
self.x += self.speed;
if (self.x < -pipeGraphicsTop.width / 2) {
self.x = 2048 + pipeGraphicsTop.width / 2;
- pipeGraphicsTop.height = Math.random() * (2732 - 400) + 200;
- pipeGraphicsBottom.height = 2732 - pipeGraphicsTop.height - 200;
+ pipeGraphicsTop.height = (2732 - 400) / 2;
+ pipeGraphicsBottom.height = (2732 - 400) / 2;
+ pipeGraphicsBottom.y = pipeGraphicsTop.height + 200;
LK.getSound('score').play();
}
};
});