Simple Pong-like Interactive

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;
   } 
 
 
}

@hullstar242 A while ago but its an easy fix mate, replace the 3 || (OR) in the if statement with && (and)
If you think about why it was going crazy left and right, its because you were asking if any of them states are true, if any one was true it would flip speed, you only want it to flip the speed if all of the states are true at the same time hence the &&

Hope that helps explain it