/****
* Classes
****/
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Bird class to represent the player's character
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('parrot', {
anchorX: 0.5,
anchorY: 0.5
});
birdGraphics.scaleX = 1.5; // Adjust scale to give a parrot-like shape
birdGraphics.scaleY = 1.2;
self.velocity = 0;
self.gravity = 0.5; // Reduce gravity for slower descent
self.flapStrength = -10;
self.update = function () {
self.velocity += self.gravity;
self.y += self.velocity;
self.y -= 0.5; // Add a slight upward force to create a floating effect
};
self.flap = function () {
self.velocity = self.flapStrength;
};
});
// Hand class to represent a hand obstacle
var Hand = Container.expand(function () {
var self = Container.call(this);
var handGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -7; // Faster than regular obstacles
self.update = function () {
self.x += self.speed;
};
});
// Obstacle class to represent obstacles
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
};
});
// Pipe class to represent obstacles
var Pipe = Container.expand(function () {
var self = Container.call(this);
var pipeGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
};
});
// Wood class to represent side obstacles
var Wood = Container.expand(function () {
var self = Container.call(this);
var woodGraphics = self.attachAsset('wood', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Wood is static, no update logic needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
var bird = game.addChild(new Bird());
bird.x = 2048 / 4;
bird.y = 2732 / 2;
var pipes = [];
var pipeInterval = 1500;
var currentLevel = 1;
var maxLevels = 80;
var levelInterval = 5000; // Time in ticks to increase level
var lastLevelUpTime = 0;
var lastPipeTime = 0;
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.down = function (x, y, obj) {
bird.flap();
bird.y -= 10; // Additional upward movement on flap
};
game.update = function () {
bird.update();
// Add wood obstacles to the sides of the game
if (!this.leftWood) {
this.leftWood = new Wood();
this.leftWood.x = 50; // Adjusted position for larger wood
this.leftWood.y = 2732 / 2;
game.addChild(this.leftWood);
}
if (!this.rightWood) {
this.rightWood = new Wood();
this.rightWood.x = 2048 - 50; // Adjusted position for larger wood
this.rightWood.y = 2732 / 2;
game.addChild(this.rightWood);
}
if (!this.topWood) {
this.topWood = new Wood();
this.topWood.rotation = Math.PI / 4; // Rotate to form a triangle
this.topWood.x = 2048 / 2;
this.topWood.y = 100; // Position at the top
game.addChild(this.topWood);
}
if (bird.y > 2732 || bird.y < 0) {
LK.showGameOver();
}
if (LK.ticks - lastLevelUpTime > levelInterval && currentLevel < maxLevels) {
currentLevel++;
pipeInterval = Math.max(500, pipeInterval - 10); // Decrease interval to increase difficulty
lastLevelUpTime = LK.ticks;
}
if (LK.ticks - lastPipeTime > pipeInterval) {
var obstacle;
if (Math.random() > 0.5) {
obstacle = new Obstacle();
} else {
obstacle = new Hand();
}
obstacle.x = 2048;
obstacle.y = Math.random() * (2732 - 400) + 200;
pipes.push(obstacle);
game.addChild(obstacle);
lastPipeTime = LK.ticks;
}
for (var i = pipes.length - 1; i >= 0; i--) {
pipes[i].update();
if (pipes[i].x < -100) {
pipes[i].destroy();
pipes.splice(i, 1);
score++;
scoreTxt.setText(score);
}
if (bird.intersects(pipes[i])) {
LK.showGameOver();
}
}
};