Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
add score system on top right on crossing in pipe score increase by one and if bird touch pipe op ground game got over and shows play again option
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'addEventListener')' in or related to this line: 'game.view.addEventListener('mousedown', jumpBird);' Line Number: 126
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'addEventListener')' in or related to this line: 'game.view.addEventListener('mousedown', jumpBird);' Line Number: 131
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'addEventListener')' in or related to this line: 'game.view.addEventListener('mousedown', jumpBird);' Line Number: 131
Code edit (1 edits merged)
Please save this source code
User prompt
Create a complete set of 2D game assets for a Flappy Bird-style game. Style: cartoon, colorful, simple, clean, vector-friendly, game-ready, transparent background. 1. Bird: - Name: "bird" - Shape: cute, round oval - Color: bright blue - Pose: facing right, wings slightly open as if flapping - Expression: cheerful and lively 2. Pipe: - Name: "pipe" - Shape: vertical cylinder with rounded edges - Color: bright green - Top and bottom ends: flat - Tall enough to create vertical gaps for gameplay 3. Background: - Name: "background" - Theme: sky with clouds, bright and cheerful - Horizon line low - Colors: blue sky, white clouds 4. Ground: - Name: "ground" - Color: earthy brown/green - Shape: simple flat layer - Texture: subtle grass or dirt 5. UI Elements: - Name: "scoreTxt" - Style: bold, cartoon font - Color: white with subtle shadow for contrast 6. Optional extras: - Name: "startButton" - Shape: round or rectangle - Color: bright, easy to see - Text: "Start" - Name: "restartButton" - Shape: round or rectangle - Color: bright, easy to see - Text: "Restart" Make sure all assets have transparent backgrounds (except background image), are visually consistent in style, and suitable for a 2D side-scrolling game.
Initial prompt
Please save this source code
/****
* Initialize Game
****/
/**** Initialize Game ****/
var game = new LK.Game({
backgroundColor: 0x70c5ce
});
/****
* Game Code
****/
/**** Background ****/
var bg = LK.getAsset('background', {
x: 0,
y: 0
});
game.addChild(bg);
var ground = LK.getAsset('ground', {
x: 0,
y: 2532
});
game.addChild(ground);
var groundDirt = LK.getAsset('groundDirt', {
x: 0,
y: 2672
});
game.addChild(groundDirt);
/**** Bird ****/
var bird = new Container();
bird.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
bird.x = 400;
bird.y = 800;
game.addChild(bird);
var velocity = 0;
var gravity = 0.8;
var jump = -15;
var maxFall = 20;
/**** Pipes ****/
var pipes = [];
var pipeGap = 400;
var pipeSpeed = 10;
/**** Score ****/
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(1, 0);
scoreTxt.x = 1950;
scoreTxt.y = 50;
LK.gui.top.addChild(scoreTxt);
/**** Game Over Text ****/
var gameOverTxt = new Text2('GAME OVER', {
size: 120,
fill: 0xff0000
});
gameOverTxt.anchor.set(0.5);
gameOverTxt.x = 1024;
gameOverTxt.y = 900;
gameOverTxt.visible = false;
LK.gui.center.addChild(gameOverTxt);
/**** Restart Button ****/
var restartButton = LK.getAsset('restartButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1300
});
restartButton.visible = false;
restartButton.interactive = true;
restartButton.on('pointerdown', resetGame);
LK.gui.center.addChild(restartButton);
/**** Spawn Pipes ****/
function spawnPipes() {
var gapY = 500 + Math.random() * 1000;
var topPipe = new Container();
topPipe.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 1
});
topPipe.x = 2200;
topPipe.y = gapY - pipeGap / 2;
var bottomPipe = new Container();
bottomPipe.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0
});
bottomPipe.x = 2200;
bottomPipe.y = gapY + pipeGap / 2;
topPipe.passed = false;
game.addChild(topPipe);
game.addChild(bottomPipe);
pipes.push({
top: topPipe,
bottom: bottomPipe
});
}
/**** Collision ****/
function hitTest(bird, pipe) {
return bird.x + 50 > pipe.x - pipe.width / 2 && bird.x - 50 < pipe.x + pipe.width / 2 && bird.y + 40 > pipe.y - pipe.height * pipe.anchorY && bird.y - 40 < pipe.y + pipe.height * (1 - pipe.anchorY);
}
/**** Controls ****/
game.down = function () {
if (gameOver) return;
velocity = jump;
};
/**** Game Loop ****/
var frame = 0;
var gameOver = false;
game.update = function () {
if (gameOver) return;
// Gravity
velocity += gravity;
if (velocity > maxFall) velocity = maxFall;
bird.y += velocity;
// Rotation
bird.rotation = velocity * 0.05;
// Ground & ceiling
if (bird.y > 2600) {
bird.y = 2600;
endGame();
return;
}
if (bird.y < 0) {
bird.y = 0;
velocity = 0;
}
// Spawn pipes
frame++;
if (frame % 90 === 0) {
spawnPipes();
}
// Difficulty scaling
if (score > 5) pipeSpeed = 12;
if (score > 10) pipeSpeed = 14;
if (score > 20) pipeSpeed = 16;
// Move pipes
for (var i = pipes.length - 1; i >= 0; i--) {
var p = pipes[i];
p.top.x -= pipeSpeed;
p.bottom.x -= pipeSpeed;
// Score
if (!p.top.passed && p.top.x < bird.x) {
p.top.passed = true;
score++;
scoreTxt.setText(score);
LK.getSound('score').play();
}
// Collision
if (hitTest(bird, p.top) || hitTest(bird, p.bottom)) {
endGame();
return;
}
// Remove pipes
if (p.top.x < -200) {
p.top.destroy();
p.bottom.destroy();
pipes.splice(i, 1);
}
}
};
/**** End Game ****/
function endGame() {
if (gameOver) return;
gameOver = true;
velocity = 0;
LK.getSound('hit').play();
restartButton.visible = true;
gameOverTxt.visible = true;
}
/**** Reset Game ****/
function resetGame() {
gameOver = false;
score = 0;
scoreTxt.setText(score);
velocity = 0;
bird.y = 800;
bird.rotation = 0;
pipeSpeed = 10;
// Clear pipes
for (var i = pipes.length - 1; i >= 0; i--) {
pipes[i].top.destroy();
pipes[i].bottom.destroy();
}
pipes = [];
frame = 0;
restartButton.visible = false;
gameOverTxt.visible = false;
} ===================================================================
--- original.js
+++ change.js
@@ -103,11 +103,10 @@
return bird.x + 50 > pipe.x - pipe.width / 2 && bird.x - 50 < pipe.x + pipe.width / 2 && bird.y + 40 > pipe.y - pipe.height * pipe.anchorY && bird.y - 40 < pipe.y + pipe.height * (1 - pipe.anchorY);
}
/**** Controls ****/
game.down = function () {
- if (!gameOver) {
- velocity = jump;
- }
+ if (gameOver) return;
+ velocity = jump;
};
/**** Game Loop ****/
var frame = 0;
var gameOver = false;
@@ -118,13 +117,18 @@
if (velocity > maxFall) velocity = maxFall;
bird.y += velocity;
// Rotation
bird.rotation = velocity * 0.05;
- // Ground hit
- if (bird.y > 2600 || bird.y < 0) {
+ // Ground & ceiling
+ if (bird.y > 2600) {
+ bird.y = 2600;
endGame();
return;
}
+ if (bird.y < 0) {
+ bird.y = 0;
+ velocity = 0;
+ }
// Spawn pipes
frame++;
if (frame % 90 === 0) {
spawnPipes();
@@ -159,9 +163,11 @@
}
};
/**** End Game ****/
function endGame() {
+ if (gameOver) return;
gameOver = true;
+ velocity = 0;
LK.getSound('hit').play();
restartButton.visible = true;
gameOverTxt.visible = true;
}
@@ -171,15 +177,16 @@
score = 0;
scoreTxt.setText(score);
velocity = 0;
bird.y = 800;
- pipeSpeed = 10; // reset difficulty
+ bird.rotation = 0;
+ pipeSpeed = 10;
// Clear pipes
for (var i = pipes.length - 1; i >= 0; i--) {
pipes[i].top.destroy();
pipes[i].bottom.destroy();
- pipes.splice(i, 1);
}
+ pipes = [];
frame = 0;
restartButton.visible = false;
gameOverTxt.visible = false;
}
\ No newline at end of file