I literally started with processing on Monday and decided to try and make a simple animation where the ball is bouncing back and forth, the Y of the ball not changing just the X and have the ball change direction when it hits the paddle which is controlled with the mouse but is locked on the X axis.
What I wrote was an epic failure and the conditions I wrote for whatever reason are always true which is making the ball go crazy from left to right.
Please I know I will learn something from this failure but right now I’m completely stumped.
here’s my code
float ballX, ballY, Xspeed, paddleX, thickness, tallness;
void setup() {
fullScreen(1);
pixelDensity(2);
ballX = width/2;
ballY = height/2;
Xspeed = 10;
paddleX = 0.1*width;
thickness = 25;
tallness = 200;
}
void draw () {
background(50);
fill(255);
noStroke();
ellipse(ballX, ballY, 25, 25);
ballX = ballX + Xspeed;
if (ballX > width || ballX < 0) {
Xspeed = Xspeed * -1;
}
rectMode(CENTER);
rect(paddleX, mouseY, thickness, tallness);
if(ballX >= paddleX - (thickness * 1/2) || ballX <= paddleX + (thickness * 1/2) || ballY >= mouseY - (tallness * 1/2) || ballY <= mouseY + (tallness * 1/2)){
Xspeed = Xspeed * -1;
}
}