/****
* 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.speedX = 5;
self.move = function () {
self.x += self.speedX;
// Reverse direction when hitting screen bounds
if (self.x > 2048 - birdGraphics.width / 2 || self.x < birdGraphics.width / 2) {
self.speedX *= -1;
}
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedY = 3;
self.move = function () {
self.y += self.speedY;
// Remove obstacle when it moves off screen
if (self.y > 2732 + obstacleGraphics.height) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to simulate sky
});
/****
* Game Code
****/
var bird = game.addChild(new Bird());
bird.x = 1024; // Start in the middle of the screen horizontally
bird.y = 1366; // Start in the middle of the screen vertically
var obstacles = [];
var spawnObstacle = function () {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048; // Random horizontal position
obstacle.y = -100; // Start just above the screen
obstacles.push(obstacle);
game.addChild(obstacle);
};
// Spawn an obstacle every 2 seconds
var obstacleTimer = LK.setInterval(spawnObstacle, 2000);
LK.on('tick', function () {
bird.move();
obstacles.forEach(function (obstacle) {
obstacle.move();
// Check for collision with bird
if (bird.intersects(obstacle)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
LK.clearInterval(obstacleTimer); // Stop spawning obstacles
}
});
// Remove obstacles that have been destroyed (moved off screen)
obstacles = obstacles.filter(function (obstacle) {
return !obstacle.isDestroyed;
});
});
// Initialize bird and obstacles
// Yellow bird
// Brown obstacles
голубое небо, горизонт и зеленое поле. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Мультяшный квадратный сюрикен. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
button leaderboards. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.