/**** * Classes ****/ //<Write imports for supported plugins here> // Ball class for game ball 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 () { if (gameStarted) { self.x += self.speedX; self.y += self.speedY; // Limit the maximum speed of the ball var maxSpeed = 20; self.speedX = Math.max(Math.min(self.speedX, maxSpeed), -maxSpeed); self.speedY = Math.max(Math.min(self.speedY, maxSpeed), -maxSpeed); // Create a trailing effect by adding a fading circle behind the ball var trail = LK.getAsset('ball', { anchorX: 0.5, anchorY: 0.5, alpha: 0.2 // Set a low alpha for a fading effect }); trail.x = self.x; trail.y = self.y; game.addChild(trail); // Fade out and remove the trail after a short duration LK.setTimeout(function () { game.removeChild(trail); }, 300); // Ensure ball speed is consistent to prevent shaking if (Math.abs(self.speedX) < 1) { self.speedX = self.speedX < 0 ? -1 : 1; } if (Math.abs(self.speedY) < 1) { self.speedY = self.speedY < 0 ? -1 : 1; } } }; }); // Paddle class for player control var Paddle = Container.expand(function () { var self = Container.call(this); var paddleGraphics = self.attachAsset('paddle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.update = function () { // Paddle movement logic will be handled in game code }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Display 'Pongi' text in the center of the screen before the game starts var startTextBackground = LK.getAsset('paddle', { width: 600, // Increased width for better visibility height: 200, color: 0x303030, alpha: 0.5, anchorX: 0.5, anchorY: 0.5 }); startTextBackground.scaleX = 1.5; startTextBackground.x = 0; startTextBackground.y = 10; LK.gui.center.addChild(startTextBackground); var startText = new Text2('Pongi v2', { size: 200, fill: 0x000000, font: "Teko Regular", shadow: { color: 0x808080, blur: 10, offsetX: 5, offsetY: 5 } }); startText.anchor.set(0.5, 0.5); startText.x = 0; // Position at top-left corner horizontally startText.y = 0; // Position at top-left corner vertically LK.gui.center.addChild(startText); // Play background music continuously LK.playMusic('fon'); var gameStarted = false; // Remove the start text and background, then begin the game after a delay LK.setTimeout(function () { LK.gui.center.removeChild(startText); LK.gui.center.removeChild(startTextBackground); gameStarted = true; // Start the game logic by enabling the game update loop game.update = function () { ball.update(); // Ball collision with top and bottom if (ball.y <= 0 && ball.speedY < 0 || ball.y >= 2732 && ball.speedY > 0) { ball.speedY *= -1; // Play 'carp1' sound effect LK.getSound('carp1').play(); } // Ball collision with paddles if (ball.intersects(leftPaddle)) { if (ball.y < leftPaddle.y) { ball.speedY = -Math.abs(ball.speedY); } else { ball.speedY = Math.abs(ball.speedY); } // Increase ball speed more significantly if right player has scored 5 points if (rightScore >= 5) { ball.speedX *= -1.2; // Greater acceleration on paddle hit } else { ball.speedX *= -1.05; // Slight acceleration on paddle hit } // Ensure ball speed is consistent to prevent shaking if (Math.abs(ball.speedX) < 1) { ball.speedX = ball.speedX < 0 ? -1 : 1; } if (Math.abs(ball.speedY) < 1) { ball.speedY = ball.speedY < 0 ? -1 : 1; } // Play 'carp1' sound effect LK.getSound('carp1').play(); } if (ball.intersects(rightPaddle)) { if (ball.y < rightPaddle.y) { ball.speedY = -Math.abs(ball.speedY); } else { ball.speedY = Math.abs(ball.speedY); } // Increase ball speed more significantly if right player has scored 5 points if (rightScore >= 5) { ball.speedX *= -1.2; // Greater acceleration on paddle hit } else { ball.speedX *= -1.05; // Slight acceleration on paddle hit } // Ensure ball speed is consistent to prevent shaking if (Math.abs(ball.speedX) < 1) { ball.speedX = ball.speedX < 0 ? -1 : 1; } if (Math.abs(ball.speedY) < 1) { ball.speedY = ball.speedY < 0 ? -1 : 1; } // Play 'carp1' sound effect LK.getSound('carp1').play(); } // Scoring if (ball.x <= 0) { rightScore++; updateScore(); if (rightScore >= 10) { LK.showGameOver("Right Player Wins!"); } else { resetBall(); } } else if (ball.x >= 2048) { leftScore++; updateScore(); if (leftScore >= 10) { LK.showGameOver("Left Player Wins!"); } else { resetBall(); } } // Automatic movement for right paddle only when the ball is moving towards it if (ball.speedX > 0) { if (ball.y > rightPaddle.y) { rightPaddle.y += Math.min(rightPaddle.speed * 1.5, Math.abs(ball.y - rightPaddle.y)); } else if (ball.y < rightPaddle.y) { rightPaddle.y -= Math.min(rightPaddle.speed * 1.5, Math.abs(ball.y - rightPaddle.y)); } } }; }, 3000); // 3 seconds delay // Create a dashed line in the center of the screen var centerLine = new Container(); var lineHeight = 20; var lineSpacing = 20; for (var y = 0; y < 2732; y += lineHeight + lineSpacing) { var lineSegment = LK.getAsset('paddle', { width: 10, height: lineHeight, color: 0xffffff, anchorX: 0.5, anchorY: 0.5 }); lineSegment.x = 2048 / 2; lineSegment.y = y + lineHeight / 2; centerLine.addChild(lineSegment); } game.addChild(centerLine); // Initialize paddles and ball var leftPaddle = game.addChild(new Paddle()); var rightPaddle = game.addChild(new Paddle()); var ball = game.addChild(new Ball()); // Position paddles and ball leftPaddle.x = 100; leftPaddle.y = 2732 / 2; rightPaddle.x = 2048 - 50; rightPaddle.y = 2732 / 2; ball.x = 2048 / 2; ball.y = 2732 / 2; // Score variables var leftScore = 0; var rightScore = 0; // Score display var leftScoreTxt = new Text2('0', { size: 100, fill: 0xFFFFFF, font: "Teko Regular" // Change font style to Teko Regular }); var rightScoreTxt = new Text2('0', { size: 100, fill: 0xFFFFFF, font: "Teko Regular" // Change font style to Teko Regular }); leftScoreTxt.anchor.set(0.5, 0); leftScoreTxt.x += 600; rightScoreTxt.anchor.set(0.5, 0); rightScoreTxt.x -= 600; // Decrease the x-axis position by 600 LK.gui.topLeft.addChild(leftScoreTxt); LK.gui.topRight.addChild(rightScoreTxt); // Update score display function updateScore() { leftScoreTxt.setText(leftScore); rightScoreTxt.setText(rightScore); // Check if right player has scored 5 points if (rightScore === 5) { // Change left paddle color to blue and increase its height by 1.5 times leftPaddle.children[0].tint = 0x0000FF; // Assuming the paddle graphics is the first child leftPaddle.children[0].scaleY = 1.5; // Increase height by 1.5 times // Reduce the speed of the right paddle by 1.5 times rightPaddle.speed /= 1.5; // Schedule 'upgrade' sound effect to play 2 seconds later LK.setTimeout(function () { LK.getSound('upgrade').play(); }, 2000); // Create 'Upgrade' text in blue var upgradeText = new Text2('Upgrade', { size: 200, fill: 0x0000FF, // Blue color font: "Teko Regular", shadow: { color: 0x000080, blur: 10, offsetX: 5, offsetY: 5 } }); upgradeText.anchor.set(0.5, 0.5); upgradeText.x = 0; // Center horizontally upgradeText.y = 0; // Center vertically LK.gui.center.addChild(upgradeText); // Remove the 'Upgrade' text after a short duration LK.setTimeout(function () { LK.gui.center.removeChild(upgradeText); }, 1000); // Display for 1 second } // Check if left player has scored 9 points if (leftScore === 9) { // Change right paddle color to red and decrease its height by 2 times rightPaddle.children[0].tint = 0xFF0000; // Assuming the paddle graphics is the first child rightPaddle.children[0].scaleY = 0.5; // Decrease height by 2 times // Triple the speed of the right paddle rightPaddle.speed *= 3; // Increase the speed of the right paddle when it turns red rightPaddle.speed *= 2; // Create 'Pro Bot' text in red var proBotText = new Text2('Pro Bot', { size: 200, fill: 0xFF0000, // Red color font: "Teko Regular", shadow: { color: 0x800000, blur: 10, offsetX: 5, offsetY: 5 } }); proBotText.anchor.set(0.5, 0.5); proBotText.x = 0; // Center horizontally proBotText.y = 0; // Center vertically LK.gui.center.addChild(proBotText); // Remove the 'Pro Bot' text after a short duration LK.setTimeout(function () { LK.gui.center.removeChild(proBotText); }, 1000); // Display for 1 second } // Play 'sayac' sound effect LK.getSound('sayac').play(); } // Handle paddle movement game.move = function (x, y, obj) { if (x < 2048 / 2) { leftPaddle.y = y; LK.getSound('cubuk1').play(); } }; // Reset ball to center function resetBall() { ball.x = 2048 / 2; ball.y = 2732 / 2; ball.speedX = 5 * (Math.random() > 0.5 ? 1 : -1); ball.speedY = 5 * (Math.random() > 0.5 ? 1 : -1); }
/****
* Classes
****/
//<Write imports for supported plugins here>
// Ball class for game ball
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 () {
if (gameStarted) {
self.x += self.speedX;
self.y += self.speedY;
// Limit the maximum speed of the ball
var maxSpeed = 20;
self.speedX = Math.max(Math.min(self.speedX, maxSpeed), -maxSpeed);
self.speedY = Math.max(Math.min(self.speedY, maxSpeed), -maxSpeed);
// Create a trailing effect by adding a fading circle behind the ball
var trail = LK.getAsset('ball', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.2 // Set a low alpha for a fading effect
});
trail.x = self.x;
trail.y = self.y;
game.addChild(trail);
// Fade out and remove the trail after a short duration
LK.setTimeout(function () {
game.removeChild(trail);
}, 300);
// Ensure ball speed is consistent to prevent shaking
if (Math.abs(self.speedX) < 1) {
self.speedX = self.speedX < 0 ? -1 : 1;
}
if (Math.abs(self.speedY) < 1) {
self.speedY = self.speedY < 0 ? -1 : 1;
}
}
};
});
// Paddle class for player control
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
// Paddle movement logic will be handled in game code
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Display 'Pongi' text in the center of the screen before the game starts
var startTextBackground = LK.getAsset('paddle', {
width: 600,
// Increased width for better visibility
height: 200,
color: 0x303030,
alpha: 0.5,
anchorX: 0.5,
anchorY: 0.5
});
startTextBackground.scaleX = 1.5;
startTextBackground.x = 0;
startTextBackground.y = 10;
LK.gui.center.addChild(startTextBackground);
var startText = new Text2('Pongi v2', {
size: 200,
fill: 0x000000,
font: "Teko Regular",
shadow: {
color: 0x808080,
blur: 10,
offsetX: 5,
offsetY: 5
}
});
startText.anchor.set(0.5, 0.5);
startText.x = 0; // Position at top-left corner horizontally
startText.y = 0; // Position at top-left corner vertically
LK.gui.center.addChild(startText);
// Play background music continuously
LK.playMusic('fon');
var gameStarted = false;
// Remove the start text and background, then begin the game after a delay
LK.setTimeout(function () {
LK.gui.center.removeChild(startText);
LK.gui.center.removeChild(startTextBackground);
gameStarted = true;
// Start the game logic by enabling the game update loop
game.update = function () {
ball.update();
// Ball collision with top and bottom
if (ball.y <= 0 && ball.speedY < 0 || ball.y >= 2732 && ball.speedY > 0) {
ball.speedY *= -1;
// Play 'carp1' sound effect
LK.getSound('carp1').play();
}
// Ball collision with paddles
if (ball.intersects(leftPaddle)) {
if (ball.y < leftPaddle.y) {
ball.speedY = -Math.abs(ball.speedY);
} else {
ball.speedY = Math.abs(ball.speedY);
}
// Increase ball speed more significantly if right player has scored 5 points
if (rightScore >= 5) {
ball.speedX *= -1.2; // Greater acceleration on paddle hit
} else {
ball.speedX *= -1.05; // Slight acceleration on paddle hit
}
// Ensure ball speed is consistent to prevent shaking
if (Math.abs(ball.speedX) < 1) {
ball.speedX = ball.speedX < 0 ? -1 : 1;
}
if (Math.abs(ball.speedY) < 1) {
ball.speedY = ball.speedY < 0 ? -1 : 1;
}
// Play 'carp1' sound effect
LK.getSound('carp1').play();
}
if (ball.intersects(rightPaddle)) {
if (ball.y < rightPaddle.y) {
ball.speedY = -Math.abs(ball.speedY);
} else {
ball.speedY = Math.abs(ball.speedY);
}
// Increase ball speed more significantly if right player has scored 5 points
if (rightScore >= 5) {
ball.speedX *= -1.2; // Greater acceleration on paddle hit
} else {
ball.speedX *= -1.05; // Slight acceleration on paddle hit
}
// Ensure ball speed is consistent to prevent shaking
if (Math.abs(ball.speedX) < 1) {
ball.speedX = ball.speedX < 0 ? -1 : 1;
}
if (Math.abs(ball.speedY) < 1) {
ball.speedY = ball.speedY < 0 ? -1 : 1;
}
// Play 'carp1' sound effect
LK.getSound('carp1').play();
}
// Scoring
if (ball.x <= 0) {
rightScore++;
updateScore();
if (rightScore >= 10) {
LK.showGameOver("Right Player Wins!");
} else {
resetBall();
}
} else if (ball.x >= 2048) {
leftScore++;
updateScore();
if (leftScore >= 10) {
LK.showGameOver("Left Player Wins!");
} else {
resetBall();
}
}
// Automatic movement for right paddle only when the ball is moving towards it
if (ball.speedX > 0) {
if (ball.y > rightPaddle.y) {
rightPaddle.y += Math.min(rightPaddle.speed * 1.5, Math.abs(ball.y - rightPaddle.y));
} else if (ball.y < rightPaddle.y) {
rightPaddle.y -= Math.min(rightPaddle.speed * 1.5, Math.abs(ball.y - rightPaddle.y));
}
}
};
}, 3000); // 3 seconds delay
// Create a dashed line in the center of the screen
var centerLine = new Container();
var lineHeight = 20;
var lineSpacing = 20;
for (var y = 0; y < 2732; y += lineHeight + lineSpacing) {
var lineSegment = LK.getAsset('paddle', {
width: 10,
height: lineHeight,
color: 0xffffff,
anchorX: 0.5,
anchorY: 0.5
});
lineSegment.x = 2048 / 2;
lineSegment.y = y + lineHeight / 2;
centerLine.addChild(lineSegment);
}
game.addChild(centerLine);
// Initialize paddles and ball
var leftPaddle = game.addChild(new Paddle());
var rightPaddle = game.addChild(new Paddle());
var ball = game.addChild(new Ball());
// Position paddles and ball
leftPaddle.x = 100;
leftPaddle.y = 2732 / 2;
rightPaddle.x = 2048 - 50;
rightPaddle.y = 2732 / 2;
ball.x = 2048 / 2;
ball.y = 2732 / 2;
// Score variables
var leftScore = 0;
var rightScore = 0;
// Score display
var leftScoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF,
font: "Teko Regular" // Change font style to Teko Regular
});
var rightScoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF,
font: "Teko Regular" // Change font style to Teko Regular
});
leftScoreTxt.anchor.set(0.5, 0);
leftScoreTxt.x += 600;
rightScoreTxt.anchor.set(0.5, 0);
rightScoreTxt.x -= 600; // Decrease the x-axis position by 600
LK.gui.topLeft.addChild(leftScoreTxt);
LK.gui.topRight.addChild(rightScoreTxt);
// Update score display
function updateScore() {
leftScoreTxt.setText(leftScore);
rightScoreTxt.setText(rightScore);
// Check if right player has scored 5 points
if (rightScore === 5) {
// Change left paddle color to blue and increase its height by 1.5 times
leftPaddle.children[0].tint = 0x0000FF; // Assuming the paddle graphics is the first child
leftPaddle.children[0].scaleY = 1.5; // Increase height by 1.5 times
// Reduce the speed of the right paddle by 1.5 times
rightPaddle.speed /= 1.5;
// Schedule 'upgrade' sound effect to play 2 seconds later
LK.setTimeout(function () {
LK.getSound('upgrade').play();
}, 2000);
// Create 'Upgrade' text in blue
var upgradeText = new Text2('Upgrade', {
size: 200,
fill: 0x0000FF,
// Blue color
font: "Teko Regular",
shadow: {
color: 0x000080,
blur: 10,
offsetX: 5,
offsetY: 5
}
});
upgradeText.anchor.set(0.5, 0.5);
upgradeText.x = 0; // Center horizontally
upgradeText.y = 0; // Center vertically
LK.gui.center.addChild(upgradeText);
// Remove the 'Upgrade' text after a short duration
LK.setTimeout(function () {
LK.gui.center.removeChild(upgradeText);
}, 1000); // Display for 1 second
}
// Check if left player has scored 9 points
if (leftScore === 9) {
// Change right paddle color to red and decrease its height by 2 times
rightPaddle.children[0].tint = 0xFF0000; // Assuming the paddle graphics is the first child
rightPaddle.children[0].scaleY = 0.5; // Decrease height by 2 times
// Triple the speed of the right paddle
rightPaddle.speed *= 3;
// Increase the speed of the right paddle when it turns red
rightPaddle.speed *= 2;
// Create 'Pro Bot' text in red
var proBotText = new Text2('Pro Bot', {
size: 200,
fill: 0xFF0000,
// Red color
font: "Teko Regular",
shadow: {
color: 0x800000,
blur: 10,
offsetX: 5,
offsetY: 5
}
});
proBotText.anchor.set(0.5, 0.5);
proBotText.x = 0; // Center horizontally
proBotText.y = 0; // Center vertically
LK.gui.center.addChild(proBotText);
// Remove the 'Pro Bot' text after a short duration
LK.setTimeout(function () {
LK.gui.center.removeChild(proBotText);
}, 1000); // Display for 1 second
}
// Play 'sayac' sound effect
LK.getSound('sayac').play();
}
// Handle paddle movement
game.move = function (x, y, obj) {
if (x < 2048 / 2) {
leftPaddle.y = y;
LK.getSound('cubuk1').play();
}
};
// Reset ball to center
function resetBall() {
ball.x = 2048 / 2;
ball.y = 2732 / 2;
ball.speedX = 5 * (Math.random() > 0.5 ? 1 : -1);
ball.speedY = 5 * (Math.random() > 0.5 ? 1 : -1);
}