# How can I implement objects with colliders?

**URL:** <https://discourse.processing.org/t/how-can-i-implement-objects-with-colliders/9033>\
**Category:** Coding Questions\
**Created:** [March 6, 2019, 7:19pm UTC](https://discourse.processing.org/t/how-can-i-implement-objects-with-colliders/9033 "2019-03-06T19:19:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mone](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@mone](https://discourse.processing.org/u/mone)\
**Post date:** [March 6, 2019, 7:19pm UTC](https://discourse.processing.org/t/how-can-i-implement-objects-with-colliders/9033/1 "2019-03-06T19:19:15Z")

</div>

I have to do a program where the player moves an object with the keyboard and there are obstacles that collide with the player. I have the movement part and it works really well but I really dont know how to print objects with hitbox that interact with the player.

There is the movement code, its really simple but works.

```auto
float x = 100; 
float y = 100; 

float xSpeed = 0;
float ySpeed = 0;

boolean keyLeft, keyRight, keyUp, keyDown;

void setup() {
  size(1500, 1000);
}

void draw() {
  background(255);
  

 ellipse(x, y, 50, 50);
  fill(255,0,100);
  
  
  pSpeed();   
  changePos(); 
  
  xSpeed *= 0.9; 
  ySpeed *= 0.9;
  
}
void pSpeed(){
  if(keyLeft) xSpeed-= 0.5;
  if(keyRight) xSpeed+= 0.5;
  if(keyUp) ySpeed-= 0.5;
  if(keyDown) ySpeed+= 0.5;
}

void changePos(){
  x+=xSpeed;
  y+=ySpeed;
}

void keyPressed() {
// if (key == CODED) {
    if (keyCode == UP) {
      keyUp = true;
    }
    if (keyCode == DOWN) {
      keyDown = true;
    }
    if (keyCode == LEFT) {
      keyLeft = true;
    }
    if (keyCode == RIGHT) {
      keyRight = true;
    }
  }

void keyReleased() {
{
    if (keyCode == UP) {
      keyUp = false;
    }
    if (keyCode == DOWN) {
      keyDown = false;
    }
    if (keyCode == LEFT) {
      keyLeft = false;
    }
    if (keyCode == RIGHT) {
      keyRight = false;
    }
  }
}

```

---

<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:** [March 6, 2019, 7:32pm UTC](https://discourse.processing.org/t/how-can-i-implement-objects-with-colliders/9033/2 "2019-03-06T19:32:23Z")

</div>

I have edited your post and formatted the code with the \</\> button – please do this in the future.

For overviews of collision detection in Processing, see:

> **[Processing Collision Detection](https://happycoding.io/tutorials/processing/collision-detection)**
>
> Learn how to trigger an action when objects overlap in Processing!

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