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
@@ -45,8 +45,21 @@
self.y = 2732;
}
};
});
+var SmallBall = Container.expand(function () {
+ var self = Container.call(this);
+ var smallBallGraphics = self.attachAsset('smallBall', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = 0;
+ self.speedY = 0;
+ self._move_migrated = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ };
+});
/****
* Initialize Game
****/
@@ -116,19 +129,30 @@
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;
+ // Create 5 new balls
+ for (var i = 0; i < 5; i++) {
+ var newBall = new SmallBall();
+ newBall.x = ball.x;
+ newBall.y = ball.y;
+ var randomAngle = angle + (Math.random() - 0.5) * (Math.PI / 6); // Randomize angle slightly
+ var randomSpeed = 5 + Math.random() * 5; // Randomize speed
+ newBall.speedX = Math.cos(randomAngle) * randomSpeed;
+ newBall.speedY = Math.sin(randomAngle) * randomSpeed;
+ game.addChild(newBall);
+ // 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;
@@ -154,31 +178,8 @@
ball.speedY = Math.sin(angle) * 5 * 3;
}
// Check for scoring
if (ball.x <= 0) {
- // Add 5 new balls at the start of a point
- for (var i = 0; i < 5; i++) {
- var newBall = new Container();
- var ballGraphics = newBall.attachAsset('smallBall', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- 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
- newBall.update = function () {
- this.x += this.speedX;
- this.y += this.speedY;
- if (this.y <= 0 || this.y >= 2732) {
- this.speedY *= -1;
- }
- if (this.x <= 0 || this.x >= 2048) {
- this.speedX *= -1;
- }
- };
- game.addChild(newBall);
- }
// Reset ball position
ball.x = 1024;
ball.y = 1366;
ball.speedX *= -1;
@@ -187,27 +188,8 @@
// Add blood splatter effect
LK.effects.flashScreen(0xff0000, 100);
}
if (ball.x >= 2048) {
- // 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
- newBall.update = function () {
- this.x += this.speedX;
- this.y += this.speedY;
- if (this.y <= 0 || this.y >= 2732) {
- this.speedY *= -1;
- }
- if (this.x <= 0 || this.x >= 2048) {
- this.speedX *= -1;
- }
- };
- game.addChild(newBall);
- }
// Reset ball position
ball.x = 1024;
ball.y = 1366;
ball.speedX *= -1;
@@ -229,5 +211,11 @@
ball._move_migrated();
aiMove();
checkCollisions();
playerScoreTxt.setText(playerPaddle.score); // Update score display
+ // Move the new balls
+ game.children.forEach(function (child) {
+ if (child instanceof SmallBall) {
+ child._move_migrated();
+ }
+ });
});
\ No newline at end of file