# Processing collision rect and circle (PacMan)

**URL:** <https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021>\
**Category:** Coding Questions\
**Created:** [February 23, 2021, 12:52pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021 "2021-02-23T12:52:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.processing.org/u/dimitris)\
**Post date:** [February 23, 2021, 12:52pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/1 "2021-02-23T12:52:11Z")

</div>

So this is my code\<3 So my question is how can the main character not be able to go through the “obstacles” as you want to call them. Yes, that, I need collision or something I​ do not know:( thanks a lot\<3

```auto
Face f1;
Enemy e1,e2,e3,e4;
Message m1, m2, m3, m4;
int currentTime;

void setup()
{
  size (600,600);
  f1=new Face(50,200,300,0,255,0); 
  e1 = new Enemy(200,300,30,-5,255,0,0);
  e2=new Enemy(400,200,40,-8,255,0,0);
  e3=new Enemy(100,500,50,-7,255,0,0);
  e4=new Enemy(550,400,30,-6,255,0,0);
  m1 = new Message(width/2, height/2, 1000,4000, "wear a mask");
  m2 = new Message(width/2, height/2, 5000,9000, "avoid contacts");
  m3 = new Message(width/2, height/2, 10000,14000, "wash your hands");
  m4 = new Message(width/2, height/2, 15000,19000, "stay safe");
 
  
}
 

void draw()
{
  background (0);
  currentTime = millis();
  f1.display();
  e1.move();
  e1.display();
  e2.display();
  e2.move();
  e3.display();
  e3.move();
  e4.display();
  e4.move();
  m1.setTime(currentTime);
  m2.setTime(currentTime);
  m3.setTime(currentTime);
  m4.setTime(currentTime);
  m1.display();
  m2.display();
  m3.display();
  m4.display();
  
fill(35, 20, 219);
  rect(200, 240, 180, 30); 
  rect(0, 0, 600, 10); 
  rect(0, 0, 10, 600); 
  rect(0, 590, 600, 10);
  rect(590, 0, 10, 600);
  rect(40, 50, 50, 20);
  rect(140, 50, 50, 20);
  rect(0, 220, 40, 140);
  rect(0, 400, 40, 20);
  rect(80, 580, 200, 20);
  rect(340, 580, 200, 20);
  rect(240, 500, 150, 20);
  rect(300, 500, 20, 50);
  rect(240, 380, 150, 20);
  rect(300, 380, 20, 70);
  rect(390, 450, 60, 15);
  rect(500, 450, 90, 15);
  rect(500, 480, 20, 50);
  rect(120, 420, 20, 80);
  rect(90, 500, 90, 20);
  rect(280, 0, 20, 60);
  rect(380, 50, 40, 20);
  rect(480, 50, 40, 20);
  rect(480, 280, 20, 100);
  rect(450, 260, 80, 20);
  rect(150, 120, 300, 20);
  rect(275, 140, 25, 40);
  rect(100, 270, 20, 100);fill(35, 20, 219);
  rect(200, 240, 180, 30); 
  rect(0, 0, 600, 10); 
  rect(0, 0, 10, 600); 
  rect(0, 590, 600, 10);
  rect(590, 0, 10, 600);
  rect(40, 50, 50, 20);
  rect(140, 50, 50, 20);
  rect(0, 220, 40, 140);
  rect(0, 400, 40, 20);
  rect(80, 580, 200, 20);
  rect(340, 580, 200, 20);
  rect(240, 500, 150, 20);
  rect(300, 500, 20, 50);
  rect(240, 380, 150, 20);
  rect(300, 380, 20, 70);
  rect(390, 450, 60, 15);
  rect(500, 450, 90, 15);
  rect(500, 480, 20, 50);
  rect(120, 420, 20, 80);
  rect(90, 500, 90, 20);
  rect(280, 0, 20, 60);
  rect(380, 50, 40, 20);
  rect(480, 50, 40, 20);
  rect(480, 280, 20, 100);
  rect(450, 260, 80, 20);
  rect(150, 120, 300, 20);
  rect(275, 140, 25, 40);
  rect(100, 270, 20, 100);
  

  
  
 
  
  if(dist(f1.x, f1.y, e1.x, e1.y) < ( (f1.diameter + e1.diameter) / 2) ){
  noLoop();
  }
  if(dist(f1.x, f1.y, e2.x, e2.y) < ( (f1.diameter + e2.diameter) / 2) ){
  noLoop();
  }
  if(dist(f1.x, f1.y, e3.x, e3.y) < ( (f1.diameter + e3.diameter) / 2) ){
  noLoop();
  }
  if(dist(f1.x, f1.y, e4.x, e4.y) < ( (f1.diameter + e4.diameter) / 2) ){
  noLoop();
  }
  if(dist(f1.x, f1.y, e4.x, e4.y) < ( (f1.diameter + e4.diameter) / 2) ){
  noLoop();
  }
  }
   }
   void keyPressed()
{
  if(key==CODED)
  {
    if(keyCode==LEFT)
    {
     f1.moveLeft();
    }
    if(keyCode==RIGHT)
    {
      f1.moveRight();
    }
    if(keyCode==UP)
    {
     f1.moveUp();
    }
    if(keyCode==DOWN)
    {
     f1.moveDown();
    }
  }
  
 
   }
  ----------------------------------------------------------------------------------------
class Eye
{
  int diameter;
  int x;
  int y;
  int grey;
  
  Eye(int d, int xcor, int ycor, int g)
  {
    grey=g;
    diameter=d;
    x=xcor;
    y=ycor;
  }
  void display()
  {
    fill(grey);
    ellipse(x,y,diameter,diameter);
  }
  int getX()
  {
    return x;
  }
  void setX(int xx)
  {
    x=xx;
 }
   int getY()
  {
    return y;
  }
  void setY(int yy)
  {
    y=yy;
 }
 
 
 
 
}
-------------------------------------------------------------------------------------------
class Enemy
{
  int x;
  int y;
  int diameter;
  int step;
  int r;
  int g;
  int b;
  
  
  Enemy(int a,int b,int c,int d,int rc,int gc,int bc)
  {
    x=a;
    y=a;
    diameter=c;
    step=d;
    r=rc;
    g=gc;
    b=bc;
}
void display()
{ 
  fill(r, g, b);
  stroke(0,0,255);
  ellipse(x,y,diameter,diameter);
  
}

void move()
{
  y=y+step;
  if(y<diameter)
  step=-step;
  if(y>600)
  step=-step;
}
void moveUp()
{ 
  if(y>=5+diameter/2)
  {
    y=y-5;
  }
}
void moveDown()
{
  if(y<=height-5-diameter/2)
  {
    y=y+5;
  }
}
void changeColor()
{
  g=(g+20)%255;
}
}
------------------------------------------------------------

class Face
{
  int diameter;
  int x;
  int y;
  int r;
  int g;
  int b;
  Eye leftEye;
  Eye rightEye;
  
  Face(int d, int xcor, int ycor,int rc,int gc,int bc)
  {
    diameter=d;
    y=ycor;
    x=xcor;
    r=rc;
    g=gc;
    b=bc;
    leftEye=new Eye(10,x-10,y-10,255);
    rightEye=new Eye(10,x+10,y-10,250);
    
    
  }
  
 
  void display()
  {
    fill(255, g, b);
    stroke(255,0,0);
    ellipse(x,y,diameter,diameter);
    leftEye.display();
    rightEye.display();
    
  }
  void moveLeft()
  {
    if(x>diameter/2)
    {
      x=x-10;
      leftEye.setX(leftEye.getX()-10);
      rightEye.setX(rightEye.getX()-10);
   }
  }
  void moveRight()
  {
    if(x<width-diameter/2)
    {
    x=x+10;
      leftEye.setX(leftEye.getX()+10);
      rightEye.setX(rightEye.getX()+10);
    }
  }
  void moveUp()
{ 
  if(y>=5+diameter/2)
  {
    y=y-10;
    leftEye.setY(leftEye.getY()-10);
    rightEye.setY(rightEye.getY()-10);
  }
}
 
    void moveDown()
{
  if(y<=height-5-diameter/2)
  {
    y=y+10;
    leftEye.setY(leftEye.getY()+10);
    rightEye.setY(rightEye.getY()+10);
    
  }
}

  }
  -----------------------------------------------------------------------------
class Message
{
int startTime;
int stopTime;
String str;
int x;
int y;
boolean visible;

Message(int xcor, int ycor, int t1,int t2, String s)
{
  x = xcor;
  y = ycor;
  startTime = t1;
  stopTime = t2;
  str = s;
  visible = false;
}

void display()
{
  textSize(24);
  if(visible == true)
   {
     text(str, x, y);
   }
}
  
void setTime(int time)
{
    if(time>=startTime && time<= stopTime)
    {
      visible = true;   
    }
    else
    {
      visible = false;   
    }
}

}
-------------------------------------------------------------------

```

---

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.processing.org/u/dimitris)\
**Post date:** [February 23, 2021, 12:57pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/3 "2021-02-23T12:57:15Z")

</div>

Sorry, I do not know why a part of my code is bold:( \<3

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [February 23, 2021, 1:05pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/4 "2021-02-23T13:05:11Z")

</div>

Welcome. Please format your code using the \</\> button in the textbox.

you can press the pen button to edit your posts.

---

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.processing.org/u/dimitris)\
**Post date:** [February 23, 2021, 1:35pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/5 "2021-02-23T13:35:27Z")

</div>

Great, thanks a lot\<3:)

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [February 23, 2021, 1:54pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/6 "2021-02-23T13:54:34Z")

