User prompt
But when it reappears, it goes to a random direction
User prompt
Make the paddle longer
User prompt
more like 10 seconds
User prompt
Make the ball go faster every 20 seconds
User prompt
Also works when it doesn't hit the AI paddle
User prompt
Make the ball regenerate when it doesn't hit the paddle
User prompt
But add it down the pint scoreboard
User prompt
Add a number that increases every second (00:00)
User prompt
When someone's paddle's point increases, the ball is regenerated in the center
User prompt
I mean the scoreboard (0-0) when the AI paddle avoids the ball, the player paddle goes 1-0, but when the player paddle avoids the ball, the AI paddle goes 0-1
User prompt
Add scoreboard and remove the game over feature
User prompt
Make the ball fall every 50 seconds, not when the white ball goes up
User prompt
Still not playing
User prompt
Doesn't fall
User prompt
But still doesn't play
User prompt
Make a sound when fastBall falls
User prompt
Make a sound when fastBall falls
User prompt
Make a sound when the red ball falls
User prompt
But can it go down every 50 seconds
User prompt
But don't make it go down when the white ball goes down
/**** * 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; // Ball collision logic }; }); //<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 = 300; self.height = 40; 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 player and AI score variables var playerScore = 0; var aiScore = 0; // Initialize score text var scoreTxt = new Text2(playerScore + '-' + aiScore, { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); // Sets anchor to the center of the top edge of the text. LK.gui.top.addChild(scoreTxt); // Add the score text to the GUI overlay at the top-center of the screen. // 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 () { // Update paddles and ball playerPaddle.update(); aiPaddle.update(); ball.update(); // Improved AI for moving the AI paddle if (ball.x < aiPaddle.x - aiPaddle.width / 2) { aiPaddle.x -= aiPaddle.speed; } else if (ball.x > aiPaddle.x + aiPaddle.width / 2) { aiPaddle.x += aiPaddle.speed; } // Ball collision with walls if (ball.x <= 0 || ball.x >= 2048) { ball.speedX *= -1; LK.getSound('hit').play(); // Play sound when ball hits the wall } if (ball.y <= 0) { ball.speedY *= -1; LK.getSound('hit').play(); // Play sound when ball hits the wall } // Removed game over feature // Ball collision with paddles if (ball.intersects(playerPaddle)) { ball.speedY *= -1; LK.getSound('hit').play(); // Play sound when ball hits the paddle playerScore += 1; // Increase player score by 1 scoreTxt.setText(playerScore + '-' + aiScore); // Update score text } else if (ball.intersects(aiPaddle)) { ball.speedY *= -1; LK.getSound('hit').play(); // Play sound when ball hits the paddle aiScore += 1; // Increase AI score by 1 scoreTxt.setText(playerScore + '-' + aiScore); // Update score text } // Increase difficulty every 20 seconds if (LK.ticks % 1200 == 0) { // 50% chance to increase speed if (Math.random() < 0.5) { ball.speedX *= 1.1; ball.speedY *= 1.1; } } }; // Player paddle control game.move = function (x, y, obj) { playerPaddle.x = x; };
===================================================================
--- original.js
+++ change.js
@@ -42,10 +42,13 @@
/****
* Game Code
****/
+// Initialize player and AI score variables
+var playerScore = 0;
+var aiScore = 0;
// Initialize score text
-var scoreTxt = new Text2('0', {
+var scoreTxt = new Text2(playerScore + '-' + aiScore, {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0); // Sets anchor to the center of the top edge of the text.
@@ -83,13 +86,18 @@
LK.getSound('hit').play(); // Play sound when ball hits the wall
}
// Removed game over feature
// Ball collision with paddles
- if (ball.intersects(playerPaddle) || ball.intersects(aiPaddle)) {
+ if (ball.intersects(playerPaddle)) {
ball.speedY *= -1;
LK.getSound('hit').play(); // Play sound when ball hits the paddle
- LK.setScore(LK.getScore() + 1); // Increase score by 1
- scoreTxt.setText(LK.getScore()); // Update score text
+ playerScore += 1; // Increase player score by 1
+ scoreTxt.setText(playerScore + '-' + aiScore); // Update score text
+ } else if (ball.intersects(aiPaddle)) {
+ ball.speedY *= -1;
+ LK.getSound('hit').play(); // Play sound when ball hits the paddle
+ aiScore += 1; // Increase AI score by 1
+ scoreTxt.setText(playerScore + '-' + aiScore); // Update score text
}
// Increase difficulty every 20 seconds
if (LK.ticks % 1200 == 0) {
// 50% chance to increase speed