User prompt
Randomise intital speed and direction of ball
User prompt
smallballs should bounce off the edge of the screen
User prompt
generate 20 smallball when enemy hits the ball
User prompt
add 5 new balls each time the player hits the ball, they should move towards the other player in an arc at random speeds
User prompt
new balls should be 80% of the size of ball
User prompt
new balls are still static, they should move in random directions
User prompt
the new balls are static, plox fix xxx
User prompt
add 5 new balls at the start of a point, make them fire at random dierections and speeds
User prompt
Delete extra balls added at end of round
User prompt
There is a bug, only one ball should be able to score one point per round
User prompt
Also create 5 balls every time a player contacts the real ball, they should shoot in a 25 degree arc towards the other player
User prompt
No, create 5 new balls at tthe start of ever point
User prompt
Now there is only one ball, or they might all be moving the same path, please change that
User prompt
Only one ball is move, but I'd liek all of them to move
User prompt
Repair change set 13
User prompt
create 5 balls at start of game
User prompt
clone ball 5 times
User prompt
create increasing numbers of balls on every round
User prompt
upon loss, double the number of balls
User prompt
make the rendered blood stay on screen
User prompt
add blood splatter special effects
User prompt
Migrate to the latest version of LK
Remix started
Copy Wall Bounce
===================================================================
--- original.js
+++ change.js
@@ -56,19 +56,12 @@
/****
* Game Code
****/
-// Initialize balls and paddles
-var balls = [];
-for (var i = 0; i < 5; i++) {
- var ball = game.addChild(new Ball());
- ball.x = 1024; // Center horizontally
- ball.y = 1366; // Center vertically
- // Assign random speeds and directions
- ball.speedX = (Math.random() < 0.5 ? -1 : 1) * (10 + Math.random() * 10);
- ball.speedY = (Math.random() < 0.5 ? -1 : 1) * (10 + Math.random() * 10);
- balls.push(ball);
-}
+// Initialize ball and paddles
+var ball = game.addChild(new Ball());
+ball.x = 1024; // Center horizontally
+ball.y = 1366; // Center vertically
var playerPaddle = game.addChild(new Paddle());
playerPaddle.x = 100; // Position player paddle on the left
var aiPaddle = game.addChild(new Paddle());
aiPaddle.x = 1948; // Position AI paddle on the right
@@ -123,8 +116,19 @@
angle = Math.max(angle, Math.PI / 6);
// Set the new speeds based on the angle and increase it by 3 times
ball.speedX = Math.cos(angle) * 5 * 3;
ball.speedY = Math.sin(angle) * 5 * 3;
+ // Calculate the difference between the center of the ball and the center of the paddle
+ var diffY = ball.y - playerPaddle.y;
+ // Normalize the difference to get a value between -1 and 1
+ var normalizedDiffY = diffY / (playerPaddle.height / 2);
+ // Multiply the normalized difference by the maximum angle of deflection (in radians)
+ var angle = normalizedDiffY * (5 * Math.PI / 12);
+ // Ensure the angle is at least 30 degrees
+ angle = Math.max(angle, Math.PI / 6);
+ // Set the new speeds based on the angle and increase it by 3 times
+ ball.speedX = Math.cos(angle) * 5 * 3;
+ ball.speedY = Math.sin(angle) * 5 * 3;
}
if (ball.intersects(aiPaddle)) {
// Calculate the difference between the center of the ball and the center of the paddle
var diffY = ball.y - aiPaddle.y;
@@ -136,27 +140,54 @@
angle = Math.max(angle, Math.PI / 6);
// Set the new speeds based on the angle and increase it by 3 times
ball.speedX = -Math.cos(angle) * 5 * 3;
ball.speedY = Math.sin(angle) * 5 * 3;
+ // Calculate the difference between the center of the ball and the center of the paddle
+ var diffY = ball.y - aiPaddle.y;
+ // Normalize the difference to get a value between -1 and 1
+ var normalizedDiffY = diffY / (aiPaddle.height / 2);
+ // Multiply the normalized difference by the maximum angle of deflection (in radians)
+ var angle = normalizedDiffY * (5 * Math.PI / 12);
+ // Ensure the angle is at least 30 degrees
+ angle = Math.max(angle, Math.PI / 6);
+ // Set the new speeds based on the angle and increase it by 3 times
+ ball.speedX = -Math.cos(angle) * 5 * 3;
+ ball.speedY = Math.sin(angle) * 5 * 3;
}
// Check for scoring
if (ball.x <= 0) {
- // Remove all existing balls
- balls.forEach(function (ball) {
- ball.destroy();
- });
- balls = [];
+ // Add 5 new balls at the start of a point
+ for (var i = 0; i < 5; i++) {
+ var newBall = new Ball();
+ newBall.x = 1024; // Center horizontally
+ newBall.y = 1366; // Center vertically
+ newBall.speedX = (Math.random() * 10 - 5) * 3; // Random speedX between -15 and 15
+ newBall.speedY = (Math.random() * 10 - 5) * 3; // Random speedY between -15 and 15
+ game.addChild(newBall);
+ }
+ // Reset ball position
+ ball.x = 1024;
+ ball.y = 1366;
+ ball.speedX *= -1;
aiPaddle.score++; // Increase AI's score
aiScoreTxt.setText(aiPaddle.score); // Update AI's score display
// Add blood splatter effect
LK.effects.flashScreen(0xff0000, 100);
}
if (ball.x >= 2048) {
- // Remove all existing balls
- balls.forEach(function (ball) {
- ball.destroy();
- });
- balls = [];
+ // Add 5 new balls at the start of a point
+ for (var i = 0; i < 5; i++) {
+ var newBall = new Ball();
+ newBall.x = 1024; // Center horizontally
+ newBall.y = 1366; // Center vertically
+ newBall.speedX = (Math.random() * 10 - 5) * 3; // Random speedX between -15 and 15
+ newBall.speedY = (Math.random() * 10 - 5) * 3; // Random speedY between -15 and 15
+ game.addChild(newBall);
+ }
+ // Reset ball position
+ ball.x = 1024;
+ ball.y = 1366;
+ ball.speedX *= -1;
playerPaddle.score++; // Increase player's score
playerScoreTxt.setText(playerPaddle.score); // Update player's score display
// Add blood splatter effect
LK.effects.flashScreen(0xff0000, 100);
@@ -170,11 +201,9 @@
}
}
// Game tick
LK.on('tick', function () {
- balls.forEach(function (ball) {
- ball._move_migrated();
- });
+ ball._move_migrated();
aiMove();
checkCollisions();
playerScoreTxt.setText(playerPaddle.score); // Update score display
});
\ No newline at end of file