# Help on line detection

**URL:** <https://discourse.processing.org/t/help-on-line-detection/8373>\
**Category:** Coding Questions\
**Created:** [February 13, 2019, 7:37pm UTC](https://discourse.processing.org/t/help-on-line-detection/8373 "2019-02-13T19:37:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter1](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@peter1](https://discourse.processing.org/u/peter1)\
**Post date:** [February 13, 2019, 7:37pm UTC](https://discourse.processing.org/t/help-on-line-detection/8373/1 "2019-02-13T19:37:16Z")

</div>

Im working on a maze game, and cant find out how to detect if the ball hits the walls/lines!

```auto
int x;
int y;
int s;

void setup(){
  size(500,500);
  background(0);
  noStroke();
  x = 20;
  y = 20;
  s = 10;
  fill(0,0,255);
  ellipse(x,y,s,s);  
  
}

void draw(){ 
  background(0); 
  ellipse(x,y,s,s);
  println(mouseX+" "+mouseY);
  fill(255);
  line(0,45,348,45);
  
  stroke(100);
  line(410,46,410,249);
  stroke(100);
  line(348,45,351,249);
  line(288,45,288,357);
  line(410,297,410,500);
  line(288,358,349,357);
  line(349,357,351,298);
  line(410,412,289,412);
  line(231,412,231,500);
  line(289,456,357,456);
  line(473,0,473,500);
  line(231,357,65,357);
  line(473,497,410,497);
  line(231,300,231,108);
}
void keyPressed(){
  if (key == 'w' || key == 'W') {
    y = y - 5;     
  }
  if (key == 's' || key == 'S') {
    y = y + 5; 
  }
  if (key == 'a' || key == 'A') {
    x = x - 5; 
  }
  if (key == 'd' || key == 'D') {
    x = x + 5; 
  }
  x = constrain(x,0,height);
  y = constrain(y,0,height);
  //https://forum.processing.org/two/discussion/1028/maze
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [February 19, 2019, 6:28pm UTC](https://discourse.processing.org/t/help-on-line-detection/8373/2 "2019-02-19T18:28:04Z")

</div>

There are a _lot_ of bouncing ball tutorials for Processing – see for example the examples section. Start with the simplest example first:

- [Bounce / Examples / Processing.org](https://processing.org/examples/bounce.html)
- [Bouncing Ball with Vectors / Examples / Processing.org](https://processing.org/examples/bouncingball.html)
- [Bouncy Bubbles / Examples / Processing.org](https://processing.org/examples/bouncybubbles.html)

In general, the principle to detect if the ball hits the walls is circle-line collision detection, covered with a working example in this guide:

> **[Collision Detection](http://www.jeffreythompson.org/collision-detection/line-circle.php)**
>
> An online book about collision detection using Processing.

You may also be interested in one of several video tutorials on the bouncing ball problem:

[![](https://img.youtube.com/vi/YIKRXl3wH8Y/hqdefault.jpg "5.5: The Bouncing Ball - Processing Tutorial") ](https://www.youtube.com/watch?v=YIKRXl3wH8Y)

[![](https://img.youtube.com/vi/U5cOB3KgFWQ/maxresdefault.jpg "Learn Processing - Ep 03 - Bouncing Ball") ](https://www.youtube.com/watch?v=U5cOB3KgFWQ)
