/****
* 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
});
self.velocity = 0;
self.gravity = 0.7;
self.flapStrength = -15;
self.rotation = 0;
self.dead = false;
self.flap = function () {
if (self.dead) {
return;
}
self.velocity = self.flapStrength * (sugarActive ? 1.5 : 1);
LK.getSound('flap').play();
// Rotate bird upward when flapping
tween(self, {
rotation: -0.5
}, {
duration: 200,
easing: tween.easeOut
});
};
self.update = function () {
if (self.dead) {
return;
}
if (gameStarted) {
self.velocity += self.gravity * (sugarActive ? 1.5 : 1);
self.y += self.velocity;
}
// Rotate bird downward when falling
if (self.velocity > 0) {
var targetRotation = Math.min(Math.PI / 2, self.velocity * 0.05);
tween(self, {
rotation: targetRotation
}, {
duration: 100,
easing: tween.linear
});
}
};
self.die = function () {
if (self.dead) {
return;
}
self.dead = true;
LK.getSound('hit').play();
// Flash red when dying
LK.effects.flashObject(self, 0xFF0000, 500);
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
var topPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 1.0,
flipY: 1 // Flip the top pipe vertically
});
var bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.0
});
self.gapSize = 400;
self.speed = 5;
self.scored = false;
self.setGapPosition = function (y) {
topPipe.y = y - self.gapSize / 2; // Adjust top pipe position
bottomPipe.y = y + self.gapSize / 2; // Revert bottom pipe position to its original state
};
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Sugar = Container.expand(function () {
var self = Container.call(this);
var sugarGraphics = self.attachAsset('sugar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
/**
* Game Description:
*
* In this exciting and fast-paced game, you control a bird navigating through a series of pipes.
* The objective is to fly as far as possible without hitting the pipes or the ground.
* Collect sugar to temporarily boost your gravity and flap strength, making it easier to maneuver through tight spaces.
* The game features a dynamic scoring system, where you earn points by successfully passing through pipes.
* As you progress, the game speed increases, adding to the challenge.
* Compete against your high score and enjoy the engaging gameplay with vibrant graphics and sound effects.
*/
var sugarActive = false;
// Initialize GUI elements
var bird;
var pipes = [];
var ground;
var gameStarted = false;
var gameSpeed = 5;
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 100;
var score = 0;
var highScore = storage.highScore || 0;
var gameOver = false;
// Initialize GUI elements
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var tapToStartTxt = new Text2('TAP TO START', {
size: 80,
fill: 0xFFFFFF
});
tapToStartTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(tapToStartTxt);
var highScoreTxt = new Text2('BEST: 0', {
size: 60,
fill: 0xFFFFFF
});
highScoreTxt.anchor.set(0.5, 0);
highScoreTxt.y = 160;
highScoreTxt.setText('BEST: ' + highScore);
LK.gui.top.addChild(highScoreTxt);
// Initialize game objects
function initGame() {
// Create bird
bird = new Bird();
bird.x = 400;
bird.y = 2732 / 2;
bird.velocity = 0; // Ensure bird doesn't move before game starts
game.addChild(bird);
// Create ground
ground = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
});
ground.x -= 1000;
ground.y = 2732 - ground.height;
game.addChild(ground);
// Move ground to the front
game.setChildIndex(ground, game.children.length - 1);
// Reset game state
pipes = [];
sugars = [];
gameStarted = false;
gameSpeed = 5;
pipeSpawnTimer = 0;
sugarSpawnTimer = 0;
score = 0;
gameOver = false;
// Update score display
scoreTxt.setText('0');
LK.setScore(0);
// Show tap to start message
tapToStartTxt.visible = true;
// Play background music
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 0.4,
duration: 1000
}
});
}
// Create a new pipe
function spawnPipe() {
var pipe = new Pipe();
pipe.x = 2048 + pipe.width + 1600; // Increase space between pipes by another 1000 pixels
// Random gap position, but keep within reasonable bounds
var minGapX = 400;
var maxGapX = 2048 - 400;
var gapX = minGapX + Math.random() * (maxGapX - minGapX);
pipe.setGapPosition(gapX);
pipe.speed = gameSpeed;
game.addChild(pipe);
pipes.push(pipe);
}
// Start the game
function startGame() {
if (gameStarted || gameOver) {
return;
}
gameStarted = true;
tapToStartTxt.visible = false;
bird.flap();
}
// Handle collision detection
function checkCollisions() {
if (!gameStarted || gameOver) {
return;
}
// Check for ground collision
if (bird.y + bird.height / 2 > ground.y) {
gameEnd();
return;
}
// Check for ceiling collision
if (bird.y - bird.height / 2 < 0) {
gameEnd(); // Trigger game over when touching the ceiling
return;
}
// Check for pipe collisions
for (var i = 0; i < pipes.length; i++) {
var pipe = pipes[i];
// Get references to the pipe parts
var topPipe = pipe.children[0];
var bottomPipe = pipe.children[1];
// Convert positions to global game coordinates
var topPipeGlobal = game.toLocal(topPipe.parent.toGlobal(topPipe.position));
var bottomPipeGlobal = game.toLocal(bottomPipe.parent.toGlobal(bottomPipe.position));
// Check for collision with top pipe
if (bird.x + bird.width / 3 > pipe.x - topPipe.width / 2 && bird.x - bird.width / 3 < pipe.x + topPipe.width / 2 && bird.y - bird.height / 3 < topPipeGlobal.y) {
gameEnd();
return;
}
// Check for collision with bottom pipe
if (bird.x + bird.width / 3 > pipe.x - bottomPipe.width / 2 && bird.x - bird.width / 3 < pipe.x + bottomPipe.width / 2 && bird.y + bird.height / 3 > bottomPipeGlobal.y) {
gameEnd();
return;
}
// Check if bird passed pipe (scoring)
if (!pipe.scored && pipe.x + topPipe.width / 2 < bird.x - bird.width / 2) {
pipe.scored = true;
incrementScore();
}
}
// Check for sugar collisions
for (var i = sugars.length - 1; i >= 0; i--) {
if (bird.intersects(sugars[i])) {
sugarActive = true;
LK.getSound('point').play();
sugars[i].destroy();
sugars.splice(i, 1);
}
}
}
// Increment the score
function incrementScore() {
score++;
LK.setScore(score);
scoreTxt.setText(score.toString());
// Increase game speed slightly with each point
if (score % 5 === 0 && gameSpeed < 10) {
gameSpeed += 0.5;
// Update speed for existing pipes
for (var i = 0; i < pipes.length; i++) {
pipes[i].speed = gameSpeed;
}
}
LK.getSound('point').play();
// Update high score if needed
if (score > highScore) {
highScore = score;
storage.highScore = highScore;
highScoreTxt.setText('BEST: ' + highScore);
}
}
// End the game
function gameEnd() {
if (gameOver) {
return;
}
gameOver = true;
bird.die();
// Flash screen red
LK.effects.flashScreen(0xFF0000, 500);
// Show game over after a short delay
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
// Input handlers
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
} else if (!gameOver) {
bird.flap();
}
};
// Game update function
game.update = function () {
if (gameStarted && !gameOver) {
// Spawn pipes
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeSpawnInterval) {
LK.setTimeout(function () {
spawnPipe();
}, 200); // Delay spawning by 0.2 seconds
pipeSpawnTimer = 0;
}
// Spawn sugar
sugarSpawnTimer++;
if (sugarSpawnTimer >= 300) {
// Randomly spawn sugar every 300 frames
var sugar = new Sugar();
sugar.x = 2048 + sugar.width;
sugar.y = Math.random() * (2732 - 200); // Random y position
game.addChild(sugar);
sugars.push(sugar);
sugarSpawnTimer = 0;
}
// Update pipes
for (var i = pipes.length - 1; i >= 0; i--) {
pipes[i].update();
// Remove pipes that have gone off-screen
if (pipes[i].x < -pipes[i].width) {
pipes[i].destroy();
pipes.splice(i, 1);
}
}
// Update sugars
for (var i = sugars.length - 1; i >= 0; i--) {
sugars[i].update();
// Remove sugars that have gone off-screen
if (sugars[i].x < -sugars[i].width) {
sugars[i].destroy();
sugars.splice(i, 1);
}
}
// Check for collisions
checkCollisions();
}
};
// Initialize the game
initGame(); /****
* 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
});
self.velocity = 0;
self.gravity = 0.7;
self.flapStrength = -15;
self.rotation = 0;
self.dead = false;
self.flap = function () {
if (self.dead) {
return;
}
self.velocity = self.flapStrength * (sugarActive ? 1.5 : 1);
LK.getSound('flap').play();
// Rotate bird upward when flapping
tween(self, {
rotation: -0.5
}, {
duration: 200,
easing: tween.easeOut
});
};
self.update = function () {
if (self.dead) {
return;
}
if (gameStarted) {
self.velocity += self.gravity * (sugarActive ? 1.5 : 1);
self.y += self.velocity;
}
// Rotate bird downward when falling
if (self.velocity > 0) {
var targetRotation = Math.min(Math.PI / 2, self.velocity * 0.05);
tween(self, {
rotation: targetRotation
}, {
duration: 100,
easing: tween.linear
});
}
};
self.die = function () {
if (self.dead) {
return;
}
self.dead = true;
LK.getSound('hit').play();
// Flash red when dying
LK.effects.flashObject(self, 0xFF0000, 500);
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
var topPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 1.0,
flipY: 1 // Flip the top pipe vertically
});
var bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.0
});
self.gapSize = 400;
self.speed = 5;
self.scored = false;
self.setGapPosition = function (y) {
topPipe.y = y - self.gapSize / 2; // Adjust top pipe position
bottomPipe.y = y + self.gapSize / 2; // Revert bottom pipe position to its original state
};
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Sugar = Container.expand(function () {
var self = Container.call(this);
var sugarGraphics = self.attachAsset('sugar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
/**
* Game Description:
*
* In this exciting and fast-paced game, you control a bird navigating through a series of pipes.
* The objective is to fly as far as possible without hitting the pipes or the ground.
* Collect sugar to temporarily boost your gravity and flap strength, making it easier to maneuver through tight spaces.
* The game features a dynamic scoring system, where you earn points by successfully passing through pipes.
* As you progress, the game speed increases, adding to the challenge.
* Compete against your high score and enjoy the engaging gameplay with vibrant graphics and sound effects.
*/
var sugarActive = false;
// Initialize GUI elements
var bird;
var pipes = [];
var ground;
var gameStarted = false;
var gameSpeed = 5;
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 100;
var score = 0;
var highScore = storage.highScore || 0;
var gameOver = false;
// Initialize GUI elements
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var tapToStartTxt = new Text2('TAP TO START', {
size: 80,
fill: 0xFFFFFF
});
tapToStartTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(tapToStartTxt);
var highScoreTxt = new Text2('BEST: 0', {
size: 60,
fill: 0xFFFFFF
});
highScoreTxt.anchor.set(0.5, 0);
highScoreTxt.y = 160;
highScoreTxt.setText('BEST: ' + highScore);
LK.gui.top.addChild(highScoreTxt);
// Initialize game objects
function initGame() {
// Create bird
bird = new Bird();
bird.x = 400;
bird.y = 2732 / 2;
bird.velocity = 0; // Ensure bird doesn't move before game starts
game.addChild(bird);
// Create ground
ground = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
});
ground.x -= 1000;
ground.y = 2732 - ground.height;
game.addChild(ground);
// Move ground to the front
game.setChildIndex(ground, game.children.length - 1);
// Reset game state
pipes = [];
sugars = [];
gameStarted = false;
gameSpeed = 5;
pipeSpawnTimer = 0;
sugarSpawnTimer = 0;
score = 0;
gameOver = false;
// Update score display
scoreTxt.setText('0');
LK.setScore(0);
// Show tap to start message
tapToStartTxt.visible = true;
// Play background music
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 0.4,
duration: 1000
}
});
}
// Create a new pipe
function spawnPipe() {
var pipe = new Pipe();
pipe.x = 2048 + pipe.width + 1600; // Increase space between pipes by another 1000 pixels
// Random gap position, but keep within reasonable bounds
var minGapX = 400;
var maxGapX = 2048 - 400;
var gapX = minGapX + Math.random() * (maxGapX - minGapX);
pipe.setGapPosition(gapX);
pipe.speed = gameSpeed;
game.addChild(pipe);
pipes.push(pipe);
}
// Start the game
function startGame() {
if (gameStarted || gameOver) {
return;
}
gameStarted = true;
tapToStartTxt.visible = false;
bird.flap();
}
// Handle collision detection
function checkCollisions() {
if (!gameStarted || gameOver) {
return;
}
// Check for ground collision
if (bird.y + bird.height / 2 > ground.y) {
gameEnd();
return;
}
// Check for ceiling collision
if (bird.y - bird.height / 2 < 0) {
gameEnd(); // Trigger game over when touching the ceiling
return;
}
// Check for pipe collisions
for (var i = 0; i < pipes.length; i++) {
var pipe = pipes[i];
// Get references to the pipe parts
var topPipe = pipe.children[0];
var bottomPipe = pipe.children[1];
// Convert positions to global game coordinates
var topPipeGlobal = game.toLocal(topPipe.parent.toGlobal(topPipe.position));
var bottomPipeGlobal = game.toLocal(bottomPipe.parent.toGlobal(bottomPipe.position));
// Check for collision with top pipe
if (bird.x + bird.width / 3 > pipe.x - topPipe.width / 2 && bird.x - bird.width / 3 < pipe.x + topPipe.width / 2 && bird.y - bird.height / 3 < topPipeGlobal.y) {
gameEnd();
return;
}
// Check for collision with bottom pipe
if (bird.x + bird.width / 3 > pipe.x - bottomPipe.width / 2 && bird.x - bird.width / 3 < pipe.x + bottomPipe.width / 2 && bird.y + bird.height / 3 > bottomPipeGlobal.y) {
gameEnd();
return;
}
// Check if bird passed pipe (scoring)
if (!pipe.scored && pipe.x + topPipe.width / 2 < bird.x - bird.width / 2) {
pipe.scored = true;
incrementScore();
}
}
// Check for sugar collisions
for (var i = sugars.length - 1; i >= 0; i--) {
if (bird.intersects(sugars[i])) {
sugarActive = true;
LK.getSound('point').play();
sugars[i].destroy();
sugars.splice(i, 1);
}
}
}
// Increment the score
function incrementScore() {
score++;
LK.setScore(score);
scoreTxt.setText(score.toString());
// Increase game speed slightly with each point
if (score % 5 === 0 && gameSpeed < 10) {
gameSpeed += 0.5;
// Update speed for existing pipes
for (var i = 0; i < pipes.length; i++) {
pipes[i].speed = gameSpeed;
}
}
LK.getSound('point').play();
// Update high score if needed
if (score > highScore) {
highScore = score;
storage.highScore = highScore;
highScoreTxt.setText('BEST: ' + highScore);
}
}
// End the game
function gameEnd() {
if (gameOver) {
return;
}
gameOver = true;
bird.die();
// Flash screen red
LK.effects.flashScreen(0xFF0000, 500);
// Show game over after a short delay
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
// Input handlers
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
} else if (!gameOver) {
bird.flap();
}
};
// Game update function
game.update = function () {
if (gameStarted && !gameOver) {
// Spawn pipes
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeSpawnInterval) {
LK.setTimeout(function () {
spawnPipe();
}, 200); // Delay spawning by 0.2 seconds
pipeSpawnTimer = 0;
}
// Spawn sugar
sugarSpawnTimer++;
if (sugarSpawnTimer >= 300) {
// Randomly spawn sugar every 300 frames
var sugar = new Sugar();
sugar.x = 2048 + sugar.width;
sugar.y = Math.random() * (2732 - 200); // Random y position
game.addChild(sugar);
sugars.push(sugar);
sugarSpawnTimer = 0;
}
// Update pipes
for (var i = pipes.length - 1; i >= 0; i--) {
pipes[i].update();
// Remove pipes that have gone off-screen
if (pipes[i].x < -pipes[i].width) {
pipes[i].destroy();
pipes.splice(i, 1);
}
}
// Update sugars
for (var i = sugars.length - 1; i >= 0; i--) {
sugars[i].update();
// Remove sugars that have gone off-screen
if (sugars[i].x < -sugars[i].width) {
sugars[i].destroy();
sugars.splice(i, 1);
}
}
// Check for collisions
checkCollisions();
}
};
// Initialize the game
initGame();
Flappy bird pipe, is green. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Grass. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Pile of sugar. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows