# Stopping the game when touching sides pong game

**URL:** https://discourse.processing.org/t/stopping-the-game-when-touching-sides-pong-game/21810
**Category:** Coding Questions
**Created:** [June 12, 2020, 4:31pm UTC](https://discourse.processing.org/t/stopping-the-game-when-touching-sides-pong-game/21810 "2020-06-12T16:31:27Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [June 12, 2020, 5:14pm UTC](https://discourse.processing.org/t/stopping-the-game-when-touching-sides-pong-game/21810/2 "2020-06-12T17:14:29Z")

</div>

Hi,

Can you please format your code by using the `</>` button in the message editor on the forum? (You can press `Ctrl+T` in the Processing IDE to auto format your code 🙂 )

Because for now it’s actually impossible to read or copy into Processing to test it. (I already told you this on [I need help to keep score](https://discourse.processing.org/t/i-need-help-to-keep-score/21724/3))

**And please do not post the same code on multiple threads, try to summarize your problem…**  
([Bouncing ball with paddle](https://discourse.processing.org/t/bouncing-ball-with-paddle/21798))  
([I need help to keep score](https://discourse.processing.org/t/i-need-help-to-keep-score/21724))  
([Creating menu for game and touching sides pong game](https://discourse.processing.org/t/creating-menu-for-game-and-touching-sides-pong-game/21821))

But testing if your ball touches left or right side is not complicated :

- The location of your ball is described by `x` and `y`
- It’s diameter is `w` and `h` (or just `w` because a ball is always circular in pong)
- The left side of the screen is at coordinates `[0, y]` (`y` can be whatever)
- The right side of the screen is at coordinates `[width, y]`

So in order to test if it touches the left wall, you test if the x coordinate of the ball is inferior (on the left side) to 0 (the left wall), you need to take into account the diameter of the ball (in fact it’s radius) :

```auto
boolean touchLeftWall(x, diameter){
  return (x - diameter / 2) <= 0;
}

```

This function returns a `boolean` (`true` or `false`) that tells if the ball hit the left wall. You can do the same for the right wall.

---

_[View the full topic](https://discourse.processing.org/t/stopping-the-game-when-touching-sides-pong-game/21810)._
