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 }; }); // 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) { LK.getSound('hit').play(); // Play sound when ball falls LK.showGameOver(); // Show game over when ball hits the southern part } if (fastBall.y >= 2732 && fastBall.lastY < 2732) { LK.getSound('falling').play(); // Play sound when fastBall falls fastBall.lastY = fastBall.y; } // Ball collision with paddles if (ball.intersects(playerPaddle) || ball.intersects(aiPaddle) || fastBall.intersects(playerPaddle) || fastBall.intersects(aiPaddle)) { ball.speedY *= -1; fastBall.speedY *= -1; LK.getSound('hit').play(); // Play sound when ball hits the paddle } // Make the fastBall go down every 50 seconds if (LK.ticks % 3000 == 0) { fastBall.y = 0; fastBall.x = Math.random() * 2048; fastBall.speedY = 20; } }; // Player paddle control game.move = function (x, y, obj) { playerPaddle.x = x; };
===================================================================
--- original.js
+++ change.js
@@ -23,9 +23,9 @@
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
- self.speedY = -20;
+ self.speedY = 20;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
};
@@ -97,8 +97,9 @@
LK.showGameOver(); // Show game over when ball hits the southern part
}
if (fastBall.y >= 2732 && fastBall.lastY < 2732) {
LK.getSound('falling').play(); // Play sound when fastBall falls
+ fastBall.lastY = fastBall.y;
}
// Ball collision with paddles
if (ball.intersects(playerPaddle) || ball.intersects(aiPaddle) || fastBall.intersects(playerPaddle) || fastBall.intersects(aiPaddle)) {
ball.speedY *= -1;