/****
* 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.isAlive = true;
self.flap = function () {
if (self.isAlive) {
self.velocity = self.flapPower;
LK.getSound('flap').play();
// Visual flap animation
tween(birdGraphics, {
rotation: -0.3
}, {
duration: 100
});
tween(birdGraphics, {
rotation: 0
}, {
duration: 200
});
}
};
self.update = function () {
if (self.isAlive) {
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 bounds
if (self.y < 0 || self.y > 2732) {
self.die();
}
}
};
self.die = function () {
self.isAlive = false;
LK.effects.flashScreen(0xFF0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
var pipeGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -4;
self.touched = false;
self.scored = false;
self.lastTouching = false;
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 pipeSpawnTimer = 0;
var pipeSpawnInterval = 120; // 2 seconds at 60fps
var gameStarted = false;
// UI
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var instructionTxt = new Text2('TAP TO FLY\nTOUCH PIPES TO SURVIVE', {
size: 60,
fill: 0xFFFFFF
});
instructionTxt.anchor.set(0.5, 0.5);
instructionTxt.x = 2048 / 2;
instructionTxt.y = 2732 / 2 - 200;
game.addChild(instructionTxt);
// Initialize bird
bird = game.addChild(new Bird());
bird.x = 400;
bird.y = 2732 / 2;
// Input handling
game.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
instructionTxt.visible = false;
LK.playMusic('bgmusic');
}
if (bird.isAlive) {
bird.flap();
}
};
// Spawn pipe function
function spawnPipe() {
var pipe = new Pipe();
pipe.x = 2048 + 40; // Start off-screen
pipe.y = Math.random() * (2732 - 400) + 200; // Random height with margins
pipes.push(pipe);
game.addChild(pipe);
}
// Main game update
game.update = function () {
if (!gameStarted) return;
// Update bird
if (bird.isAlive) {
// Spawn pipes
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeSpawnInterval) {
spawnPipe();
pipeSpawnTimer = 0;
// Gradually increase difficulty
if (pipeSpawnInterval > 80) {
pipeSpawnInterval -= 0.5;
}
}
// Update and check pipes
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
// Remove off-screen pipes
if (pipe.x < -100) {
pipe.destroy();
pipes.splice(i, 1);
continue;
}
// Check if bird is touching pipe
var currentTouching = bird.intersects(pipe);
// If bird just started touching this pipe (deadly collision)
if (!pipe.lastTouching && currentTouching && !pipe.touched) {
pipe.touched = true;
LK.getSound('touch').play();
// Visual feedback
LK.effects.flashObject(pipe, 0xFF0000, 300);
// Bird dies when touching pipe
bird.die();
}
pipe.lastTouching = currentTouching;
}
// Check if bird successfully avoided pipes (score condition)
for (var j = 0; j < pipes.length; j++) {
var checkPipe = pipes[j];
// If pipe has moved past the bird and wasn't touched, increase score
if (checkPipe.x < bird.x - 100 && !checkPipe.touched && !checkPipe.scored) {
checkPipe.scored = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
// Visual feedback for successful avoidance
LK.effects.flashObject(checkPipe, 0x00FF00, 300);
}
}
}
}; /****
* 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.isAlive = true;
self.flap = function () {
if (self.isAlive) {
self.velocity = self.flapPower;
LK.getSound('flap').play();
// Visual flap animation
tween(birdGraphics, {
rotation: -0.3
}, {
duration: 100
});
tween(birdGraphics, {
rotation: 0
}, {
duration: 200
});
}
};
self.update = function () {
if (self.isAlive) {
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 bounds
if (self.y < 0 || self.y > 2732) {
self.die();
}
}
};
self.die = function () {
self.isAlive = false;
LK.effects.flashScreen(0xFF0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
var pipeGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -4;
self.touched = false;
self.scored = false;
self.lastTouching = false;
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 pipeSpawnTimer = 0;
var pipeSpawnInterval = 120; // 2 seconds at 60fps
var gameStarted = false;
// UI
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var instructionTxt = new Text2('TAP TO FLY\nTOUCH PIPES TO SURVIVE', {
size: 60,
fill: 0xFFFFFF
});
instructionTxt.anchor.set(0.5, 0.5);
instructionTxt.x = 2048 / 2;
instructionTxt.y = 2732 / 2 - 200;
game.addChild(instructionTxt);
// Initialize bird
bird = game.addChild(new Bird());
bird.x = 400;
bird.y = 2732 / 2;
// Input handling
game.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
instructionTxt.visible = false;
LK.playMusic('bgmusic');
}
if (bird.isAlive) {
bird.flap();
}
};
// Spawn pipe function
function spawnPipe() {
var pipe = new Pipe();
pipe.x = 2048 + 40; // Start off-screen
pipe.y = Math.random() * (2732 - 400) + 200; // Random height with margins
pipes.push(pipe);
game.addChild(pipe);
}
// Main game update
game.update = function () {
if (!gameStarted) return;
// Update bird
if (bird.isAlive) {
// Spawn pipes
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeSpawnInterval) {
spawnPipe();
pipeSpawnTimer = 0;
// Gradually increase difficulty
if (pipeSpawnInterval > 80) {
pipeSpawnInterval -= 0.5;
}
}
// Update and check pipes
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
// Remove off-screen pipes
if (pipe.x < -100) {
pipe.destroy();
pipes.splice(i, 1);
continue;
}
// Check if bird is touching pipe
var currentTouching = bird.intersects(pipe);
// If bird just started touching this pipe (deadly collision)
if (!pipe.lastTouching && currentTouching && !pipe.touched) {
pipe.touched = true;
LK.getSound('touch').play();
// Visual feedback
LK.effects.flashObject(pipe, 0xFF0000, 300);
// Bird dies when touching pipe
bird.die();
}
pipe.lastTouching = currentTouching;
}
// Check if bird successfully avoided pipes (score condition)
for (var j = 0; j < pipes.length; j++) {
var checkPipe = pipes[j];
// If pipe has moved past the bird and wasn't touched, increase score
if (checkPipe.x < bird.x - 100 && !checkPipe.touched && !checkPipe.scored) {
checkPipe.scored = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
// Visual feedback for successful avoidance
LK.effects.flashObject(checkPipe, 0x00FF00, 300);
}
}
}
};