User prompt
Paddle should not teleport
Code edit (1 edits merged)
Please save this source code
User prompt
Bold score text
User prompt
Black score text
User prompt
Add a background to the game
User prompt
Display the score on the top right
User prompt
Player gains a point when opponent misses ball. Player loses a point when he misses the ball
User prompt
Rate of increase should be one per five seconds
User prompt
Limit the number of increases to 5
User prompt
Let the increase happen every 5 seconds
User prompt
Ball speed changes every 10 seconds
User prompt
Decrease the acceleration of ball
User prompt
Ball gets faster with time
User prompt
Gradually increase the speed of ball
Initial prompt
Pong
/****
* Classes
****/
// 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 = 5;
self.speedY = 5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
// Increase speed over time
if (LK.ticks % 300 == 0) {
self.speedX += 1;
self.speedY += 1;
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Paddle class for player and AI
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = 200;
self.height = 20;
self.speed = 10;
self.update = function () {
// Paddle update logic
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize paddles and ball
var background = game.addChild(LK.getAsset('background', {}));
var playerPaddle = game.addChild(new Paddle());
var aiPaddle = game.addChild(new Paddle());
var ball = game.addChild(new Ball());
// Position paddles and ball
playerPaddle.x = 2048 / 2;
playerPaddle.y = 2732 - 50;
aiPaddle.x = 2048 / 2;
aiPaddle.y = 50;
ball.x = 2048 / 2;
ball.y = 2732 / 2;
// Game update logic
game.update = function () {
// Ball movement
ball.update();
// Ball collision with walls
if (ball.x <= 0 || ball.x >= 2048) {
ball.speedX *= -1;
}
if (ball.y <= 0) {
ball.speedY *= -1;
LK.setScore(LK.getScore() + 1); // Player gains a point when opponent misses ball
scoreTxt.setText(LK.getScore()); // Update score text
}
if (ball.y >= 2732) {
ball.speedY *= -1;
LK.setScore(LK.getScore() - 1); // Player loses a point when he misses the ball
scoreTxt.setText(LK.getScore()); // Update score text
}
// Ball collision with paddles
if (ball.intersects(playerPaddle) || ball.intersects(aiPaddle)) {
ball.speedY *= -1;
}
// AI paddle movement
if (ball.x < aiPaddle.x) {
aiPaddle.x -= aiPaddle.speed;
} else if (ball.x > aiPaddle.x) {
aiPaddle.x += aiPaddle.speed;
}
};
// Create score text
var scoreTxt = new Text2('0', {
size: 150,
fill: 0x000000,
fontWeight: 'bold'
});
scoreTxt.anchor.set(1, 0); // Sets anchor to the top right edge of the text.
LK.gui.topRight.addChild(scoreTxt);
// Player paddle control
game.move = function (x, y, obj) {
playerPaddle.x = x;
}; ===================================================================
--- original.js
+++ change.js
@@ -90,9 +90,10 @@
};
// Create score text
var scoreTxt = new Text2('0', {
size: 150,
- fill: 0x000000
+ fill: 0x000000,
+ fontWeight: 'bold'
});
scoreTxt.anchor.set(1, 0); // Sets anchor to the top right edge of the text.
LK.gui.topRight.addChild(scoreTxt);
// Player paddle control