/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Ball class
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 10;
self.speedY = -10;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.x <= 0 || self.x >= 2048) {
self.speedX *= -1;
}
if (self.y <= 0 || self.y >= 2732) {
self.speedY *= -1;
}
};
});
// Bonus class
var Bonus = Container.expand(function () {
var self = Container.call(this);
var bonusGraphics = self.attachAsset('bonus', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Bonus2 class
var Bonus2 = Container.expand(function () {
var self = Container.call(this);
var bonus2Graphics = self.attachAsset('bonus2', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Bonus3 class
var Bonus3 = Container.expand(function () {
var self = Container.call(this);
var bonus3Graphics = self.attachAsset('bonus3', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Paddle class
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Paddle movement logic will be handled in the game move event
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize game elements
var courtLines = LK.getAsset('courtLines', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
game.addChild(courtLines);
var ball = game.addChild(new Ball());
ball.x = 1024;
ball.y = 1366;
var paddle = game.addChild(new Paddle());
paddle.x = 1024;
paddle.y = 2500;
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Bonus appearance logic
var bonus;
var bonusVisible = false;
var bonus2Visible = false;
var bonus3Visible = false;
var bonusTimer = LK.setInterval(function () {
var positions = [{
x: 824,
y: 1366
},
// Left position
{
x: 1024,
y: 1366
},
// Center position
{
x: 1224,
y: 1366
} // Right position
];
// Shuffle positions array
for (var i = positions.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var _ref = [positions[j], positions[i]];
positions[i] = _ref[0];
positions[j] = _ref[1];
}
if (!bonusVisible) {
bonus = game.addChild(new Bonus());
bonus.x = positions[0].x;
bonus.y = positions[0].y;
bonusVisible = true;
LK.setTimeout(function () {
if (bonusVisible) {
game.removeChild(bonus);
bonusVisible = false;
}
}, 7000);
}
if (!bonus2Visible) {
bonus2 = game.addChild(new Bonus2());
bonus2.x = positions[1].x;
bonus2.y = positions[1].y;
bonus2Visible = true;
LK.setTimeout(function () {
if (bonus2Visible) {
game.removeChild(bonus2);
bonus2Visible = false;
}
}, 7000);
}
if (typeof bonus3Visible !== 'undefined' && !bonus3Visible) {
bonus3 = game.addChild(new Bonus3());
bonus3.x = positions[2].x;
bonus3.y = positions[2].y;
bonus3Visible = true;
LK.setTimeout(function () {
if (typeof bonus3Visible !== 'undefined' && bonus3Visible) {
game.removeChild(bonus3);
bonus3Visible = false;
}
}, 7000);
}
}, 5000);
// Handle paddle movement
game.move = function (x, y, obj) {
paddle.x = x;
};
// Update game logic
game.update = function () {
ball.update();
paddle.update();
if (ball.intersects(paddle)) {
ball.speedY *= -1;
score += 1;
scoreTxt.setText(score);
LK.getSound('ballSound').play(); // Play ball sound when the ball touches the paddle
}
if (ball.y > 2732) {
LK.showGameOver();
}
if (bonusVisible && ball.intersects(bonus)) {
score += 10;
scoreTxt.setText(score);
game.removeChild(bonus);
bonusVisible = false;
}
if (bonus2Visible && ball.intersects(bonus2)) {
score += 10;
scoreTxt.setText(score);
game.removeChild(bonus2);
bonus2Visible = false;
}
if (typeof bonus3Visible !== 'undefined' && bonus3Visible && ball.intersects(bonus3)) {
score += 10;
scoreTxt.setText(score);
game.removeChild(bonus3);
bonus3Visible = false;
}
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Ball class
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 10;
self.speedY = -10;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.x <= 0 || self.x >= 2048) {
self.speedX *= -1;
}
if (self.y <= 0 || self.y >= 2732) {
self.speedY *= -1;
}
};
});
// Bonus class
var Bonus = Container.expand(function () {
var self = Container.call(this);
var bonusGraphics = self.attachAsset('bonus', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Bonus2 class
var Bonus2 = Container.expand(function () {
var self = Container.call(this);
var bonus2Graphics = self.attachAsset('bonus2', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Bonus3 class
var Bonus3 = Container.expand(function () {
var self = Container.call(this);
var bonus3Graphics = self.attachAsset('bonus3', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Paddle class
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Paddle movement logic will be handled in the game move event
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize game elements
var courtLines = LK.getAsset('courtLines', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
game.addChild(courtLines);
var ball = game.addChild(new Ball());
ball.x = 1024;
ball.y = 1366;
var paddle = game.addChild(new Paddle());
paddle.x = 1024;
paddle.y = 2500;
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Bonus appearance logic
var bonus;
var bonusVisible = false;
var bonus2Visible = false;
var bonus3Visible = false;
var bonusTimer = LK.setInterval(function () {
var positions = [{
x: 824,
y: 1366
},
// Left position
{
x: 1024,
y: 1366
},
// Center position
{
x: 1224,
y: 1366
} // Right position
];
// Shuffle positions array
for (var i = positions.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var _ref = [positions[j], positions[i]];
positions[i] = _ref[0];
positions[j] = _ref[1];
}
if (!bonusVisible) {
bonus = game.addChild(new Bonus());
bonus.x = positions[0].x;
bonus.y = positions[0].y;
bonusVisible = true;
LK.setTimeout(function () {
if (bonusVisible) {
game.removeChild(bonus);
bonusVisible = false;
}
}, 7000);
}
if (!bonus2Visible) {
bonus2 = game.addChild(new Bonus2());
bonus2.x = positions[1].x;
bonus2.y = positions[1].y;
bonus2Visible = true;
LK.setTimeout(function () {
if (bonus2Visible) {
game.removeChild(bonus2);
bonus2Visible = false;
}
}, 7000);
}
if (typeof bonus3Visible !== 'undefined' && !bonus3Visible) {
bonus3 = game.addChild(new Bonus3());
bonus3.x = positions[2].x;
bonus3.y = positions[2].y;
bonus3Visible = true;
LK.setTimeout(function () {
if (typeof bonus3Visible !== 'undefined' && bonus3Visible) {
game.removeChild(bonus3);
bonus3Visible = false;
}
}, 7000);
}
}, 5000);
// Handle paddle movement
game.move = function (x, y, obj) {
paddle.x = x;
};
// Update game logic
game.update = function () {
ball.update();
paddle.update();
if (ball.intersects(paddle)) {
ball.speedY *= -1;
score += 1;
scoreTxt.setText(score);
LK.getSound('ballSound').play(); // Play ball sound when the ball touches the paddle
}
if (ball.y > 2732) {
LK.showGameOver();
}
if (bonusVisible && ball.intersects(bonus)) {
score += 10;
scoreTxt.setText(score);
game.removeChild(bonus);
bonusVisible = false;
}
if (bonus2Visible && ball.intersects(bonus2)) {
score += 10;
scoreTxt.setText(score);
game.removeChild(bonus2);
bonus2Visible = false;
}
if (typeof bonus3Visible !== 'undefined' && bonus3Visible && ball.intersects(bonus3)) {
score += 10;
scoreTxt.setText(score);
game.removeChild(bonus3);
bonus3Visible = false;
}
};