User prompt
Let's make the menu and the background of the game more beautiful
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var ub = 0; ub < unlockedBirds.length; ub++) {' Line Number: 180 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var ub = 0; ub < unlockedBirds.length; ub++) {' Line Number: 180 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Let's open new birds with the points we collect. Do this. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
make the level is hards
User prompt
Let the game pause in the menu
User prompt
make the level buttons
User prompt
make the menu
User prompt
make the coins
User prompt
make the point
User prompt
MAKE THE PHYSİCY
User prompt
make the level
Code edit (1 edits merged)
Please save this source code
User prompt
Flappy Bird
Initial prompt
make me flappy bird
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 0.6;
self.flapPower = -12;
self.isAlive = true;
self.flap = function () {
self.velocityY = self.flapPower;
LK.getSound('flap').play();
};
self.update = function () {
if (!self.isAlive) return;
self.velocityY += self.gravity;
self.lastY = self.y;
self.y += self.velocityY;
if (self.lastY - 25 >= 0 && self.y - 25 < 0) {
self.isAlive = false;
LK.showGameOver();
}
if (self.y - 25 < 0) {
self.y = 25;
self.velocityY = 0;
}
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -6;
self.isCollected = false;
self.update = function () {
self.x += self.speed;
};
return self;
});
var Ground = Container.expand(function () {
var self = Container.call(this);
var groundGraphics = self.attachAsset('ground', {
anchorX: 0,
anchorY: 0
});
self.x = 0;
self.y = 2582;
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
self.speed = -6;
self.gapSize = 250;
self.hasBeenScored = false;
var topPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 1
});
var bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0
});
self.setup = function (gapY) {
self.gapY = gapY;
topPipe.y = gapY - self.gapSize / 2;
bottomPipe.y = gapY + self.gapSize / 2;
topPipe.x = 50;
bottomPipe.x = 50;
};
self.update = function () {
self.x += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var bird = game.addChild(new Bird());
bird.x = 300;
bird.y = 1366;
bird.lastY = bird.y;
bird.lastWasCollidingWithPipe = false;
var ground = game.addChild(new Ground());
var pipes = [];
var coins = [];
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 200;
var nextGapPosition = 0;
var currentLevel = 1;
var pipsPassedInLevel = 0;
var pipsRequiredToLevelUp = 5;
var coinsCollected = 0;
var scoreTxt = new Text2('Score: 0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.y = 20;
LK.gui.top.addChild(scoreTxt);
var gameScore = 0;
var levelTxt = new Text2('Level 1', {
size: 100,
fill: 0xFFFFFF
});
levelTxt.anchor.set(0.5, 0);
levelTxt.y = 150;
LK.gui.top.addChild(levelTxt);
function spawnPipe() {
var minGapY = 400;
var maxGapY = 1800;
var randomGapY = minGapY + Math.random() * (maxGapY - minGapY);
var newPipe = game.addChild(new Pipe());
newPipe.x = 2048 + 100;
var basePipeGapSize = newPipe.gapSize;
newPipe.gapSize = Math.max(150, basePipeGapSize - (currentLevel - 1) * 15);
newPipe.setup(randomGapY);
newPipe.lastX = newPipe.x;
newPipe.hasBeenScored = false;
pipes.push(newPipe);
var coinOffset = (Math.random() - 0.5) * 150;
var newCoin = game.addChild(new Coin());
newCoin.x = newPipe.x;
newCoin.y = randomGapY + coinOffset;
newCoin.lastX = newCoin.x;
newCoin.isCollected = false;
coins.push(newCoin);
}
game.down = function (x, y, obj) {
if (bird.isAlive) {
bird.flap();
}
};
game.update = function () {
bird.update();
pipeSpawnTimer++;
var currentSpawnInterval = Math.max(120, pipeSpawnInterval - (currentLevel - 1) * 15);
if (pipeSpawnTimer >= currentSpawnInterval) {
spawnPipe();
pipeSpawnTimer = 0;
}
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
coin.update();
if (!coin.lastX) coin.lastX = coin.x;
if (coin.x < -100) {
coin.destroy();
coins.splice(i, 1);
}
if (bird.isAlive && !coin.isCollected) {
var coinCollisionDistance = Math.sqrt((bird.x - coin.x) * (bird.x - coin.x) + (bird.y - coin.y) * (bird.y - coin.y));
if (coinCollisionDistance < 50) {
coin.isCollected = true;
coinsCollected++;
LK.getSound('coin').play();
coin.destroy();
coins.splice(i, 1);
}
}
}
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
pipe.update();
if (!pipe.lastX) pipe.lastX = pipe.x;
if (pipe.lastX > 300 && pipe.x <= 300 && !pipe.hasBeenScored) {
pipe.hasBeenScored = true;
gameScore++;
LK.setScore(gameScore);
pipsPassedInLevel++;
scoreTxt.setText('Score: ' + gameScore);
LK.getSound('score').play();
if (pipsPassedInLevel >= pipsRequiredToLevelUp) {
currentLevel++;
pipsPassedInLevel = 0;
levelTxt.setText('Level ' + currentLevel);
}
}
pipe.lastX = pipe.x;
if (pipe.x < -150) {
pipe.destroy();
pipes.splice(i, 1);
}
if (bird.isAlive && bird.lastWasCollidingWithPipe === undefined) {
bird.lastWasCollidingWithPipe = false;
}
if (bird.isAlive) {
var birdLeft = bird.x - 25;
var birdRight = bird.x + 25;
var birdTop = bird.y - 25;
var birdBottom = bird.y + 25;
var pipeLeft = pipe.x - 50;
var pipeRight = pipe.x + 50;
var isCollidingNow = false;
if (birdRight > pipeLeft && birdLeft < pipeRight) {
if (birdTop < pipe.gapY - pipe.gapSize / 2 || birdBottom > pipe.gapY + pipe.gapSize / 2) {
isCollidingNow = true;
}
}
if (!bird.lastWasCollidingWithPipe && isCollidingNow) {
bird.isAlive = false;
LK.showGameOver();
}
bird.lastWasCollidingWithPipe = isCollidingNow;
}
}
};
LK.playMusic('bgmusic', {
loop: true
}); ===================================================================
--- original.js
+++ change.js
@@ -35,8 +35,21 @@
}
};
return self;
});
+var Coin = Container.expand(function () {
+ var self = Container.call(this);
+ var coinGraphics = self.attachAsset('coin', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -6;
+ self.isCollected = false;
+ self.update = function () {
+ self.x += self.speed;
+ };
+ return self;
+});
var Ground = Container.expand(function () {
var self = Container.call(this);
var groundGraphics = self.attachAsset('ground', {
anchorX: 0,
@@ -88,14 +101,16 @@
bird.lastY = bird.y;
bird.lastWasCollidingWithPipe = false;
var ground = game.addChild(new Ground());
var pipes = [];
+var coins = [];
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 200;
var nextGapPosition = 0;
var currentLevel = 1;
var pipsPassedInLevel = 0;
var pipsRequiredToLevelUp = 5;
+var coinsCollected = 0;
var scoreTxt = new Text2('Score: 0', {
size: 120,
fill: 0xFFFFFF
});
@@ -121,8 +136,15 @@
newPipe.setup(randomGapY);
newPipe.lastX = newPipe.x;
newPipe.hasBeenScored = false;
pipes.push(newPipe);
+ var coinOffset = (Math.random() - 0.5) * 150;
+ var newCoin = game.addChild(new Coin());
+ newCoin.x = newPipe.x;
+ newCoin.y = randomGapY + coinOffset;
+ newCoin.lastX = newCoin.x;
+ newCoin.isCollected = false;
+ coins.push(newCoin);
}
game.down = function (x, y, obj) {
if (bird.isAlive) {
bird.flap();
@@ -135,8 +157,27 @@
if (pipeSpawnTimer >= currentSpawnInterval) {
spawnPipe();
pipeSpawnTimer = 0;
}
+ for (var i = coins.length - 1; i >= 0; i--) {
+ var coin = coins[i];
+ coin.update();
+ if (!coin.lastX) coin.lastX = coin.x;
+ if (coin.x < -100) {
+ coin.destroy();
+ coins.splice(i, 1);
+ }
+ if (bird.isAlive && !coin.isCollected) {
+ var coinCollisionDistance = Math.sqrt((bird.x - coin.x) * (bird.x - coin.x) + (bird.y - coin.y) * (bird.y - coin.y));
+ if (coinCollisionDistance < 50) {
+ coin.isCollected = true;
+ coinsCollected++;
+ LK.getSound('coin').play();
+ coin.destroy();
+ coins.splice(i, 1);
+ }
+ }
+ }
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
pipe.update();
if (!pipe.lastX) pipe.lastX = pipe.x;