/**** * Classes ****/ // Assets will be automatically created and loaded during gameplay // Bird class var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = 0; self.gravity = 0.5; self.lift = -10; 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; } }; self.flap = function () { self.velocity = self.lift; }; }); // Pipe class var Pipe = Container.expand(function () { var self = Container.call(this); var topPipe = self.attachAsset('pipe', { anchorX: 0.5, anchorY: 1.0 }); var bottomPipe = self.attachAsset('pipe', { anchorX: 0.5, anchorY: 0.0 }); self.gap = 400; self.speed = 5; self.setPosition = function (x, y) { self.x = x; topPipe.y = y - self.gap / 2; bottomPipe.y = y + self.gap / 2; }; self.update = function () { self.x -= self.speed; if (self.x < -topPipe.width) { self.destroy(); } }; self.intersects = function (bird) { return bird.intersects(topPipe) || bird.intersects(bottomPipe); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ var bird; var pipes = []; var score = 0; var scoreTxt; function resetGame() { bird = game.addChild(new Bird()); bird.x = 722 / 4; bird.y = 722 / 2; pipes.forEach(function (pipe) { pipe.destroy(); }); pipes = []; score = 0; scoreTxt.setText(score); } function addPipe() { var pipe = game.addChild(new Pipe()); var pipeY = Math.random() * (2732 - 800) + 400; pipe.setPosition(2048 + pipe.width, pipeY); pipes.push(pipe); } function updateGame() { bird.update(); pipes.forEach(function (pipe) { pipe.update(); if (pipe.intersects(bird)) { LK.showGameOver(); } }); pipes = pipes.filter(function (pipe) { return pipe.x > -pipe.width; }); if (LK.ticks % 90 === 0) { addPipe(); } if (LK.ticks % 30 === 0) { score++; scoreTxt.setText(score); } } game.down = function (x, y, obj) { bird.flap(); }; game.update = updateGame; scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); resetGame();
===================================================================
--- original.js
+++ change.js
@@ -73,9 +73,9 @@
var scoreTxt;
function resetGame() {
bird = game.addChild(new Bird());
bird.x = 722 / 4;
- bird.y = 2732 / 2;
+ bird.y = 722 / 2;
pipes.forEach(function (pipe) {
pipe.destroy();
});
pipes = [];