/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Bird class to handle the bird's behavior
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.5;
self.lift = -10;
self.update = function () {
self.velocity += self.gravity;
self.y += self.velocity;
// Prevent bird from going off the top of the screen
if (self.y < 0) {
self.y = 0;
self.velocity = 0;
}
};
self.flap = function () {
self.velocity = self.lift;
};
});
// Pipe class to handle the pipe's behavior
var Pipe = Container.expand(function () {
var self = Container.call(this);
var pipeGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.x -= 2;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB,
// Sky blue background
width: 4096,
height: 5464
});
/****
* Game Code
****/
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048,
y: 2700
}));
// Initialize game variables
var bird;
var pipes = [];
var pipeSpacing = 600;
var pipeGap = 400;
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
// Create the "Glaud" text in orange color
var glaudText = new Text2('Glaud', {
size: 80,
fill: 0xFFA500 // Orange color
});
glaudText.anchor.set(1, 0); // Anchor at the top right
LK.gui.topRight.addChild(glaudText);
// Add a pipe at position (0,0)
var pipe = game.addChild(new Pipe());
pipe.x = 1000;
pipe.y = 0;
pipes.push(pipe);
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create a start screen
var startScreen = new Container();
var startText = new Text2('Tap to start', {
size: 150,
fill: 0xFFFFFF
});
startText.anchor.set(0.5, 0.5);
startText.x = 2048 / 2;
startText.y = 2732 / 2;
startScreen.addChild(startText);
game.addChild(startScreen);
// Handle screen tap to start the game
startScreen.down = function (x, y, obj) {
if (!bird) {
bird = game.addChild(new Bird());
bird.x = 2048 / 4;
bird.y = 2732 / 2;
game.removeChild(startScreen);
}
};
// Handle screen tap to make the bird flap
game.down = function (x, y, obj) {
if (bird) {
bird.flap();
bird.y -= 300; // Make the bird fly even higher when clicked
}
};
// Update game logic
game.update = function () {
if (typeof document !== 'undefined' && document.hidden) {
return;
}
if (bird) {
bird.update();
}
// Add new pipes periodically
if (LK.ticks % 300 == 0) {
var pipeTop = game.addChild(new Pipe());
pipeTop.x = 2048; // position pipe on the left side of the screen
pipeTop.y = Math.random() * (2732 - pipeGap);
pipes.push(pipeTop);
var pipeBottom = game.addChild(new Pipe());
pipeBottom.x = 2048; // position pipe on the left side of the screen
pipeBottom.y = pipeTop.y + pipeTop.height + pipeGap + 4000; // Increase the gap between pipes on the y-axis
pipes.push(pipeBottom);
}
for (var i = 0; i < pipes.length; i++) {
pipes[i].update();
if (bird && (bird.intersects(ground) || bird.intersects(pipes[i]))) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Remove pipe if it's off the screen
if (pipes[i].x < -pipes[i].width) {
game.removeChild(pipes[i]);
pipes.splice(i, 1);
i--;
}
}
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Bird class to handle the bird's behavior
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.5;
self.lift = -10;
self.update = function () {
self.velocity += self.gravity;
self.y += self.velocity;
// Prevent bird from going off the top of the screen
if (self.y < 0) {
self.y = 0;
self.velocity = 0;
}
};
self.flap = function () {
self.velocity = self.lift;
};
});
// Pipe class to handle the pipe's behavior
var Pipe = Container.expand(function () {
var self = Container.call(this);
var pipeGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.x -= 2;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB,
// Sky blue background
width: 4096,
height: 5464
});
/****
* Game Code
****/
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048,
y: 2700
}));
// Initialize game variables
var bird;
var pipes = [];
var pipeSpacing = 600;
var pipeGap = 400;
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
// Create the "Glaud" text in orange color
var glaudText = new Text2('Glaud', {
size: 80,
fill: 0xFFA500 // Orange color
});
glaudText.anchor.set(1, 0); // Anchor at the top right
LK.gui.topRight.addChild(glaudText);
// Add a pipe at position (0,0)
var pipe = game.addChild(new Pipe());
pipe.x = 1000;
pipe.y = 0;
pipes.push(pipe);
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create a start screen
var startScreen = new Container();
var startText = new Text2('Tap to start', {
size: 150,
fill: 0xFFFFFF
});
startText.anchor.set(0.5, 0.5);
startText.x = 2048 / 2;
startText.y = 2732 / 2;
startScreen.addChild(startText);
game.addChild(startScreen);
// Handle screen tap to start the game
startScreen.down = function (x, y, obj) {
if (!bird) {
bird = game.addChild(new Bird());
bird.x = 2048 / 4;
bird.y = 2732 / 2;
game.removeChild(startScreen);
}
};
// Handle screen tap to make the bird flap
game.down = function (x, y, obj) {
if (bird) {
bird.flap();
bird.y -= 300; // Make the bird fly even higher when clicked
}
};
// Update game logic
game.update = function () {
if (typeof document !== 'undefined' && document.hidden) {
return;
}
if (bird) {
bird.update();
}
// Add new pipes periodically
if (LK.ticks % 300 == 0) {
var pipeTop = game.addChild(new Pipe());
pipeTop.x = 2048; // position pipe on the left side of the screen
pipeTop.y = Math.random() * (2732 - pipeGap);
pipes.push(pipeTop);
var pipeBottom = game.addChild(new Pipe());
pipeBottom.x = 2048; // position pipe on the left side of the screen
pipeBottom.y = pipeTop.y + pipeTop.height + pipeGap + 4000; // Increase the gap between pipes on the y-axis
pipes.push(pipeBottom);
}
for (var i = 0; i < pipes.length; i++) {
pipes[i].update();
if (bird && (bird.intersects(ground) || bird.intersects(pipes[i]))) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Remove pipe if it's off the screen
if (pipes[i].x < -pipes[i].width) {
game.removeChild(pipes[i]);
pipes.splice(i, 1);
i--;
}
}
};