User prompt
Change back ground colour into black
User prompt
Change the back ground
User prompt
When the bird touch on top of the screen finish the game
User prompt
Increse the jump
User prompt
Increse the jump
User prompt
Deincrese the jump
User prompt
When the bird fall down finish the game
User prompt
Increse the jump
User prompt
Increse the jump
User prompt
Increse the jump
Initial prompt
Flappy bird
===================================================================
--- original.js
+++ change.js
@@ -1,91 +1,91 @@
-/****
+/****
* Classes
-****/
+****/
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Bird class to represent the player's character
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.flapStrength = -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;
- }
- };
- self.flap = function () {
- self.velocity = self.flapStrength;
- };
+ var self = Container.call(this);
+ var birdGraphics = self.attachAsset('bird', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocity = 0;
+ self.gravity = 0.5;
+ self.flapStrength = -15;
+ 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;
+ }
+ };
+ self.flap = function () {
+ self.velocity = self.flapStrength;
+ };
});
// Pipe class to represent obstacles
var Pipe = Container.expand(function () {
- var self = Container.call(this);
- var pipeGraphics = self.attachAsset('pipe', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = -5;
- self.update = function () {
- self.x += self.speed;
- if (self.x < -pipeGraphics.width / 2) {
- self.destroy();
- }
- };
+ var self = Container.call(this);
+ var pipeGraphics = self.attachAsset('pipe', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -5;
+ self.update = function () {
+ self.x += self.speed;
+ if (self.x < -pipeGraphics.width / 2) {
+ self.destroy();
+ }
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB // Sky blue background
+ backgroundColor: 0x87CEEB // Sky blue background
});
-/****
+/****
* Game Code
-****/
+****/
var bird = game.addChild(new Bird());
bird.x = 2048 / 4;
bird.y = 2732 / 2;
var pipes = [];
var score = 0;
var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff"
+ size: 150,
+ fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function spawnPipe() {
- var pipe = new Pipe();
- pipe.x = 2048 + pipe.width / 2;
- pipe.y = Math.random() * (2732 - 400) + 200;
- pipes.push(pipe);
- game.addChild(pipe);
+ var pipe = new Pipe();
+ pipe.x = 2048 + pipe.width / 2;
+ pipe.y = Math.random() * (2732 - 400) + 200;
+ pipes.push(pipe);
+ game.addChild(pipe);
}
game.down = function (x, y, obj) {
- bird.flap();
+ bird.flap();
};
game.update = function () {
- bird.update();
- for (var i = pipes.length - 1; i >= 0; i--) {
- pipes[i].update();
- if (bird.intersects(pipes[i])) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- if (pipes[i].x < bird.x && !pipes[i].scored) {
- score++;
- scoreTxt.setText(score);
- pipes[i].scored = true;
- }
- }
- if (LK.ticks % 90 == 0) {
- spawnPipe();
- }
+ bird.update();
+ for (var i = pipes.length - 1; i >= 0; i--) {
+ pipes[i].update();
+ if (bird.intersects(pipes[i])) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ if (pipes[i].x < bird.x && !pipes[i].scored) {
+ score++;
+ scoreTxt.setText(score);
+ pipes[i].scored = true;
+ }
+ }
+ if (LK.ticks % 90 == 0) {
+ spawnPipe();
+ }
};
\ No newline at end of file