/****
* Classes
****/
// Ball class to control the ball movement
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 5;
self.speedY = 5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Paddle class to control the paddle movement
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = 300;
self.height = 30;
self.speed = 20;
self.update = function () {
// Paddle update logic if needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize paddle and ball
var paddle = game.addChild(new Paddle());
paddle.x = 2048 / 2;
paddle.y = 2500;
var ball = game.addChild(new Ball());
ball.x = 2048 / 2;
ball.y = 2000;
// Score display
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle paddle movement
game.move = function (x, y, obj) {
paddle.x = x;
};
// Update game logic
game.update = function () {
ball.update();
// Ball collision with walls
if (ball.x <= 0 || ball.x >= 2048) {
ball.speedX *= -1;
}
if (ball.y <= 0) {
ball.speedY *= -1;
}
// Ball collision with paddle
if (ball.intersects(paddle)) {
ball.speedY *= -1;
score += 1;
scoreTxt.setText('Score: ' + score);
}
// Ball out of bounds
if (ball.y >= 2732) {
LK.showGameOver();
}
}; /****
* Classes
****/
// Ball class to control the ball movement
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 5;
self.speedY = 5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Paddle class to control the paddle movement
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = 300;
self.height = 30;
self.speed = 20;
self.update = function () {
// Paddle update logic if needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize paddle and ball
var paddle = game.addChild(new Paddle());
paddle.x = 2048 / 2;
paddle.y = 2500;
var ball = game.addChild(new Ball());
ball.x = 2048 / 2;
ball.y = 2000;
// Score display
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle paddle movement
game.move = function (x, y, obj) {
paddle.x = x;
};
// Update game logic
game.update = function () {
ball.update();
// Ball collision with walls
if (ball.x <= 0 || ball.x >= 2048) {
ball.speedX *= -1;
}
if (ball.y <= 0) {
ball.speedY *= -1;
}
// Ball collision with paddle
if (ball.intersects(paddle)) {
ball.speedY *= -1;
score += 1;
scoreTxt.setText('Score: ' + score);
}
// Ball out of bounds
if (ball.y >= 2732) {
LK.showGameOver();
}
};