/**** * Classes ****/ // Assets will be automatically created based on usage in the code. // Bird class var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); self.speedY = 10; self.flyUp = false; self._move_migrated = function () { // Bird falls down self.y += self.speedY; // If bird is flying up, decrease its y position if (self.flyUp) { self.speedY -= 80; if (self.speedY <= -10) { self.flyUp = false; } } else { self.speedY += 10; if (self.speedY > 10) { self.speedY = 11; } } }; }); // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5, shape: 'ellipse' }); self.speedX = -5; self._move_migrated = function () { // Obstacle moves from right to left self.x += self.speedX; // Rotate obstacle counterclockwise // self.rotation -= 0.17; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background to simulate sky }); /**** * Game Code ****/ // Add background to the game var background = game.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2048 / 2 })); var bird = game.addChild(new Bird()); bird.x = 350; // Start in the middle of the screen horizontally bird.y = 1366; // Start in the middle of the screen vertically // Add touch event listener to make bird move up and down smoothly game.on('down', function (x, y, obj) { bird.flyUp = true; // bird.rotation += Math.PI / 2; // Rotate 90 degrees bird.scale.y = 0.7; // Reduce bird size vertically by 10% LK.setTimeout(function () { bird.scale.y = 1; // Return bird to original size after 100ms }, 100); // Play 'Jump' sound when the screen is pressed LK.getSound('Jump').play(); }); var obstacles = []; var obstacleCreationCounter = 0; var score = 0; // Add a variable to track the player's score LK.on('tick', function () { bird._move_migrated(); // Create a new obstacle every 42 ticks (approximately 0.7 seconds) obstacleCreationCounter++; if (score < 15 && obstacleCreationCounter >= 36 || score >= 15 && score < 30 && obstacleCreationCounter >= 30 || score >= 30 && score < 45 && obstacleCreationCounter >= 24 || score >= 45 && score < 60 && obstacleCreationCounter >= 24 || score >= 60 && obstacleCreationCounter >= 18) { var newObstacle = game.addChild(new Obstacle()); newObstacle.x = 2048; // Start at the right edge of the screen newObstacle.y = Math.random() * 2732; // Start at a random height // After 10 points, randomly change obstacle speed between -4 and -9 if (score > 25) { newObstacle.speedX = Math.floor(Math.random() * (-10 + 4 + 1)) + -4; } else if (obstacles.length % 10 == 9) { newObstacle.speedX = -13; } obstacles.push(newObstacle); obstacleCreationCounter = 0; } // If the player's score is 13 or more, make the obstacles move up and down if (score >= 13) { for (var i = 0; i < obstacles.length; i++) { var obstacle = obstacles[i]; obstacle.y += Math.sin(obstacle.x * 0.01) * 5; // Change the y position of the obstacle based on a sine wave } } // Move each obstacle and check for collisions for (var i = 0; i < obstacles.length; i++) { var obstacle = obstacles[i]; obstacle._move_migrated(); // Check if bird has collided with the obstacle var dx = bird.x - obstacle.x; var dy = bird.y - obstacle.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < bird.width / 2 + obstacle.width / 2) { // Play 'chainsaw' sound when the bird collides with an obstacle LK.getSound('chainsaw').play(); // Flash screen red for 1 second (1000ms) to show game over. LK.effects.flashScreen(0xff0000, 1000); // Show game over. The game will be automatically paused while game over is showing. LK.showGameOver(); } } // Check if bird has fallen off the screen or risen above the screen var dx = bird.x - 2048 / 2; var dy = bird.y - 2670 / 2; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 3000 / 2) { // Flash screen red for 1 second (1000ms) to show game over. LK.effects.flashScreen(0xff0000, 1000); // Show game over. The game will be automatically paused while game over is showing. LK.showGameOver(); } }); // Initialize bird and obstacles // Yellow bird // Brown obstacles; var obstacle = game.addChild(new Obstacle()); obstacle.x = 2120; // Start at the right edge of the screen obstacle.y = Math.random() * 2732; // Start at a random height; // Initialize score counter var score = 0; var scoreTxt = new Text2(score.toString(), { size: 75, fill: 0xFFFFFF }); scoreTxt.anchor.set(1, 0); // Anchor to the top right corner LK.gui.topRight.addChild(scoreTxt); // Update score every 2 seconds LK.setInterval(function () { score++; scoreTxt.setText(score.toString()); // Save the score LK.setScore(score); }, 1300); ;
/****
* Classes
****/
// Assets will be automatically created based on usage in the code.
// Bird class
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedY = 10;
self.flyUp = false;
self._move_migrated = function () {
// Bird falls down
self.y += self.speedY;
// If bird is flying up, decrease its y position
if (self.flyUp) {
self.speedY -= 80;
if (self.speedY <= -10) {
self.flyUp = false;
}
} else {
self.speedY += 10;
if (self.speedY > 10) {
self.speedY = 11;
}
}
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5,
shape: 'ellipse'
});
self.speedX = -5;
self._move_migrated = function () {
// Obstacle moves from right to left
self.x += self.speedX;
// Rotate obstacle counterclockwise
// self.rotation -= 0.17;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to simulate sky
});
/****
* Game Code
****/
// Add background to the game
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2048 / 2
}));
var bird = game.addChild(new Bird());
bird.x = 350; // Start in the middle of the screen horizontally
bird.y = 1366; // Start in the middle of the screen vertically
// Add touch event listener to make bird move up and down smoothly
game.on('down', function (x, y, obj) {
bird.flyUp = true;
// bird.rotation += Math.PI / 2; // Rotate 90 degrees
bird.scale.y = 0.7; // Reduce bird size vertically by 10%
LK.setTimeout(function () {
bird.scale.y = 1; // Return bird to original size after 100ms
}, 100);
// Play 'Jump' sound when the screen is pressed
LK.getSound('Jump').play();
});
var obstacles = [];
var obstacleCreationCounter = 0;
var score = 0; // Add a variable to track the player's score
LK.on('tick', function () {
bird._move_migrated();
// Create a new obstacle every 42 ticks (approximately 0.7 seconds)
obstacleCreationCounter++;
if (score < 15 && obstacleCreationCounter >= 36 || score >= 15 && score < 30 && obstacleCreationCounter >= 30 || score >= 30 && score < 45 && obstacleCreationCounter >= 24 || score >= 45 && score < 60 && obstacleCreationCounter >= 24 || score >= 60 && obstacleCreationCounter >= 18) {
var newObstacle = game.addChild(new Obstacle());
newObstacle.x = 2048; // Start at the right edge of the screen
newObstacle.y = Math.random() * 2732; // Start at a random height
// After 10 points, randomly change obstacle speed between -4 and -9
if (score > 25) {
newObstacle.speedX = Math.floor(Math.random() * (-10 + 4 + 1)) + -4;
} else if (obstacles.length % 10 == 9) {
newObstacle.speedX = -13;
}
obstacles.push(newObstacle);
obstacleCreationCounter = 0;
}
// If the player's score is 13 or more, make the obstacles move up and down
if (score >= 13) {
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
obstacle.y += Math.sin(obstacle.x * 0.01) * 5; // Change the y position of the obstacle based on a sine wave
}
}
// Move each obstacle and check for collisions
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
obstacle._move_migrated();
// Check if bird has collided with the obstacle
var dx = bird.x - obstacle.x;
var dy = bird.y - obstacle.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < bird.width / 2 + obstacle.width / 2) {
// Play 'chainsaw' sound when the bird collides with an obstacle
LK.getSound('chainsaw').play();
// Flash screen red for 1 second (1000ms) to show game over.
LK.effects.flashScreen(0xff0000, 1000);
// Show game over. The game will be automatically paused while game over is showing.
LK.showGameOver();
}
}
// Check if bird has fallen off the screen or risen above the screen
var dx = bird.x - 2048 / 2;
var dy = bird.y - 2670 / 2;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 3000 / 2) {
// Flash screen red for 1 second (1000ms) to show game over.
LK.effects.flashScreen(0xff0000, 1000);
// Show game over. The game will be automatically paused while game over is showing.
LK.showGameOver();
}
});
// Initialize bird and obstacles
// Yellow bird
// Brown obstacles;
var obstacle = game.addChild(new Obstacle());
obstacle.x = 2120; // Start at the right edge of the screen
obstacle.y = Math.random() * 2732; // Start at a random height;
// Initialize score counter
var score = 0;
var scoreTxt = new Text2(score.toString(), {
size: 75,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(1, 0); // Anchor to the top right corner
LK.gui.topRight.addChild(scoreTxt);
// Update score every 2 seconds
LK.setInterval(function () {
score++;
scoreTxt.setText(score.toString());
// Save the score
LK.setScore(score);
}, 1300);
;