User prompt
Have left and right obstacles spawn at random times
User prompt
Flip the initial orientation of the bird graphic
User prompt
Make sure the bird can only bounce on a wall if it's moving towards the wall
User prompt
Add obstacles to the left and right wall that moves from the top of the screen to the bottom of the screen
User prompt
When the bird bounce on a wall flip the bird graphic
User prompt
Make the background a light pastel blue
User prompt
Add x speed to the bird
User prompt
Set the initial bird speed to 10
User prompt
Make the bird fly back and forward between the walls, if the bird hit a wall it should bounce bounce and reverse direction
User prompt
Add a wall on the left and right side of the screen
User prompt
Remove the Wall class
User prompt
Remove wall related variables from the game
User prompt
Remove the wall spawning from the game
Initial prompt
Flap & Bounce
var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.createAsset('obstacle', 'Obstacle', .5, .5); self.speed = 5; self.move = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; } }; }); var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.createAsset('wall', 'Wall', .5, .5); }); var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.createAsset('bird', 'Bird character', .5, .5); birdGraphics.scale.x = -1; self.xSpeed = 5; self.ySpeed = 0; self.gravity = 0.5; self.lift = -15; self.flap = function () { self.ySpeed = self.lift; }; self.update = function () { self.ySpeed += self.gravity; self.y += self.ySpeed; self.x += self.xSpeed; if (self.y <= 0 || self.y >= 2732) { self.speed = -self.speed; } }; self.flip = function () { self.scale.x *= -1; }; }); var Game = Container.expand(function () { var self = Container.call(this); LK.stageContainer.setBackgroundColor(0xadd8e6); var bird = self.addChild(new Bird()); var leftWall = self.addChild(new Wall()); leftWall.x = 0; leftWall.y = 1366; var rightWall = self.addChild(new Wall()); rightWall.x = 2048; rightWall.y = 1366; var leftObstacle, rightObstacle; var leftObstacleSpawnTime = Math.floor(Math.random() * 60) + 60; var rightObstacleSpawnTime = Math.floor(Math.random() * 60) + 60; bird.x = 1024; bird.y = 1366; stage.on('down', function (obj) { bird.flap(); }); LK.on('tick', function () { bird.update(); if (LK.ticks == leftObstacleSpawnTime) { leftObstacle = self.addChild(new Obstacle()); leftObstacle.x = 0; leftObstacle.y = 0; leftObstacleSpawnTime += Math.floor(Math.random() * 60) + 60; } if (LK.ticks == rightObstacleSpawnTime) { rightObstacle = self.addChild(new Obstacle()); rightObstacle.x = 2048; rightObstacle.y = 0; rightObstacleSpawnTime += Math.floor(Math.random() * 60) + 60; } if (leftObstacle) leftObstacle.move(); if (rightObstacle) rightObstacle.move(); if (bird.intersects(leftWall) || bird.intersects(rightWall) || bird.intersects(leftObstacle) || bird.intersects(rightObstacle)) { bird.xSpeed = -bird.xSpeed; bird.flip(); } if (bird.y < 0 || bird.y > 2732) { LK.showGameOver(); } }); });
===================================================================
--- original.js
+++ change.js
@@ -45,23 +45,32 @@
leftWall.y = 1366;
var rightWall = self.addChild(new Wall());
rightWall.x = 2048;
rightWall.y = 1366;
- var leftObstacle = self.addChild(new Obstacle());
- leftObstacle.x = 0;
- leftObstacle.y = 0;
- var rightObstacle = self.addChild(new Obstacle());
- rightObstacle.x = 2048;
- rightObstacle.y = 0;
+ var leftObstacle, rightObstacle;
+ var leftObstacleSpawnTime = Math.floor(Math.random() * 60) + 60;
+ var rightObstacleSpawnTime = Math.floor(Math.random() * 60) + 60;
bird.x = 1024;
bird.y = 1366;
stage.on('down', function (obj) {
bird.flap();
});
LK.on('tick', function () {
bird.update();
- leftObstacle.move();
- rightObstacle.move();
+ if (LK.ticks == leftObstacleSpawnTime) {
+ leftObstacle = self.addChild(new Obstacle());
+ leftObstacle.x = 0;
+ leftObstacle.y = 0;
+ leftObstacleSpawnTime += Math.floor(Math.random() * 60) + 60;
+ }
+ if (LK.ticks == rightObstacleSpawnTime) {
+ rightObstacle = self.addChild(new Obstacle());
+ rightObstacle.x = 2048;
+ rightObstacle.y = 0;
+ rightObstacleSpawnTime += Math.floor(Math.random() * 60) + 60;
+ }
+ if (leftObstacle) leftObstacle.move();
+ if (rightObstacle) rightObstacle.move();
if (bird.intersects(leftWall) || bird.intersects(rightWall) || bird.intersects(leftObstacle) || bird.intersects(rightObstacle)) {
bird.xSpeed = -bird.xSpeed;
bird.flip();
}