Code edit (9 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Flappy Bird
User prompt
Create a simple 2D Flappy Bird-style game. Game requirements: - The player controls a small bird that continuously falls due to gravity. - Pressing spacebar or tapping makes the bird jump upward. - Obstacles (pipes) move from right to left across the screen. - Each pipe has a gap that the bird must pass through. - If the bird hits a pipe or the ground, the game ends. - Score increases each time the bird successfully passes a pipe. Game features: - Start screen with "Tap or Press Space to Start" - Game over screen with final score and restart option - Smooth animations and simple physics (gravity and jump) - Randomized pipe heights for difficulty - Clean, colorful 2D graphics Technical requirements: - Use simple and readable code - Include comments explaining the logic - Use basic physics for movement - Keep everything beginner-friendly Optional enhancements: - Add sound effects for jump and collision - Add background scrolling - Increase difficulty over time
User prompt
Please continue polishing my design document.
Initial prompt
Create a simple 2D Flappy Bird-style game. Game requirements: - The player controls a small bird that continuously falls due to gravity. - Pressing spacebar or tapping makes the bird jump upward. - Obstacles (pipes) move from right to left across the screen. - Each pipe has a gap that the bird must pass through. - If the bird hits a pipe or the ground, the game ends. - Score increases each time the bird successfully passes a pipe. Game features: - Start screen with "Tap or Press Space to Start" - Game over screen with final score and restart option - Smooth animations and simple physics (gravity and jump) - Randomized pipe heights for difficulty - Clean, colorful 2D graphics Technical requirements: - Use simple and readable code - Include comments explaining the logic - Use basic physics for movement - Keep everything beginner-friendly Optional enhancements: - Add sound effects for jump and collision - Add background scrolling - Increase difficulty over time
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// β
UPDATED BIRD (SMOOTH MOTION)
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.4;
self.jumpPower = -15;
self.maxFallSpeed = 20;
// Smooth rotation settings
self.rotationSmooth = 0.1;
self.maxRotationDown = 1.2;
self.maxRotationUp = -0.5;
self.jump = function () {
self.velocityY = self.jumpPower;
// instant tilt upward
birdGraphics.rotation = -0.3;
LK.getSound('jump').play();
};
self.update = function () {
self.velocityY += self.gravity;
if (self.velocityY > self.maxFallSpeed) {
self.velocityY = self.maxFallSpeed;
}
self.y += self.velocityY;
// Smooth rotation
var targetRotation = self.velocityY * 0.05;
if (targetRotation > self.maxRotationDown) {
targetRotation = self.maxRotationDown;
}
if (targetRotation < self.maxRotationUp) {
targetRotation = self.maxRotationUp;
}
birdGraphics.rotation += (targetRotation - birdGraphics.rotation) * self.rotationSmooth;
};
return self;
});
// π« UNCHANGED
var Pipe = Container.expand(function () {
var self = Container.call(this);
self.speed = -8;
self.gapHeight = 500;
self.pipeWidth = 150;
self.scored = false;
var topPipe = self.attachAsset('pipeTop', {
anchorX: 0.5,
anchorY: 0.5
});
var bottomPipe = self.attachAsset('pipeBottom', {
anchorX: 0.5,
anchorY: 0.5
});
self.setPipeGap = function (gapY) {
var topPipeHeight = gapY - self.gapHeight / 2;
var bottomPipeY = gapY + self.gapHeight / 2;
var bottomPipeHeight = 2732 - bottomPipeY;
topPipe.height = Math.max(100, topPipeHeight);
topPipe.y = topPipe.height / 2;
bottomPipe.height = Math.max(100, bottomPipeHeight);
bottomPipe.y = bottomPipeY + bottomPipe.height / 2;
};
self.update = function () {
self.x += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var bird;
var pipes = [];
var gameStarted = false;
var gameOver = false;
var score = 0;
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 120;
var difficultyTimer = 0;
var backgroundGraphic = LK.getAsset('background', {
anchorX: 0,
anchorY: 0
});
game.addChild(backgroundGraphic);
var groundGraphic = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
}));
groundGraphic.y = 2732 - 100;
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.setText('0');
LK.gui.top.addChild(scoreTxt);
var startTxt = new Text2('Tap to Start', {
size: 80,
fill: 0xFFFFFF
});
startTxt.anchor.set(0.5, 0.5);
startTxt.x = 1024;
startTxt.y = 1366;
game.addChild(startTxt);
function initGame() {
bird = game.addChild(new Bird());
bird.x = 300;
bird.y = 1366;
bird.velocityY = 0;
gameStarted = true;
gameOver = false;
score = 0;
pipes = [];
pipeSpawnTimer = 0;
difficultyTimer = 0;
scoreTxt.setText('0');
startTxt.visible = false;
LK.playMusic('bgmusic', {
loop: true
});
}
function spawnPipe() {
var minGapY = 300;
var maxGapY = 2200;
var gapY = minGapY + Math.random() * (maxGapY - minGapY);
var pipe = game.addChild(new Pipe());
pipe.x = 2048 + 100;
pipe.y = 0;
pipe.setPipeGap(gapY);
pipes.push(pipe);
}
game.down = function (x, y, obj) {
if (!gameStarted) {
initGame();
} else if (!gameOver && bird) {
bird.jump();
}
};
game.update = function () {
if (!gameStarted) {
return;
}
if (gameOver) {
return;
}
if (bird) {
bird.update();
if (bird.y - 25 < 0 || bird.y + 25 > 2732 - 100) {
gameOver = true;
LK.getSound('collision').play();
LK.showGameOver();
return;
}
}
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeSpawnInterval) {
spawnPipe();
pipeSpawnTimer = 0;
}
difficultyTimer++;
if (difficultyTimer > 0 && difficultyTimer % 600 === 0) {
pipeSpawnInterval = Math.max(90, pipeSpawnInterval - 5);
}
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
pipe.update();
if (bird && bird.intersects(pipe)) {
gameOver = true;
LK.getSound('collision').play();
LK.showGameOver();
return;
}
if (bird && !pipe.scored && bird.x > pipe.x) {
pipe.scored = true;
score++;
LK.setScore(score);
scoreTxt.setText(String(score));
}
if (pipe.x < -200) {
pipe.destroy();
pipes.splice(i, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -5,37 +5,52 @@
/****
* Classes
****/
+// β
UPDATED BIRD (SMOOTH MOTION)
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.gravity = 0.4;
self.jumpPower = -15;
self.maxFallSpeed = 20;
+ // Smooth rotation settings
+ self.rotationSmooth = 0.1;
+ self.maxRotationDown = 1.2;
+ self.maxRotationUp = -0.5;
self.jump = function () {
self.velocityY = self.jumpPower;
+ // instant tilt upward
+ birdGraphics.rotation = -0.3;
LK.getSound('jump').play();
};
self.update = function () {
self.velocityY += self.gravity;
if (self.velocityY > self.maxFallSpeed) {
self.velocityY = self.maxFallSpeed;
}
self.y += self.velocityY;
- var rotation = Math.min(self.velocityY * 0.05, 0.5);
- birdGraphics.rotation = rotation;
+ // Smooth rotation
+ var targetRotation = self.velocityY * 0.05;
+ if (targetRotation > self.maxRotationDown) {
+ targetRotation = self.maxRotationDown;
+ }
+ if (targetRotation < self.maxRotationUp) {
+ targetRotation = self.maxRotationUp;
+ }
+ birdGraphics.rotation += (targetRotation - birdGraphics.rotation) * self.rotationSmooth;
};
return self;
});
+// π« UNCHANGED
var Pipe = Container.expand(function () {
var self = Container.call(this);
self.speed = -8;
- self.gapHeight = 200;
+ self.gapHeight = 500;
self.pipeWidth = 150;
self.scored = false;
var topPipe = self.attachAsset('pipeTop', {
anchorX: 0.5,