User prompt
When updating score text also update LK.setScore
User prompt
Update the bird rotation code such that it animates to the new rotation over a few frames rather than snapping
User prompt
Change the bird angle based on if it's flying up or down.
User prompt
Make pipes spawn outside the right side of the full stage.width as well
User prompt
Spawn and remove pipes when they are outside the full stage.width area.
User prompt
Spawn pipes at z-index 0
User prompt
Make floor graphics be attached at 0.0
User prompt
Make background teal
User prompt
Increase column gab by 4x
User prompt
Make columns move 5x faster at the start, then increase column speed when increasing score.
User prompt
Progress the development of the game.
User prompt
Progress the development of the game.
User prompt
Progress the development of the game.
Initial prompt
Progress the development of the game.
/**** * Classes ****/ var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = LK.getAsset('bird', {}); birdGraphics.anchor.set(0.5, 0.5); self.addChild(birdGraphics); self.velocity = 0; self.gravity = 0.5; self.lift = -15; self.update = function () { self.velocity += self.gravity; self.y += self.velocity; if (self.y < 0) { self.y = 0; self.velocity = 0; } self.rotation += (Math.atan(self.velocity / 10) - self.rotation) * 0.1; }; self.flap = function () { self.velocity += self.lift; }; }); var Pipe = Container.expand(function () { var self = Container.call(this); self.passed = false; var topPipeGraphics = LK.getAsset('pipe', {}); topPipeGraphics.anchor.set(0.5, 1); self.addChild(topPipeGraphics); var bottomPipeGraphics = LK.getAsset('pipe', {}); bottomPipeGraphics.anchor.set(0.5, 0); self.addChild(bottomPipeGraphics); self.setGap = function (gapSize, gapPosition) { topPipeGraphics.y = gapPosition - gapSize / 2; bottomPipeGraphics.y = gapPosition + gapSize / 2; }; self.speed = -10; self.update = function () { self.x += self.speed; }; }); var Ground = Container.expand(function () { var self = Container.call(this); var groundGraphics = LK.getAsset('ground', {}); groundGraphics.anchor.set(0, 0); self.addChild(groundGraphics); self.speed = -2; self.update = function () { self.x += self.speed; if (self.x <= -self.width / 2) { self.x = 0; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ game.setBackgroundColor(0x008080); var bird = game.addChild(new Bird()); bird.x = 2048 / 4; bird.y = 2732 / 2; var ground = game.addChild(new Ground()); ground.y = 2732; var pipes = []; function spawnPipe() { var pipe = new Pipe(); pipe.x = game.width; var gapPosition = Math.random() * (2732 - 400) + 200; pipe.setGap(1200, gapPosition); pipes.push(pipe); game.addChildAt(pipe, 0); } function updatePipes() { for (var i = 0; i < pipes.length; i++) { pipes[i].update(); pipes[i].speed = -10 - score * 0.5; if (pipes[i].x < -game.width) { game.removeChild(pipes[i]); pipes.splice(i, 1); i--; } } } function checkCollision() { for (var i = 0; i < pipes.length; i++) { if (bird.intersects(pipes[i])) { return true; } } return false; } function restartGame() { bird.y = 2732 / 2; bird.velocity = 0; for (var i = 0; i < pipes.length; i++) { game.removeChild(pipes[i]); } pipes = []; score = 0; scoreText.setText(score); } var spawnPipeInterval = LK.setInterval(spawnPipe, 2000); var score = 0; var scoreText = new Text2('0', { size: 150, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma", fill: "#ffffff" }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); LK.on('tick', function () { bird.update(); ground.update(); updatePipes(); if (checkCollision() || bird.y + bird.height / 2 >= ground.y) { LK.showGameOver(restartGame); } else { for (var i = 0; i < pipes.length; i++) { if (pipes[i].x + pipes[i].width / 2 < bird.x && !pipes[i].passed) { pipes[i].passed = true; score++; LK.setScore(score); scoreText.setText(score); } } } }); game.on('down', function () { bird.flap(); });
===================================================================
--- original.js
+++ change.js
@@ -1,156 +1,139 @@
-var Bird = Container.expand(function() {
- var self = Container.call(this); //{0}
- var birdGraphics = XS.getAsset('bird', 'Flappy Bird');
- birdGraphics.anchor.set(0.5, 0.5);
- self.addChild(birdGraphics);
- //{1}
- self.velocity = 0; //{2}
- self.gravity = 0.5;
- self.lift = -15;
- //{3}
- self.update = function() { //{4}
- self.velocity += self.gravity;
- self.y += self.velocity;
- //{5}
- if (self.y < 0) {
- self.y = 0;
- self.velocity = 0; //{6}
- } //{7}
- //{8}
- self.rotation += (Math.atan(self.velocity / 10) - self.rotation) * 0.1;
- }; //{9}
- //{10}
- self.flap = function() {
- self.velocity += self.lift;
- }; //{11}
-}); //{12}
-//{13}
-var Pipe = Container.expand(function() {
- var self = Container.call(this); //{14}
- self.passed = false;
- var topPipeGraphics = XS.getAsset('pipe', 'Top Pipe Graphics');
- topPipeGraphics.anchor.set(0.5, 1);
- self.addChild(topPipeGraphics);
- //{15}
- var bottomPipeGraphics = XS.getAsset('pipe', 'Bottom Pipe Graphics');
- bottomPipeGraphics.anchor.set(0.5, 0);
- self.addChild(bottomPipeGraphics);
- //{16}
- self.setGap = function(gapSize, gapPosition) {
- topPipeGraphics.y = gapPosition - gapSize / 2;
- bottomPipeGraphics.y = gapPosition + gapSize / 2;
- }; //{17}
- //{18}
- self.speed = -10;
- //{19}
- self.update = function() { //{20}
- self.x += self.speed; //{21}
- }; //{22}
-}); //{23}
-//{24}
-var Ground = Container.expand(function() {
- var self = Container.call(this); //{25}
- var groundGraphics = XS.getAsset('ground', 'Ground Graphics');
- groundGraphics.anchor.set(0, 0);
- self.addChild(groundGraphics);
- //{26}
- self.speed = -2;
- //{27}
- self.update = function() { //{28}
- self.x += self.speed; //{29}
- if (self.x <= -self.width / 2) {
- self.x = 0;
- } //{30}
- }; //{31}
-}); //{32}
-//{33}
-var Game = Container.expand(function() {
- var self = Container.call(this); //{34}
- //{35}
- XS.stageContainer.setBackgroundColor(0x008080);
- //{36}
- var bird = self.addChild(new Bird());
- bird.x = 2048 / 4;
- bird.y = 2732 / 2; //{37}
- //{38}
- var ground = self.addChild(new Ground());
- ground.y = 2732;
- //{39}
- var pipes = [];
- //{40}
- function spawnPipe() {
- var pipe = new Pipe();
- pipe.x = stage.width;
- var gapPosition = Math.random() * (2732 - 400) + 200;
- pipe.setGap(1200, gapPosition);
- pipes.push(pipe);
- self.addChildAt(pipe, 0);
- } //{41}
- //{42}
- function updatePipes() {
- for (var i = 0; i < pipes.length; i++) { //{43}
- pipes[i].update();
- pipes[i].speed = -10 - score * 0.5;
- //{44}
- if (pipes[i].x < -stage.width) {
- self.removeChild(pipes[i]); //{45}
- pipes.splice(i, 1);
- i--;
- } //{46}
- } //{47}
- } //{48}
- //{49}
- function checkCollision() {
- for (var i = 0; i < pipes.length; i++) { //{50}
- if (bird.intersects(pipes[i])) {
- return true;
- } //{51}
- } //{52}
- return false;
- } //{53}
- //{54}
- function restartGame() {
- bird.y = 2732 / 2; //{55}
- bird.velocity = 0;
- //{56}
- for (var i = 0; i < pipes.length; i++) { //{57}
- self.removeChild(pipes[i]); //{58}
- } //{59}
- pipes = [];
- score = 0;
- scoreText.setText(score); //{60}
- } //{61}
- //{62}
- var spawnPipeInterval = XS.setInterval(spawnPipe, 2000);
- //{63}
- var score = 0;
- var scoreText = new Text2('0', {
- size: 150,
- font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
- fill: "#ffffff"
- }); //{64}
- scoreText.anchor.set(0.5, 0);
- XS.gui.top.addChild(scoreText);
- //{65}
- XS.on('tick', function() {
- bird.update();
- ground.update();
- updatePipes();
- //{66}
- if (checkCollision() || bird.y + bird.height / 2 >= ground.y) {
- XS.showGameOver(restartGame);
- } else {
- for (var i = 0; i < pipes.length; i++) { //{67}
- if (pipes[i].x + pipes[i].width / 2 < bird.x && !pipes[i].passed) {
- pipes[i].passed = true;
- score++;
- scoreText.setText(score); //{68}
- } //{69}
- } //{70}
- } //{71}
- }); //{72}
- //{73}
- stage.on('down', function() {
- bird.flap();
- }); //{74}
-}); //{75}
\ No newline at end of file
+/****
+* Classes
+****/
+var Bird = Container.expand(function () {
+ var self = Container.call(this);
+ var birdGraphics = LK.getAsset('bird', {});
+ birdGraphics.anchor.set(0.5, 0.5);
+ self.addChild(birdGraphics);
+ self.velocity = 0;
+ self.gravity = 0.5;
+ self.lift = -15;
+ self.update = function () {
+ self.velocity += self.gravity;
+ self.y += self.velocity;
+ if (self.y < 0) {
+ self.y = 0;
+ self.velocity = 0;
+ }
+ self.rotation += (Math.atan(self.velocity / 10) - self.rotation) * 0.1;
+ };
+ self.flap = function () {
+ self.velocity += self.lift;
+ };
+});
+var Pipe = Container.expand(function () {
+ var self = Container.call(this);
+ self.passed = false;
+ var topPipeGraphics = LK.getAsset('pipe', {});
+ topPipeGraphics.anchor.set(0.5, 1);
+ self.addChild(topPipeGraphics);
+ var bottomPipeGraphics = LK.getAsset('pipe', {});
+ bottomPipeGraphics.anchor.set(0.5, 0);
+ self.addChild(bottomPipeGraphics);
+ self.setGap = function (gapSize, gapPosition) {
+ topPipeGraphics.y = gapPosition - gapSize / 2;
+ bottomPipeGraphics.y = gapPosition + gapSize / 2;
+ };
+ self.speed = -10;
+ self.update = function () {
+ self.x += self.speed;
+ };
+});
+var Ground = Container.expand(function () {
+ var self = Container.call(this);
+ var groundGraphics = LK.getAsset('ground', {});
+ groundGraphics.anchor.set(0, 0);
+ self.addChild(groundGraphics);
+ self.speed = -2;
+ self.update = function () {
+ self.x += self.speed;
+ if (self.x <= -self.width / 2) {
+ self.x = 0;
+ }
+ };
+});
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+game.setBackgroundColor(0x008080);
+var bird = game.addChild(new Bird());
+bird.x = 2048 / 4;
+bird.y = 2732 / 2;
+var ground = game.addChild(new Ground());
+ground.y = 2732;
+var pipes = [];
+function spawnPipe() {
+ var pipe = new Pipe();
+ pipe.x = game.width;
+ var gapPosition = Math.random() * (2732 - 400) + 200;
+ pipe.setGap(1200, gapPosition);
+ pipes.push(pipe);
+ game.addChildAt(pipe, 0);
+}
+function updatePipes() {
+ for (var i = 0; i < pipes.length; i++) {
+ pipes[i].update();
+ pipes[i].speed = -10 - score * 0.5;
+ if (pipes[i].x < -game.width) {
+ game.removeChild(pipes[i]);
+ pipes.splice(i, 1);
+ i--;
+ }
+ }
+}
+function checkCollision() {
+ for (var i = 0; i < pipes.length; i++) {
+ if (bird.intersects(pipes[i])) {
+ return true;
+ }
+ }
+ return false;
+}
+function restartGame() {
+ bird.y = 2732 / 2;
+ bird.velocity = 0;
+ for (var i = 0; i < pipes.length; i++) {
+ game.removeChild(pipes[i]);
+ }
+ pipes = [];
+ score = 0;
+ scoreText.setText(score);
+}
+var spawnPipeInterval = LK.setInterval(spawnPipe, 2000);
+var score = 0;
+var scoreText = new Text2('0', {
+ size: 150,
+ font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
+ fill: "#ffffff"
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+LK.on('tick', function () {
+ bird.update();
+ ground.update();
+ updatePipes();
+ if (checkCollision() || bird.y + bird.height / 2 >= ground.y) {
+ LK.showGameOver(restartGame);
+ } else {
+ for (var i = 0; i < pipes.length; i++) {
+ if (pipes[i].x + pipes[i].width / 2 < bird.x && !pipes[i].passed) {
+ pipes[i].passed = true;
+ score++;
+ LK.setScore(score);
+ scoreText.setText(score);
+ }
+ }
+ }
+});
+game.on('down', function () {
+ bird.flap();
+});
\ No newline at end of file