</div>

YW. Collisions are kinda straight forward, however I’ll point you to this site as it will explain it better than I could. Hope you are comfortable with some math.  
this site has everything you could require for collisions.

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

also here is an example to show how it works, I’ll leave it to you to adapt it to your purposes.

```auto

float radius = 50;
void setup(){
  size(400,400);
};

void draw(){
  
  background(0);
  fill(255);
  rectMode(CENTER);
  rect(width/2,height/2,200,200);
  fill(255,0,0);
  if((mouseX-radius/2<width/2+100
     &&mouseY+radius/2>height/2-100
     &&mouseY-radius/2<height/2+100
     &&mouseX+radius/2>width/2-100))
  fill(0,0,255);
  ellipse(mouseX,mouseY,radius,radius);
};

```

---

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.processing.org/u/dimitris)\
**Post date:** [February 23, 2021, 2:24pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/7 "2021-02-23T14:24:06Z")

</div>

Wow thanks with the advice, although I understand it, I can not understand how this collision is related to mine. It is a circle/rect collision but I do not want the circle to just go through the rectangle. Appreciate it\<3

---

<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:** [February 23, 2021, 2:30pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/8 "2021-02-23T14:30:03Z")

</div>

This means the circle hit the rect.

So prior to moving the circle make this test. When it gives you true, **do not move** the circle.

```auto
boolean collide() {
    if((playerX-radius/2<width/2+100
         &&playerX+radius/2>height/2-100
         &&PlayerY-radius/2<height/2+100
         &&PlayerX+radius/2>width/2-100))
      return true;
      else return false; 
}

```

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [February 23, 2021, 2:30pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/9 "2021-02-23T14:30:46Z")

</div>

the if statement provides the condition you are looking for, I have simply added logic to change the color when this condition is true. If you want more functionality you will have to think outside the box.

```auto

float radius = 50;
void setup(){
  size(400,400);
};

void draw(){
  
  background(0);
  fill(255);
  rectMode(CENTER);
  rect(width/2,height/2,200,200);
  fill(255,0,0);
  if(!(mouseX-radius/2<width/2+100
     &&mouseY+radius/2>height/2-100
     &&mouseY-radius/2<height/2+100
     &&mouseX+radius/2>width/2-100))
  //fill(0,0,255);
  ellipse(mouseX,mouseY,radius,radius);
};

```

---

<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:** [February 23, 2021, 2:41pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/10 "2021-02-23T14:41:00Z")

</div>

Ah, because the walls are blue:

you can also check the color in the target direction of your movement.

When it’s blue, **do not move**

(You need to take the wall color exactly)

Here is your new moveUp() :

(remove ` else println("No");` when you clean up your code later)

```auto
  void moveUp()
  { 

    if (y>=5+diameter/2 && 
      get(x, y-10-diameter/2) != color(35, 20, 219) )
    {
      y=y-10;
      leftEye.setY(leftEye.getY()-10);
      rightEye.setY(rightEye.getY()-10);
    } else println("No");
  }

```

---

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.processing.org/u/dimitris)\
**Post date:** [February 23, 2021, 3:51pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/11 "2021-02-23T15:51:15Z")

</div>

Guys, I really appreciate the help!! Everything turned out beautifully, and thanks for creating a mindset to me. Many many thanks!!! You guys are awesome, I am really proud of you( idk thats wrong with me:) Yes, basically many thanks to both of you!\<3

---

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.processing.org/u/dimitris)\
**Post date:** [February 23, 2021, 5:47pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/12 "2021-02-23T17:47:42Z")

</div>

hi, my FINAL question ever and I will never bother you again about this code. So I’ve putted the moveup addition and I have also putted the movedown addition. Now I have been trying to make the left and right correct code and it doesn’t go, you know, through it. Sorry\<3

---

<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:** [February 23, 2021, 6:06pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/13 "2021-02-23T18:06:49Z")

</div>

can you post your entire code please

---

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.processing.org/u/dimitris)\
**Post date:** [February 23, 2021, 6:11pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/14 "2021-02-23T18:11:27Z")

</div>

```auto

```

```auto

```

Face f1;  
Enemy e1,e2,e3,e4;  
Message m1, m2, m3, m4;  
int currentTime;

void setup()  
{  
size (600,600);  
f1=new Face(50,200,300,0,255,0);  
e1 = new Enemy(200,300,30,-5,255,0,0);  
e2=new Enemy(400,200,40,-8,255,0,0);  
e3=new Enemy(100,500,50,-7,255,0,0);  
e4=new Enemy(550,400,30,-6,255,0,0);  
m1 = new Message(width/2, height/2, 1000,4000, “wear a mask”);  
m2 = new Message(width/2, height/2, 5000,9000, “avoid contacts”);  
m3 = new Message(width/2, height/2, 10000,14000, “wash your hands”);  
m4 = new Message(width/2, height/2, 15000,19000, “stay safe”);

}

void draw()  
{  
background (0);  
currentTime = millis();

f1.display();  
e1.move();  
e1.display();  
e2.display();  
e2.move();  
e3.display();  
e3.move();  
e4.display();  
e4.move();  
m1.setTime(currentTime);  
m2.setTime(currentTime);  
m3.setTime(currentTime);  
m4.setTime(currentTime);  
m1.display();  
m2.display();  
m3.display();  
m4.display();

fill(35, 20, 219);  
rect(200, 240, 180, 30);  
rect(0, 0, 600, 10);  
rect(0, 0, 10, 600);  
rect(0, 590, 600, 10);  
rect(590, 0, 10, 600);  
rect(40, 50, 50, 20);  
rect(140, 50, 50, 20);  
rect(0, 220, 40, 140);  
rect(0, 400, 40, 20);  
rect(80, 580, 200, 20);  
rect(340, 580, 200, 20);  
rect(240, 500, 150, 20);  
rect(300, 500, 20, 50);  
rect(240, 380, 150, 20);  
rect(300, 380, 20, 70);  
rect(390, 450, 60, 15);  
rect(500, 450, 90, 15);  
rect(500, 480, 20, 50);  
rect(120, 420, 20, 80);  
rect(90, 500, 90, 20);  
rect(280, 0, 20, 60);  
rect(380, 50, 40, 20);  
rect(480, 50, 40, 20);  
rect(480, 280, 20, 100);  
rect(450, 260, 80, 20);  
rect(150, 120, 300, 20);  
rect(275, 140, 25, 40);  
rect(100, 270, 20, 100);fill(35, 20, 219);  
rect(200, 240, 180, 30);  
rect(0, 0, 600, 10);  
rect(0, 0, 10, 600);  
rect(0, 590, 600, 10);  
rect(590, 0, 10, 600);  
rect(40, 50, 50, 20);  
rect(140, 50, 50, 20);  
rect(0, 220, 40, 140);  
rect(0, 400, 40, 20);  
rect(80, 580, 200, 20);  
rect(340, 580, 200, 20);  
rect(240, 500, 150, 20);  
rect(300, 500, 20, 50);  
rect(240, 380, 150, 20);  
rect(300, 380, 20, 70);  
rect(390, 450, 60, 15);  
rect(500, 450, 90, 15);  
rect(500, 480, 20, 50);  
rect(120, 420, 20, 80);  
rect(90, 500, 90, 20);  
rect(280, 0, 20, 60);  
rect(380, 50, 40, 20);  
rect(480, 50, 40, 20);  
rect(480, 280, 20, 100);  
rect(450, 260, 80, 20);  
rect(150, 120, 300, 20);  
rect(275, 140, 25, 40);  
rect(100, 270, 20, 100);

if(dist(f1.x, f1.y, e1.x, e1.y) \< ( (f1.diameter + e1.diameter) / 2) ){  
noLoop();  
}  
if(dist(f1.x, f1.y, e2.x, e2.y) \< ( (f1.diameter + e2.diameter) / 2) ){  
noLoop();  
}  
if(dist(f1.x, f1.y, e3.x, e3.y) \< ( (f1.diameter + e3.diameter) / 2) ){  
noLoop();  
}  
if(dist(f1.x, f1.y, e4.x, e4.y) \< ( (f1.diameter + e4.diameter) / 2) ){  
noLoop();  
}  
if(dist(f1.x, f1.y, e4.x, e4.y) \< ( (f1.diameter + e4.diameter) / 2) ){  
noLoop();  
}

}

