# How can I implement objects with colliders?

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.

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

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: