User prompt
Make it fall when the white ball doesn't fall
User prompt
Make it very fast and hittable
User prompt
Each 50 seconds, a fast red ball falls from up, and you have to hit it or you lose
User prompt
Remove the ball number increase when each 20 seconds
User prompt
But the balls that get spawned randomly as of the difficulty increase do the same as the original ball (same speed and same features)
User prompt
Lose when the ball hits the southern part
User prompt
Each 20 seconds, the difficulty increases and some things happen randomly Ball number increase (50%) Speed increase (50%)
User prompt
Make a sound when the ball hits something
User prompt
More like, increase the weight and decrease the height
User prompt
More longer
User prompt
Make the paddles a little bit longer
User prompt
But can you make the other paddle get controlled by AI
Initial prompt
Ping-Pong Deluxe
/**** * 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 }; }); // FastBall class var FastBall = Container.expand(function () { var self = Container.call(this); var fastBallGraphics = self.attachAsset('fastBall', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = 0; self.speedY = 20; self.update = function () { 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 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 paddles and ball var playerPaddle = game.addChild(new Paddle()); var aiPaddle = game.addChild(new Paddle()); var ball = game.addChild(new Ball()); var fastBall = game.addChild(new FastBall()); fastBall.x = 2048 / 2; fastBall.y = 0; // 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 } if (ball.y >= 2732 || fastBall.y >= 2732) { LK.showGameOver(); // Show game over when ball hits the southern part } // Ball collision with paddles if (ball.intersects(playerPaddle) || ball.intersects(aiPaddle)) { ball.speedY *= -1; LK.getSound('hit').play(); // Play sound when ball hits the paddle } if (fastBall.intersects(playerPaddle) || fastBall.intersects(aiPaddle)) { if (ball.speedY > 0) { fastBall.speedY *= -1; } LK.getSound('hit').play(); // Play sound when ball hits the paddle } // Increase difficulty every 50 seconds if (LK.ticks % 3000 == 0) { fastBall.y = 0; fastBall.x = Math.random() * 2048; } }; // Player paddle control game.move = function (x, y, obj) { playerPaddle.x = x; };
===================================================================
--- original.js
+++ change.js
@@ -95,13 +95,18 @@
if (ball.y >= 2732 || fastBall.y >= 2732) {
LK.showGameOver(); // Show game over when ball hits the southern part
}
// Ball collision with paddles
- if (ball.intersects(playerPaddle) || ball.intersects(aiPaddle) || fastBall.intersects(playerPaddle) || fastBall.intersects(aiPaddle)) {
+ if (ball.intersects(playerPaddle) || ball.intersects(aiPaddle)) {
ball.speedY *= -1;
- fastBall.speedY *= -1;
LK.getSound('hit').play(); // Play sound when ball hits the paddle
}
+ if (fastBall.intersects(playerPaddle) || fastBall.intersects(aiPaddle)) {
+ if (ball.speedY > 0) {
+ fastBall.speedY *= -1;
+ }
+ LK.getSound('hit').play(); // Play sound when ball hits the paddle
+ }
// Increase difficulty every 50 seconds
if (LK.ticks % 3000 == 0) {
fastBall.y = 0;
fastBall.x = Math.random() * 2048;