void keyPressed()  
{  
if(key==CODED)  
{  
if(keyCode==LEFT)  
{  
f1.moveLeft();  
}  
if(keyCode==RIGHT)  
{  
f1.moveRight();  
}  
if(keyCode==UP)  
{  
f1.moveUp();  
}  
if(keyCode==DOWN)  
{  
f1.moveDown();  
}  
}

}

```auto
----------------------------------------------------------
class Eye
{
  int diameter;
  int x;
  int y;
  int grey;
  
  Eye(int d, int xcor, int ycor, int g)
  {
    grey=g;
    diameter=d;
    x=xcor;
    y=ycor;
  }
  void display()
  {
    fill(grey);
    ellipse(x,y,diameter,diameter);
  }
  int getX()
  {
    return x;
  }
  void setX(int xx)
  {
    x=xx;
 }
   int getY()
  {
    return y;
  }
  void setY(int yy)
  {
    y=yy;
 }
 
 
 
 
}
-----------------------------------------------------------
class Enemy
{
  int x;
  int y;
  int diameter;
  int step;
  int r;
  int g;
  int b;
  
  
  Enemy(int a,int b,int c,int d,int rc,int gc,int bc)
  {
    x=a;
    y=a;
    diameter=c;
    step=d;
    r=rc;
    g=gc;
    b=bc;
}
void display()
{ 
  fill(r, g, b);
  stroke(0,0,255);
  ellipse(x,y,diameter,diameter);
  
}

void move()
{
  y=y+step;
  if(y<diameter)
  step=-step;
  if(y>600)
  step=-step;
}
void moveUp()
{ 
  if(y>=5+diameter/2)
  {
    y=y-5;
  }
}
void moveDown()
{
  if(y<=height-5-diameter/2)
  {
    y=y+5;
  }
}
void changeColor()
{
  g=(g+20)%255;
}
}
--------------------------------------
class Face
{
  int diameter;
  int x;
  int y;
  int r;
  int g;
  int b;
  Eye leftEye;
  Eye rightEye;
  boolean collide;
  
  Face(int d, int xcor, int ycor,int rc,int gc,int bc)
  {
    diameter=d;
    y=ycor;
    x=xcor;
    r=rc;
    g=gc;
    b=bc;
    leftEye=new Eye(10,x-10,y-10,255);
    rightEye=new Eye(10,x+10,y-10,250);
    
    
  }
  
 
  void display()
  {
    fill(255, g, b);
    stroke(255,0,0);
    ellipse(x,y,diameter,diameter);
    leftEye.display();
    rightEye.display();
    
  }
  void moveLeft()
  {
    if(x>diameter/2)
       
    {
      x=x-10;
      leftEye.setX(leftEye.getX()-10);
      rightEye.setX(rightEye.getX()-10);
      
      
      }
      
   }
  
  void moveRight()
  {
    if(x<width-diameter/2)
    {
    x=x+10;
      leftEye.setX(leftEye.getX()+10);
      rightEye.setX(rightEye.getX()+10);
    }
  }
   void moveUp()
  { 

    if (y>=5+diameter/2 && 
      get(x, y-10-diameter/2) != color(35, 20, 219) )
    {
      y=y-10;
      leftEye.setY(leftEye.getY()-10);
      rightEye.setY(rightEye.getY()-10);
    }
    
  }
  
 
    void moveDown()
{
  if(y<=height-5-diameter/2 &&
   get(x, y+10+diameter/2) != color(35, 20, 219) )
  {
    y=y+10;
    leftEye.setY(leftEye.getY()+10);
    rightEye.setY(rightEye.getY()+10);
    
  }
  
}

  
  

  
  

}

--------------------------------------
class Message
{
int startTime;
int stopTime;
String str;
int x;
int y;
boolean visible;

Message(int xcor, int ycor, int t1,int t2, String s)
{
  x = xcor;
  y = ycor;
  startTime = t1;
  stopTime = t2;
  str = s;
  visible = false;
}

void display()
{
  textSize(24);
  if(visible == true)
   {
     text(str, x, y);
   }
}
  
void setTime(int time)
{
    if(time>=startTime && time<= stopTime)
    {
      visible = true;   
    }
    else
    {
      visible = false;   
    }
}

}
-------------------------------

```

