Code edit (2 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
I want a star icon next to score count. and a skull emoji when game over
User prompt
the lives aren't 3.they are 10
User prompt
every time when the player dies the live counter deincrement but let the user play again. the game over banner appears when all three lives ends. and after the death counter goes down by 1, the player has1 second of going through walls ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
and you have 3 lives
Code edit (1 edits merged)
Please save this source code
User prompt
Flappy Navigator
Initial prompt
create a game similar to 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.velocity = 0;
self.gravity = 0.8;
self.flapPower = -12;
self.flap = function () {
self.velocity = self.flapPower;
LK.getSound('flap').play();
// Add a little bounce animation
tween(birdGraphics, {
rotation: -0.3
}, {
duration: 100
});
tween(birdGraphics, {
rotation: 0
}, {
duration: 200
});
};
self.update = function () {
self.velocity += self.gravity;
self.y += self.velocity;
// Rotate bird based on velocity
birdGraphics.rotation = Math.max(-0.5, Math.min(0.5, self.velocity * 0.05));
// Check ground collision
if (self.y > 2732 - 150) {
LK.showGameOver();
}
// Check ceiling collision
if (self.y < 0) {
self.y = 0;
self.velocity = 0;
}
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
self.speed = -4;
self.scored = false;
// Create top pipe
self.topPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 1
});
// Create bottom pipe
self.bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0
});
self.setGapPosition = function (gapY, gapSize) {
self.topPipe.y = gapY - gapSize / 2;
self.bottomPipe.y = gapY + gapSize / 2;
};
self.update = function () {
self.x += self.speed;
// Remove pipe when off screen
if (self.x < -100) {
self.shouldRemove = true;
}
// Check scoring
if (!self.scored && self.x < bird.x) {
self.scored = true;
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore());
LK.getSound('score').play();
}
};
self.checkCollision = function (bird) {
var birdBounds = {
x: bird.x - 30,
y: bird.y - 30,
width: 60,
height: 60
};
var topPipeBounds = {
x: self.x - 60,
y: self.topPipe.y - 800,
width: 120,
height: 800
};
var bottomPipeBounds = {
x: self.x - 60,
y: self.bottomPipe.y,
width: 120,
height: 800
};
return birdBounds.x < topPipeBounds.x + topPipeBounds.width && birdBounds.x + birdBounds.width > topPipeBounds.x && birdBounds.y < topPipeBounds.y + topPipeBounds.height && birdBounds.y + birdBounds.height > topPipeBounds.y || birdBounds.x < bottomPipeBounds.x + bottomPipeBounds.width && birdBounds.x + birdBounds.width > bottomPipeBounds.x && birdBounds.y < bottomPipeBounds.y + bottomPipeBounds.height && birdBounds.y + birdBounds.height > bottomPipeBounds.y;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var bird;
var pipes = [];
var ground;
var scoreText;
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 90; // Spawn pipe every 1.5 seconds at 60fps
var gapSize = 300;
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 2732 - 100
}));
// Create bird
bird = game.addChild(new Bird());
bird.x = 300;
bird.y = 1366; // Middle of screen
// Create score display
scoreText = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 100;
// Input handling
game.down = function (x, y, obj) {
bird.flap();
};
// Spawn pipes
function spawnPipe() {
var pipe = game.addChild(new Pipe());
pipe.x = 2148; // Start off screen to the right
// Random gap position
var minGapY = gapSize / 2 + 100;
var maxGapY = 2732 - 100 - gapSize / 2;
var gapY = minGapY + Math.random() * (maxGapY - minGapY);
pipe.setGapPosition(gapY, gapSize);
pipes.push(pipe);
}
// Main game loop
game.update = function () {
// Spawn pipes
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeSpawnInterval) {
spawnPipe();
pipeSpawnTimer = 0;
}
// Update pipes
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
// Check collision
if (pipe.checkCollision(bird)) {
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
return;
}
// Remove pipes that are off screen
if (pipe.shouldRemove) {
pipe.destroy();
pipes.splice(i, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,181 @@
-/****
+/****
+* 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.velocity = 0;
+ self.gravity = 0.8;
+ self.flapPower = -12;
+ self.flap = function () {
+ self.velocity = self.flapPower;
+ LK.getSound('flap').play();
+ // Add a little bounce animation
+ tween(birdGraphics, {
+ rotation: -0.3
+ }, {
+ duration: 100
+ });
+ tween(birdGraphics, {
+ rotation: 0
+ }, {
+ duration: 200
+ });
+ };
+ self.update = function () {
+ self.velocity += self.gravity;
+ self.y += self.velocity;
+ // Rotate bird based on velocity
+ birdGraphics.rotation = Math.max(-0.5, Math.min(0.5, self.velocity * 0.05));
+ // Check ground collision
+ if (self.y > 2732 - 150) {
+ LK.showGameOver();
+ }
+ // Check ceiling collision
+ if (self.y < 0) {
+ self.y = 0;
+ self.velocity = 0;
+ }
+ };
+ return self;
+});
+var Pipe = Container.expand(function () {
+ var self = Container.call(this);
+ self.speed = -4;
+ self.scored = false;
+ // Create top pipe
+ self.topPipe = self.attachAsset('pipe', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ // Create bottom pipe
+ self.bottomPipe = self.attachAsset('pipe', {
+ anchorX: 0.5,
+ anchorY: 0
+ });
+ self.setGapPosition = function (gapY, gapSize) {
+ self.topPipe.y = gapY - gapSize / 2;
+ self.bottomPipe.y = gapY + gapSize / 2;
+ };
+ self.update = function () {
+ self.x += self.speed;
+ // Remove pipe when off screen
+ if (self.x < -100) {
+ self.shouldRemove = true;
+ }
+ // Check scoring
+ if (!self.scored && self.x < bird.x) {
+ self.scored = true;
+ LK.setScore(LK.getScore() + 1);
+ scoreText.setText(LK.getScore());
+ LK.getSound('score').play();
+ }
+ };
+ self.checkCollision = function (bird) {
+ var birdBounds = {
+ x: bird.x - 30,
+ y: bird.y - 30,
+ width: 60,
+ height: 60
+ };
+ var topPipeBounds = {
+ x: self.x - 60,
+ y: self.topPipe.y - 800,
+ width: 120,
+ height: 800
+ };
+ var bottomPipeBounds = {
+ x: self.x - 60,
+ y: self.bottomPipe.y,
+ width: 120,
+ height: 800
+ };
+ return birdBounds.x < topPipeBounds.x + topPipeBounds.width && birdBounds.x + birdBounds.width > topPipeBounds.x && birdBounds.y < topPipeBounds.y + topPipeBounds.height && birdBounds.y + birdBounds.height > topPipeBounds.y || birdBounds.x < bottomPipeBounds.x + bottomPipeBounds.width && birdBounds.x + birdBounds.width > bottomPipeBounds.x && birdBounds.y < bottomPipeBounds.y + bottomPipeBounds.height && birdBounds.y + birdBounds.height > bottomPipeBounds.y;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var bird;
+var pipes = [];
+var ground;
+var scoreText;
+var pipeSpawnTimer = 0;
+var pipeSpawnInterval = 90; // Spawn pipe every 1.5 seconds at 60fps
+var gapSize = 300;
+// Create ground
+ground = game.addChild(LK.getAsset('ground', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 2732 - 100
+}));
+// Create bird
+bird = game.addChild(new Bird());
+bird.x = 300;
+bird.y = 1366; // Middle of screen
+// Create score display
+scoreText = new Text2('0', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+scoreText.y = 100;
+// Input handling
+game.down = function (x, y, obj) {
+ bird.flap();
+};
+// Spawn pipes
+function spawnPipe() {
+ var pipe = game.addChild(new Pipe());
+ pipe.x = 2148; // Start off screen to the right
+ // Random gap position
+ var minGapY = gapSize / 2 + 100;
+ var maxGapY = 2732 - 100 - gapSize / 2;
+ var gapY = minGapY + Math.random() * (maxGapY - minGapY);
+ pipe.setGapPosition(gapY, gapSize);
+ pipes.push(pipe);
+}
+// Main game loop
+game.update = function () {
+ // Spawn pipes
+ pipeSpawnTimer++;
+ if (pipeSpawnTimer >= pipeSpawnInterval) {
+ spawnPipe();
+ pipeSpawnTimer = 0;
+ }
+ // Update pipes
+ for (var i = pipes.length - 1; i >= 0; i--) {
+ var pipe = pipes[i];
+ // Check collision
+ if (pipe.checkCollision(bird)) {
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.showGameOver();
+ return;
+ }
+ // Remove pipes that are off screen
+ if (pipe.shouldRemove) {
+ pipe.destroy();
+ pipes.splice(i, 1);
+ }
+ }
+};
\ No newline at end of file