# Making a labyrinth

**URL:** <https://discourse.processing.org/t/making-a-labyrinth/6869>\
**Category:** Coding Questions\
**Created:** [December 24, 2018, 7:42am UTC](https://discourse.processing.org/t/making-a-labyrinth/6869 "2018-12-24T07:42:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 24, 2018, 12:28pm UTC](https://discourse.processing.org/t/making-a-labyrinth/6869/2 "2018-12-24T12:28:55Z")

</div>

there is some ?rules? about the naming of variables,  
and you just hit it!  
better:

```auto
class Balle {....

Balle b1;

```

if you want go with the color check ( instead object collision )  
need the color check inside your class ( instead the window size limit check)  
and should do just before you walk.

- 
  - there was a small mistake, you can not use width and height in the variable declaration / prior to setup size()  
so b1 position was wrong.

for example:

```auto
Balle b1;
color labcol = color(200, 0, 0);

void setup() {
  size(600, 600);
  b1 = new Balle(width /2, height /2, 10);
  background(255);
}

void draw() { 
  background(255);
  draw_lab();
  b1.render();
}

class Balle {
  boolean goUP, goDOWN, goLEFT, goRIGHT; 
  int x, y, r;
  Balle(int x_, int y_, int r_) {
    x = x_;
    y = y_;
    r = r_;
  }
  void render() {
    if ((keyPressed == true) && (key == CODED)) {
      color_check();
      if (keyCode == UP && goUP ) y--;
      if (keyCode == DOWN && goDOWN ) y++;
      if (keyCode == LEFT && goLEFT ) x--;
      if (keyCode == RIGHT && goRIGHT ) x++;
    }
    fill(200, 200, 0);
    stroke(0, 0, 200);
    strokeWeight(1);
    ellipse(x, y, r, r);
  }
  void color_check() {
    goUP=goDOWN=goLEFT=goRIGHT=true;
    if ( labcol == get(x, y-r/2 -1) ) goUP = false;
    if ( labcol == get(x, y+r/2 +1) ) goDOWN = false;
    if ( labcol == get(x-r/2 -1, y) ) goLEFT = false;
    if ( labcol == get(x+r/2 +1, y) ) goRIGHT = false;
  }
}

void draw_lab() {
  stroke(labcol);
  strokeWeight(20);
  noFill();
  rect( 20, 20, width-40, height-40);
  //... MORE 
}

```

---

_[View the full topic](https://discourse.processing.org/t/making-a-labyrinth/6869)._
