User prompt
arka plan rengi biraz daha koyu
User prompt
ve x ekseninde eşit büyüt
User prompt
y de azıcık aşağı al arka planı
User prompt
bir kaç pikcel yukarı
User prompt
biraz daha
User prompt
daha koyu bir gri olsu arka plan
User prompt
yazıyı siyah yap pongi
User prompt
pongi play yazı stili olsun
User prompt
yazıyı play yazı stili yap
User prompt
teko regular yazı stili yap
User prompt
her sayaç sayı değişince sayac sesi gelsin.
User prompt
cubuk1 sesi paddle her hareket ederken çuksın.
User prompt
fon1 sürekli çal
User prompt
fon her zaman çalsın müzik olan
User prompt
top ve padle çarptığında carp1 çalsın
User prompt
top her çarptığında carp1 çal
User prompt
biraz daha hızlansın kendi hareket eden peddle
User prompt
tireme oldu düzelt
User prompt
titremne oluyor düzelt
User prompt
hala tireme olyor kendi harket eden paddle de
/****
* Classes
****/
// 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;
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// 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: 400,
height: 200,
color: 0x505050,
alpha: 0.5,
anchorX: 0.5,
anchorY: 0.5
});
startTextBackground.x = 0;
startTextBackground.y = 0;
LK.gui.center.addChild(startTextBackground);
var startText = new Text2('Pongi', {
size: 200,
fill: 0xFFFFFF,
font: "Jura",
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);
// Initialize gameStarted variable
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;
}
// 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);
}
ball.speedX *= -1.05; // Slight acceleration on paddle hit
}
if (ball.intersects(rightPaddle)) {
if (ball.y < rightPaddle.y) {
ball.speedY = -Math.abs(ball.speedY);
} else {
ball.speedY = Math.abs(ball.speedY);
}
ball.speedX *= -1.05; // Slight acceleration on paddle hit
}
// 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 += rightPaddle.speed;
} else if (ball.y < rightPaddle.y) {
rightPaddle.y -= rightPaddle.speed;
}
}
};
}, 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: "Jura" // Change font style to Jura
});
var rightScoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF,
font: "Jura" // Change font style to Jura
});
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);
}
// Handle paddle movement
game.move = function (x, y, obj) {
if (x < 2048 / 2) {
leftPaddle.y = y;
}
};
// 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;
}
// 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);
}
ball.speedX *= -1.05; // Slight acceleration on paddle hit
}
if (ball.intersects(rightPaddle)) {
if (ball.y < rightPaddle.y) {
ball.speedY = -Math.abs(ball.speedY);
} else {
ball.speedY = Math.abs(ball.speedY);
}
ball.speedX *= -1.05; // Slight acceleration on paddle hit
}
// 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 += rightPaddle.speed;
} else if (ball.y < rightPaddle.y) {
rightPaddle.y -= rightPaddle.speed;
}
}
};
// 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);
}