/****
* Classes
****/
// Ball class to handle ball behavior
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedY = 10;
self.directionY = 1; // 1 for down, -1 for up
self.update = function () {
if (self.directionY === -1) {
self.speedY -= 0.2; // Further reduced gravity effect for more bounce
if (self.speedY < 0) {
self.directionY = 1; // Change direction to down when speedY is zero or negative
}
} else {
self.speedY = 8; // Lower reset speed for more bounce
}
self.y += self.speedY * self.directionY;
if (self.y > 2732 - ballGraphics.height / 2) {
self.directionY = -1;
self.speedY = 10; // Reset speed when hitting the ground
} else if (self.y < ballGraphics.height / 2) {
self.directionY = 1;
}
};
});
// Boot class to handle boot behavior
var Boot = Container.expand(function () {
var self = Container.call(this);
var bootGraphics = self.attachAsset('boot', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize assets used in this game.
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Initialize game elements
var footballGround = LK.getAsset('footballGround', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(footballGround);
var ball = game.addChild(new Ball());
ball.x = 2048 / 2;
ball.y = 2732 / 4;
var boot = game.addChild(new Boot());
boot.x = 2048 / 2;
boot.y = 2732 - 200;
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle game move events
game.move = function (x, y, obj) {
boot.x = x;
boot.y = y;
};
// Handle game update
game.update = function () {
ball.update();
if (ball.intersects(boot)) {
ball.directionY = -1;
score += 1;
scoreTxt.setText(score);
}
if (ball.y > 2732 - ball.height / 2 || ball.y < ball.height / 2) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
Football ground from middle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A foot ball boot. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Football. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.