# Simple Pong-like Interactive

**URL:** https://discourse.processing.org/t/simple-pong-like-interactive/34615
**Category:** Beginners
**Created:** [January 13, 2022, 9:00pm UTC](https://discourse.processing.org/t/simple-pong-like-interactive/34615 "2022-01-13T21:00:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hullstar242](https://avatars.discourse-cdn.com/v4/letter/h/4da419/32.png) [@hullstar242](https://discourse.processing.org/u/hullstar242)
#### Post date: [January 13, 2022, 9:00pm UTC](https://discourse.processing.org/t/simple-pong-like-interactive/34615/1 "2022-01-13T21:00:49Z")

</div>

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;

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

```

---

<div class="post-metadata">

### Author: ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)
#### Post date: [May 24, 2022, 2:43am UTC](https://discourse.processing.org/t/simple-pong-like-interactive/34615/2 "2022-05-24T02:43:10Z")

</div>

@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
