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 gameStarted = false;
var menuContainer = new Container();
game.addChild(menuContainer);
var titleTxt = new Text2('FLAPPY BIRD', {
size: 200,
fill: 0xFFFFFF
});
titleTxt.anchor.set(0.5, 0.5);
titleTxt.x = 1024;
titleTxt.y = 600;
menuContainer.addChild(titleTxt);
var instructionsTxt = new Text2('TAP TO FLAP', {
size: 120,
fill: 0xFFFFFF
});
instructionsTxt.anchor.set(0.5, 0.5);
instructionsTxt.x = 1024;
instructionsTxt.y = 1100;
menuContainer.addChild(instructionsTxt);
var tapToStartTxt = new Text2('TAP TO START', {
size: 100,
fill: 0xFFD700
});
tapToStartTxt.anchor.set(0.5, 0.5);
tapToStartTxt.x = 1024;
tapToStartTxt.y = 1500;
menuContainer.addChild(tapToStartTxt);
var bird = game.addChild(new Bird());
bird.x = 300;
bird.y = 1366;
bird.lastY = bird.y;
bird.lastWasCollidingWithPipe = false;
bird.visible = false;
var ground = game.addChild(new Ground());
ground.visible = false;
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);
scoreTxt.visible = false;
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);
levelTxt.visible = false;
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 (!gameStarted) {
gameStarted = true;
menuContainer.visible = false;
bird.visible = true;
ground.visible = true;
scoreTxt.visible = true;
levelTxt.visible = true;
bird.flap();
} else if (bird.isAlive) {
bird.flap();
}
};
game.update = function () {
if (!gameStarted) return;
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
@@ -94,14 +94,43 @@
/****
* Game Code
****/
+var gameStarted = false;
+var menuContainer = new Container();
+game.addChild(menuContainer);
+var titleTxt = new Text2('FLAPPY BIRD', {
+ size: 200,
+ fill: 0xFFFFFF
+});
+titleTxt.anchor.set(0.5, 0.5);
+titleTxt.x = 1024;
+titleTxt.y = 600;
+menuContainer.addChild(titleTxt);
+var instructionsTxt = new Text2('TAP TO FLAP', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+instructionsTxt.anchor.set(0.5, 0.5);
+instructionsTxt.x = 1024;
+instructionsTxt.y = 1100;
+menuContainer.addChild(instructionsTxt);
+var tapToStartTxt = new Text2('TAP TO START', {
+ size: 100,
+ fill: 0xFFD700
+});
+tapToStartTxt.anchor.set(0.5, 0.5);
+tapToStartTxt.x = 1024;
+tapToStartTxt.y = 1500;
+menuContainer.addChild(tapToStartTxt);
var bird = game.addChild(new Bird());
bird.x = 300;
bird.y = 1366;
bird.lastY = bird.y;
bird.lastWasCollidingWithPipe = false;
+bird.visible = false;
var ground = game.addChild(new Ground());
+ground.visible = false;
var pipes = [];
var coins = [];
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 200;
@@ -116,16 +145,18 @@
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.y = 20;
LK.gui.top.addChild(scoreTxt);
+scoreTxt.visible = false;
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);
+levelTxt.visible = false;
function spawnPipe() {
var minGapY = 400;
var maxGapY = 1800;
var randomGapY = minGapY + Math.random() * (maxGapY - minGapY);
@@ -145,13 +176,22 @@
newCoin.isCollected = false;
coins.push(newCoin);
}
game.down = function (x, y, obj) {
- if (bird.isAlive) {
+ if (!gameStarted) {
+ gameStarted = true;
+ menuContainer.visible = false;
+ bird.visible = true;
+ ground.visible = true;
+ scoreTxt.visible = true;
+ levelTxt.visible = true;
bird.flap();
+ } else if (bird.isAlive) {
+ bird.flap();
}
};
game.update = function () {
+ if (!gameStarted) return;
bird.update();
pipeSpawnTimer++;
var currentSpawnInterval = Math.max(120, pipeSpawnInterval - (currentLevel - 1) * 15);
if (pipeSpawnTimer >= currentSpawnInterval) {