# Wall isn't working

**URL:** <https://discourse.processing.org/t/wall-isnt-working/21399>\
**Category:** Coding Questions\
**Created:** [May 29, 2020, 11:12am UTC](https://discourse.processing.org/t/wall-isnt-working/21399 "2020-05-29T11:12:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![till](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@till](https://discourse.processing.org/u/till)\
**Post date:** [May 29, 2020, 11:12am UTC](https://discourse.processing.org/t/wall-isnt-working/21399/1 "2020-05-29T11:12:22Z")

</div>

```auto
float spieler_x;
float spieler_y;
float ball_x;
float ball_y;
float ball_speed_x;
float ball_speed_y;
int runde;

void setup(){
    
  spieler_x = 20;
  spieler_y = 20;
  
  // **Ball starting position**
  ball_x = 500;
  ball_y = 350;
  ball_speed_x = -4;
  ball_speed_y = 0;
  
  size(1000, 780);
    
  rectMode(CENTER);
}

void draw(){
  
  background(0);
  
  rect(spieler_x, spieler_y, 25, 160);
  rect(ball_x, ball_y, 10, 10); 
    
  if(spieler_y < 720) {
    if(keyCode == DOWN) {
      spieler_y = spieler_y + 5; } }
  
   
  if(keyCode == UP){
    if(spieler_y > 80) {
      spieler_y = spieler_y - 5; } } 
   
  ball_x = ball_x + ball_speed_x;
  ball_y = ball_y + ball_speed_y;
   
  // **When the ball hits the platform**
  
  if(ball_x < 40) {
    if(ball_y < (spieler_y + 80) && ball_y > (spieler_y -80)) {
      ball_speed_x = (-ball_speed_x) + 1;
      ball_speed_y = ball_speed_y - (spieler_y - ball_y) * 0.05;
  } else {
     ball_x = 500;
     ball_y = 350;
     ball_speed_x = -4;
     ball_speed_y = 0;
     runde = 0;
 
     // **These should be the walls**
 
     if(ball_y > 760 || ball_y < 20) { 
       ball_speed_y = -ball_speed_y;
     }
     if(ball_x > 980) {
       ball_speed_x *= -ball_speed_x;
     }
   }
 } 
 text("runde: " + runde, 1300, 20); }

```

So i am trying to make a pong game and this is the code. The the thing is that the walls on the outside aren’t working and i don’t know why.  
thx

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 29, 2020, 12:50pm UTC](https://discourse.processing.org/t/wall-isnt-working/21399/2 "2020-05-29T12:50:14Z")

</div>

> [@till](#):
>
> ball\_speed\_y = -ball\_speed\_y;

this looks ok

> [@till](#):
>
> ball\_speed\_x \*= -ball\_speed\_x;

this looks wrong.

Can you spot the error?

(Additionally in the 2nd if-clause `ball_x < 20` is missing)

---

<div class="post-metadata">

**Author:** ![till](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@till](https://discourse.processing.org/u/till)\
**Post date:** [May 29, 2020, 3:25pm UTC](https://discourse.processing.org/t/wall-isnt-working/21399/3 "2020-05-29T15:25:47Z")

</div>

if(ball\_y \> 760 || ball\_y \< 20) {  
ball\_speed\_y = -ball\_speed\_y;  
}  
if(ball\_x \> 980) {  
ball\_speed\_x = -ball\_speed\_x;  
}

it looks like this now and still isn’t working. And you said the Y-axis is right but this doesn’t work either.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 29, 2020, 3:39pm UTC](https://discourse.processing.org/t/wall-isnt-working/21399/4 "2020-05-29T15:39:07Z")

</div>

yeah, these lines are ok now

but please check where the if-clauses are closed } in your code…

```auto
  if (ball_x < 40) {
    if (ball_y < (spieler_y + 80) && ball_y > (spieler_y -80)) {

```

Is that correct?

Wo befinden sich die schließenden Klammern } für beide ifs?

Chrisir

---

<div class="post-metadata">

**Author:** ![till](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@till](https://discourse.processing.org/u/till)\
**Post date:** [May 29, 2020, 4:25pm UTC](https://discourse.processing.org/t/wall-isnt-working/21399/5 "2020-05-29T16:25:23Z")

</div>

Ah yes the brackets were the Problem thx 🙂
