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
****/
/**** Assets ****/
var bg = LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChild(bg);
var ground = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 2532
});
game.addChild(ground);
var groundDirt = LK.getAsset('groundDirt', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 2532 + 140
});
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,
shadow: {
color: 0x222222,
blur: 8,
x: 0,
y: 4
},
font: "'Comic Sans MS', 'Comic Sans', 'Arial Black', Impact, Tahoma"
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.x = 1024;
scoreTxt.y = 50;
LK.gui.top.addChild(scoreTxt);
/**** Buttons ****/
var startButton = LK.getAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
});
startButton.visible = false;
LK.gui.center.addChild(startButton);
var restartButton = LK.getAsset('restartButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1500
});
restartButton.visible = false;
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(a, b) {
return a.x + 40 > b.x - 80 && a.x - 40 < b.x + 80 && a.y + 40 > b.y - 400 && a.y - 40 < b.y + 400;
}
/**** Controls (Mouse + Touch) ****/
function jumpBird() {
velocity = jump;
}
game.down = function () {
jumpBird();
};
/**** Game Loop ****/
var frame = 0;
game.update = function () {
velocity += gravity;
if (velocity > maxFall) velocity = maxFall;
bird.y += velocity;
bird.rotation = velocity * 0.05;
if (bird.y > 2600 || bird.y < 0) {
LK.getSound('hit').play();
LK.showGameOver();
return;
}
frame++;
if (frame % 90 === 0) spawnPipes();
if (score > 5) pipeSpeed = 12;
if (score > 10) pipeSpeed = 14;
if (score > 20) pipeSpeed = 16;
for (var i = pipes.length - 1; i >= 0; i--) {
var p = pipes[i];
p.top.x -= pipeSpeed;
p.bottom.x -= pipeSpeed;
if (!p.top.passed && p.top.x < bird.x) {
p.top.passed = true;
score++;
scoreTxt.setText(score);
LK.getSound('score').play();
}
if (hitTest(bird, p.top) || hitTest(bird, p.bottom)) {
LK.getSound('hit').play();
LK.showGameOver();
return;
}
if (p.top.x < -200) {
p.top.destroy();
p.bottom.destroy();
pipes.splice(i, 1);
}
}
};
/**** Restart ****/
LK.on('gameover', function () {
setTimeout(function () {
location.reload();
}, 500);
}); ===================================================================
--- original.js
+++ change.js
@@ -1,31 +1,30 @@
/****
* Initialize Game
****/
+/**** Initialize Game ****/
var game = new LK.Game({
backgroundColor: 0x70c5ce
});
/****
* Game Code
****/
-// Background
+/**** Assets ****/
var bg = LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChild(bg);
-// Ground (grass)
var ground = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 2532
});
game.addChild(ground);
-// Ground (dirt)
var groundDirt = LK.getAsset('groundDirt', {
anchorX: 0,
anchorY: 0,
x: 0,
@@ -65,18 +64,17 @@
scoreTxt.anchor.set(0.5, 0);
scoreTxt.x = 1024;
scoreTxt.y = 50;
LK.gui.top.addChild(scoreTxt);
-// Start Button
+/**** Buttons ****/
var startButton = LK.getAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
});
startButton.visible = false;
LK.gui.center.addChild(startButton);
-// Restart Button
var restartButton = LK.getAsset('restartButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
@@ -112,53 +110,47 @@
/**** Collision ****/
function hitTest(a, b) {
return a.x + 40 > b.x - 80 && a.x - 40 < b.x + 80 && a.y + 40 > b.y - 400 && a.y - 40 < b.y + 400;
}
-/**** Controls ****/
-LK.on('tap', function () {
- velocity = jump; // jump immediately on tap
-});
+/**** Controls (Mouse + Touch) ****/
+function jumpBird() {
+ velocity = jump;
+}
+game.down = function () {
+ jumpBird();
+};
/**** Game Loop ****/
var frame = 0;
game.update = function () {
- // Gravity
velocity += gravity;
if (velocity > maxFall) velocity = maxFall;
bird.y += velocity;
- // Bird rotation
bird.rotation = velocity * 0.05;
- // Ground / ceiling collision
if (bird.y > 2600 || bird.y < 0) {
LK.getSound('hit').play();
LK.showGameOver();
return;
}
- // Spawn pipes
frame++;
if (frame % 90 === 0) spawnPipes();
- // Increase difficulty
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)) {
LK.getSound('hit').play();
LK.showGameOver();
return;
}
- // Remove off-screen pipes
if (p.top.x < -200) {
p.top.destroy();
p.bottom.destroy();
pipes.splice(i, 1);