```auto

```

---

<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:** [February 23, 2021, 6:12pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/15 "2021-02-23T18:12:37Z")

</div>

err…

you need the color check in moveLeft and moveRight?

---

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.processing.org/u/dimitris)\
**Post date:** [February 23, 2021, 6:12pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/16 "2021-02-23T18:12:51Z")

</div>

Of course and thanks for not being sarcastic and serious!\<3

---

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.processing.org/u/dimitris)\
**Post date:** [February 23, 2021, 6:15pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/17 "2021-02-23T18:15:41Z")

</div>

I tried putting again like the moveUp get and the color but nothing

---

<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:** [February 23, 2021, 6:22pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/18 "2021-02-23T18:22:48Z")

</div>

okay,

this

```auto
 get(x, y-10-diameter/2) != color(35, 20, 219)

```

means if the new position (x,y-10) is not blue, then you are allowed to move. The expression color(35, 20, 219) must be the exact wall color.

The new position you test (x,y-10) must match with the new position you are attempting to move to!

it’s hard to tell without seeing your code

---

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.processing.org/u/dimitris)\
**Post date:** [February 23, 2021, 6:27pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/19 "2021-02-23T18:27:37Z")

</div>

I have putted this code to my moveup and then I have changed it like this:

```auto
void moveDown()
{
  if(y<=height-5-diameter/2 &&
   get(x, y+10+diameter/2) != color(35, 20, 219) )
  {
    y=y+10;
    leftEye.setY(leftEye.getY()+10);
    rightEye.setY(rightEye.getY()+10);
    
  }

```

for my movedown. Now I have a problem with the left and right. Would you like for me to sent again the code?\<3

---

<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:** [February 23, 2021, 6:35pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/20 "2021-02-23T18:35:50Z")

</div>

You need to test into the direction you want to move

So when it’s x=x+10 you want to check where **the new position** would be:

```auto
  if( ..... &&
   get(x+10+diameter/2 , y) != color(35, 20, 219) )
  {
  

```

in this case, x changes, y does not

**Next case**

x=x-10

gives you:

```auto
  if( .... &&
   get(x-10-diameter/2, y) != color(35, 20, 219) )
  {
  

```

[EDITED: the `y<=height-5-diameter/2` was wrong. Please use them like they were in your code]

Warm regards,

Chrisir

😉

---

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.processing.org/u/dimitris)\
**Post date:** [February 24, 2021, 5:01pm UTC](https://discourse.processing.org/t/processing-collision-rect-and-circle-pacman/28021/21 "2021-02-24T17:01:52Z")

</div>

I am so sorry about yesterday, but apparently, I have a limited number of comments that I can do and I had reached it. Everything turned out perfect, yes you are correct! I feel privileged to have met you, many thanks\<3
