User prompt
Remove coin
User prompt
Remove coin
User prompt
left the coin on the path where the bird flies
User prompt
Fix coin in tow pipe middle in
User prompt
Add coin
User prompt
Ground is smooth not showing so make smooth the ground
User prompt
Ground is not showing longer so fix it
User prompt
Pipe is not touching up screen so fix it
User prompt
Fix pipe error
User prompt
Birk are not showing
User prompt
Fix the pipe error pipe is not touching the ground
Code edit (1 edits merged)
Please save this source code
User prompt
Flapster Flight
Initial prompt
Modern App Store icon, high definition, square with rounded corners, for a game titled "Flapster Flight" and with the description "A tap-to-play side-scroller where you control a bird flying through obstacle pipes. Tap to flap and keep the bird airborne while avoiding collisions with pipes and the ground. Simple to learn but challenging to master, with each successful pipe passage earning you points.". No text on icon!
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5,
width: 100,
height: 100
});
self.velocity = 0;
self.gravity = 0.5;
self.flapStrength = -10;
self.rotation = 0;
self.isDead = false;
self.flap = function () {
if (self.isDead) return;
self.velocity = self.flapStrength;
LK.getSound('flap').play();
// Rotate bird upward when flapping
tween(self, {
rotation: -0.5
}, {
duration: 100
});
};
self.update = function () {
if (self.isDead) return;
// Apply gravity and update position
self.velocity += self.gravity;
self.y += self.velocity;
// Update rotation based on velocity
if (self.velocity > 0) {
var targetRotation = Math.min(Math.PI / 2, self.velocity * 0.05);
tween(self, {
rotation: targetRotation
}, {
duration: 200
});
}
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('Coin', {
anchorX: 0.5,
anchorY: 0.5,
width: 50,
height: 50
});
self.speed = 5;
self.isCollected = false;
self.rotation = 0;
self.update = function () {
self.x -= self.speed;
// Rotate coin for visual effect
self.rotation += 0.05;
coinGraphics.rotation = self.rotation;
};
return self;
});
var Ground = Container.expand(function () {
var self = Container.call(this);
var groundGraphics = self.attachAsset('ground', {
anchorX: 0.0,
anchorY: 0.0,
height: 100
});
self.height = 100;
self.speed = 5;
self.update = function () {
self.x -= self.speed;
// Loop ground for infinite scrolling
if (self.x <= -groundGraphics.width) {
self.x = 0;
}
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
self.topPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 1.0
});
self.bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.0
});
self.speed = 5;
self.isPassed = false;
self.setGapPosition = function (gapY, gapHeight) {
self.topPipe.y = gapY - gapHeight / 2;
self.bottomPipe.y = gapY + gapHeight / 2;
// Adjust the scale of the bottom pipe to ensure it reaches the ground
// Use the actual height of grounds when available, otherwise use a default value
var groundHeight = grounds.length > 0 ? grounds[0].height : 100;
// Calculate how much we need to scale the pipe to reach the ground
var distanceToGround = game.height - self.bottomPipe.y - groundHeight;
self.bottomPipe.scale.y = distanceToGround / self.bottomPipe.height;
// Adjust the scale of the top pipe to ensure it reaches the top of the screen
self.topPipe.scale.y = self.topPipe.y / self.topPipe.height;
self.gapY = gapY;
};
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var bird;
var pipes = [];
var grounds = [];
var coins = [];
var gameStarted = false;
var isGameOver = false;
var pipeGapHeight = 300;
var timeSinceLastPipe = 0;
var pipeInterval = 120; // Frames between pipe spawns
var timeSinceLastCoin = 0;
var coinInterval = 80; // Frames between coin spawns
var score = 0;
var bestScore = storage.bestScore || 0;
// Create score text
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create tap to start text
var startTxt = new Text2('Tap to Start', {
size: 100,
fill: 0xFFFFFF
});
startTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(startTxt);
// Create bird
function createBird() {
bird = new Bird();
bird.x = 400;
bird.y = game.height / 2;
game.addChild(bird);
}
// Create ground
function createGround() {
var ground = new Ground();
ground.y = game.height - ground.height;
grounds.push(ground);
game.addChild(ground);
// Add second ground piece for continuous scrolling
var ground2 = new Ground();
ground2.x = ground.width;
ground2.y = game.height - ground2.height;
grounds.push(ground2);
game.addChild(ground2);
}
// Create pipe
function createPipe() {
var pipe = new Pipe();
pipe.x = game.width + 100;
// Random gap position, but keep within bounds
var minGapY = pipeGapHeight / 2 + 100;
var maxGapY = game.height - pipeGapHeight / 2 - 150; // Account for ground
var gapY = minGapY + Math.random() * (maxGapY - minGapY);
pipe.setGapPosition(gapY, pipeGapHeight);
pipes.push(pipe);
game.addChild(pipe);
}
// Create coin
function createCoin() {
var coin = new Coin();
coin.x = game.width + 100;
// Position coins within a safe area for the bird to collect
var minY = 150;
var maxY = game.height - grounds[0].height - 150;
coin.y = minY + Math.random() * (maxY - minY);
coins.push(coin);
game.addChild(coin);
}
// Check collisions
function checkCollisions() {
if (isGameOver) return;
// Ground collision
if (bird.y + bird.height / 2 > game.height - grounds[0].height) {
gameOver();
return;
}
// Ceiling collision
if (bird.y - bird.height / 2 < 0) {
bird.y = bird.height / 2;
bird.velocity = 0;
}
// Pipe collisions
for (var i = 0; i < pipes.length; i++) {
var pipe = pipes[i];
if (bird.intersects(pipe.topPipe) || bird.intersects(pipe.bottomPipe)) {
gameOver();
return;
}
// Check if bird passed the pipe
if (!pipe.isPassed && bird.x > pipe.x) {
pipe.isPassed = true;
score++;
scoreTxt.setText(score.toString());
LK.getSound('point').play();
}
}
// Coin collisions
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (!coin.isCollected && bird.intersects(coin)) {
// Collect the coin
coin.isCollected = true;
score += 2; // Coins are worth 2 points
scoreTxt.setText(score.toString());
// Visual/audio feedback
LK.effects.flashObject(coin, 0xffff00, 300);
LK.getSound('point').play();
// Remove the coin
LK.setTimeout(function () {
var coinIndex = coins.indexOf(coin);
if (coinIndex !== -1) {
coin.destroy();
coins.splice(coinIndex, 1);
}
}, 300);
}
}
}
// Game over
function gameOver() {
isGameOver = true;
bird.isDead = true;
// Update best score
if (score > bestScore) {
bestScore = score;
storage.bestScore = bestScore;
}
// Play hit sound
LK.getSound('hit').play();
// Visual feedback
LK.effects.flashScreen(0xff0000, 300);
// Show game over after a short delay
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
// Initialize game
function initGame() {
// Reset variables
gameStarted = false;
isGameOver = false;
timeSinceLastPipe = 0;
timeSinceLastCoin = 0;
score = 0;
// Clear existing elements
for (var i = 0; i < pipes.length; i++) {
pipes[i].destroy();
}
pipes = [];
for (var i = 0; i < grounds.length; i++) {
grounds[i].destroy();
}
grounds = [];
for (var i = 0; i < coins.length; i++) {
coins[i].destroy();
}
coins = [];
if (bird) {
bird.destroy();
}
// Setup new game
scoreTxt.setText("0");
startTxt.visible = true;
createBird();
createGround();
// Set score based on LK.getScore()
score = LK.getScore();
scoreTxt.setText(score.toString());
// Play background music
LK.playMusic('bgmusic');
}
// Start the game
function startGame() {
if (!gameStarted && !isGameOver) {
gameStarted = true;
startTxt.visible = false;
bird.flap();
}
}
// Event handlers
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
} else if (!isGameOver) {
bird.flap();
}
};
// Update function
game.update = function () {
if (isGameOver) return;
// Update bird
if (gameStarted) {
bird.update();
}
// Update grounds
for (var i = 0; i < grounds.length; i++) {
if (gameStarted) {
grounds[i].update();
}
}
// Update pipes and check for cleanup
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
if (gameStarted) {
pipe.update();
}
// Remove pipes that have moved off screen
if (pipe.x < -300) {
pipe.destroy();
pipes.splice(i, 1);
}
}
// Update coins and check for cleanup
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (gameStarted) {
coin.update();
}
// Remove coins that have moved off screen
if (coin.x < -100) {
coin.destroy();
coins.splice(i, 1);
}
}
// Create new pipes
if (gameStarted) {
timeSinceLastPipe++;
if (timeSinceLastPipe >= pipeInterval) {
createPipe();
timeSinceLastPipe = 0;
}
// Create new coins
timeSinceLastCoin++;
if (timeSinceLastCoin >= coinInterval) {
createCoin();
timeSinceLastCoin = 0;
}
}
// Check collisions
if (gameStarted) {
checkCollisions();
}
// Update score display
LK.setScore(score);
};
// Initialize the game on startup
initGame(); ===================================================================
--- original.js
+++ change.js
@@ -47,8 +47,27 @@
}
};
return self;
});
+var Coin = Container.expand(function () {
+ var self = Container.call(this);
+ var coinGraphics = self.attachAsset('Coin', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ width: 50,
+ height: 50
+ });
+ self.speed = 5;
+ self.isCollected = false;
+ self.rotation = 0;
+ self.update = function () {
+ self.x -= self.speed;
+ // Rotate coin for visual effect
+ self.rotation += 0.05;
+ coinGraphics.rotation = self.rotation;
+ };
+ return self;
+});
var Ground = Container.expand(function () {
var self = Container.call(this);
var groundGraphics = self.attachAsset('ground', {
anchorX: 0.0,
@@ -110,13 +129,16 @@
// Game variables
var bird;
var pipes = [];
var grounds = [];
+var coins = [];
var gameStarted = false;
var isGameOver = false;
var pipeGapHeight = 300;
var timeSinceLastPipe = 0;
var pipeInterval = 120; // Frames between pipe spawns
+var timeSinceLastCoin = 0;
+var coinInterval = 80; // Frames between coin spawns
var score = 0;
var bestScore = storage.bestScore || 0;
// Create score text
var scoreTxt = new Text2('0', {
@@ -163,8 +185,19 @@
pipe.setGapPosition(gapY, pipeGapHeight);
pipes.push(pipe);
game.addChild(pipe);
}
+// Create coin
+function createCoin() {
+ var coin = new Coin();
+ coin.x = game.width + 100;
+ // Position coins within a safe area for the bird to collect
+ var minY = 150;
+ var maxY = game.height - grounds[0].height - 150;
+ coin.y = minY + Math.random() * (maxY - minY);
+ coins.push(coin);
+ game.addChild(coin);
+}
// Check collisions
function checkCollisions() {
if (isGameOver) return;
// Ground collision
@@ -191,8 +224,29 @@
scoreTxt.setText(score.toString());
LK.getSound('point').play();
}
}
+ // Coin collisions
+ for (var i = coins.length - 1; i >= 0; i--) {
+ var coin = coins[i];
+ if (!coin.isCollected && bird.intersects(coin)) {
+ // Collect the coin
+ coin.isCollected = true;
+ score += 2; // Coins are worth 2 points
+ scoreTxt.setText(score.toString());
+ // Visual/audio feedback
+ LK.effects.flashObject(coin, 0xffff00, 300);
+ LK.getSound('point').play();
+ // Remove the coin
+ LK.setTimeout(function () {
+ var coinIndex = coins.indexOf(coin);
+ if (coinIndex !== -1) {
+ coin.destroy();
+ coins.splice(coinIndex, 1);
+ }
+ }, 300);
+ }
+ }
}
// Game over
function gameOver() {
isGameOver = true;
@@ -216,8 +270,9 @@
// Reset variables
gameStarted = false;
isGameOver = false;
timeSinceLastPipe = 0;
+ timeSinceLastCoin = 0;
score = 0;
// Clear existing elements
for (var i = 0; i < pipes.length; i++) {
pipes[i].destroy();
@@ -226,8 +281,12 @@
for (var i = 0; i < grounds.length; i++) {
grounds[i].destroy();
}
grounds = [];
+ for (var i = 0; i < coins.length; i++) {
+ coins[i].destroy();
+ }
+ coins = [];
if (bird) {
bird.destroy();
}
// Setup new game
@@ -281,15 +340,33 @@
pipe.destroy();
pipes.splice(i, 1);
}
}
+ // Update coins and check for cleanup
+ for (var i = coins.length - 1; i >= 0; i--) {
+ var coin = coins[i];
+ if (gameStarted) {
+ coin.update();
+ }
+ // Remove coins that have moved off screen
+ if (coin.x < -100) {
+ coin.destroy();
+ coins.splice(i, 1);
+ }
+ }
// Create new pipes
if (gameStarted) {
timeSinceLastPipe++;
if (timeSinceLastPipe >= pipeInterval) {
createPipe();
timeSinceLastPipe = 0;
}
+ // Create new coins
+ timeSinceLastCoin++;
+ if (timeSinceLastCoin >= coinInterval) {
+ createCoin();
+ timeSinceLastCoin = 0;
+ }
}
// Check collisions
if (gameStarted) {
checkCollisions();