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
self.speedX *= 1.01;
self.speedY *= 1.01;
};
});
//<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 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.y >= 2732) {
ball.speedY *= -1;
}
// 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;
}
};
// Player paddle control
game.move = function (x, y, obj) {
playerPaddle.x = x;
}; ===================================================================
--- original.js
+++ change.js
@@ -12,8 +12,11 @@
self.speedY = 5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
+ // Increase speed over time
+ self.speedX *= 1.01;
+ self.speedY *= 1.01;
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
@@ -65,10 +68,9 @@
ball.speedY *= -1;
}
// Ball collision with paddles
if (ball.intersects(playerPaddle) || ball.intersects(aiPaddle)) {
- ball.speedY *= -1.1; // Increase speed by 10% after each collision
- ball.speedX *= -1.1; // Increase speed by 10% after each collision
+ ball.speedY *= -1;
}
// AI paddle movement
if (ball.x < aiPaddle.x) {
aiPaddle.x -= aiPaddle.speed;