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.
//Always include this, it helps AI's //@include('ai-support.js') XS.stageContainer.setBackgroundColor(0x008080); function game() { /** Entity Classes **/ 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); self.velocity = 0; //{1} self.gravity = 0.5; self.lift = -15; self.update = function() { //{2} self.velocity += self.gravity; self.y += self.velocity; if (self.y < 0) { self.y = 0; self.velocity = 0; //{3} } //{4} self.rotation = Math.atan(self.velocity / 10); }; //{5} self.flap = function() { self.velocity += self.lift; }; //{6} }); //{7} var Pipe = Container.expand(function() { var self = Container.call(this); //{8} self.passed = false; var topPipeGraphics = XS.getAsset('pipe', 'Top Pipe Graphics'); topPipeGraphics.anchor.set(0.5, 1); self.addChild(topPipeGraphics); var bottomPipeGraphics = XS.getAsset('pipe', 'Bottom Pipe Graphics'); bottomPipeGraphics.anchor.set(0.5, 0); self.addChild(bottomPipeGraphics); self.setGap = function(gapSize, gapPosition) { topPipeGraphics.y = gapPosition - gapSize / 2; bottomPipeGraphics.y = gapPosition + gapSize / 2; }; //{9} self.speed = -10; self.update = function() { //{10} self.x += self.speed; //{11} }; //{12} }); //{13} /** Main Class **/ var Ground = Container.expand(function() { var self = Container.call(this); //{14} var groundGraphics = XS.getAsset('ground', 'Ground Graphics'); groundGraphics.anchor.set(0, 0); self.addChild(groundGraphics); self.speed = -2; self.update = function() { //{15} self.x += self.speed; //{16} if (self.x <= -self.width / 2) { self.x = 0; } //{17} }; //{18} }); //{19} var FlappyFRVR = Container.expand(function() { var self = Container.call(this); //{20} var bird = self.addChild(new Bird()); bird.x = 2048 / 4; bird.y = 2732 / 2; //{21} var ground = self.addChild(new Ground()); ground.y = 2732; var pipes = []; 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); } //{22} function updatePipes() { for (var i = 0; i < pipes.length; i++) { //{23} pipes[i].update(); pipes[i].speed = -10 - score * 0.5; if (pipes[i].x < -stage.width) { self.removeChild(pipes[i]); //{24} pipes.splice(i, 1); i--; } //{25} } //{26} } //{27} function checkCollision() { for (var i = 0; i < pipes.length; i++) { //{28} if (bird.intersects(pipes[i])) { return true; } //{29} } //{30} return false; } //{31} function restartGame() { bird.y = 2732 / 2; //{32} bird.velocity = 0; for (var i = 0; i < pipes.length; i++) { //{33} self.removeChild(pipes[i]); //{34} } //{35} pipes = []; score = 0; scoreText.setText(score); //{36} } //{37} var spawnPipeInterval = XS.setInterval(spawnPipe, 2000); var score = 0; var scoreText = new Text2('0', { size: 150, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma", fill: "#ffffff" }); //{38} scoreText.anchor.set(0.5, 0); XS.gui.top.addChild(scoreText); XS.on('tick', function() { bird.update(); ground.update(); updatePipes(); if (checkCollision() || bird.y + bird.height / 2 >= ground.y) { XS.showGameOver(restartGame); } else { for (var i = 0; i < pipes.length; i++) { //{39} if (pipes[i].x + pipes[i].width / 2 < bird.x && !pipes[i].passed) { pipes[i].passed = true; score++; scoreText.setText(score); //{40} } //{41} } //{42} } //{43} }); //{44} stage.on('down', function() { bird.flap(); }); //{45} }); //{46} /** Initialize the 'main class' and attach it to stage **/ var flappyFRVR = new FlappyFRVR(); stage.addChild(flappyFRVR); function positionElements() { flappyFRVR.x = (stage.width - 2048) / 2; } //{47} positionElements(); XS.on('resize', positionElements); } //{48}
===================================================================
--- original.js
+++ change.js
@@ -21,8 +21,10 @@
if (self.y < 0) {
self.y = 0;
self.velocity = 0; //{3}
} //{4}
+
+ self.rotation = Math.atan(self.velocity / 10);
}; //{5}
self.flap = function() {
self.velocity += self.lift;