Я не могу сделать лабиринт так как мой персонаж проходит через стены в программе processing

В от код в котором смайлик это игрок а призрак стена как сделать чтобы смайл не проходил через призрака

PImage smile_img; 
PImage ghost_img; 
int ghost_x= 250, ghost_y=250;
int hx; int hy; int speed;
boolean[] pressed_keys={false,false,false,false};

boolean collide2objects(int x1, int x2, int y1, int y2, int w1, int  w2, int h1, int h2){
   if(x1+w1<x2){return false;}
   if(x2+w2<x1){return false;}
   if(y1+h1<y2){return false;}
   if(y2+h2<y1){return false;}
   return true;
}

void setup(){
  size (500,500,P2D);
  smile_img=loadImage("smile.png");
  imageMode(CENTER);
  hx = 300;
  hy = 150;
  speed = 5;
  
  ghost_img=loadImage("ghost.png");
  imageMode(CENTER);
 
}

void draw(){
   background(255, 250, 205);
   image(ghost_img,ghost_x,ghost_y);
   
   pushMatrix();
   translate(hx,hy);
   image(smile_img,0,0);
   popMatrix();
   
   if (collide2objects(hx,hy,smile_img.width, smile_img.height,ghost_img.width, ghost_img.height,ghost_x, ghost_y)){
       
   }
   
   
   if(pressed_keys[0]) { hy=hy-speed;}
   if(pressed_keys[1]) { hy=hy+speed;}
   if(pressed_keys[2]) { hx=hx-speed;}
   if(pressed_keys[3]) { hx=hx+speed;}//ghost
   
   if (hx<0) {hx=0;}
   if (hx>500){hx=500;}
   if (hy<0) {hy=0;}
   if (hy>500){hy=500;}
   
   fill(178, 34, 34);
   textSize(20);
   text("X = "+hx,10,20);
   text("Y = "+hy,10,40);
   
    
   
}

void keyPressed(){
  print(key);
  if(key=='w'){
    pressed_keys[0]=true;
  }
  if(key=='s'){
    pressed_keys[1]=true;
  }
  if(key=='a'){
    pressed_keys[2]=true;
  }
  if(key=='d'){
    pressed_keys[3]=true;
  }
}

void keyReleased(){
  print(key);
  if(key=='w'){
    pressed_keys[0]=false;
  }
  if(key=='s'){
    pressed_keys[1]=false;
  }
  if(key=='a'){
    pressed_keys[2]=false;
  }
  if(key=='d'){
    pressed_keys[3]=false;
  }
}

вот картинка смайла вот картинка призрака


Ответы (0 шт):