How can i make walls that are solid

I am new to processing
I am making a maze where you have to press the mouse to see it and i dnt know how to make walls that have collision is there anyone that can help

float x = 5; 
float y = 55;
PImage img;

void setup() {
  size(600, 597);
  
  img = loadImage( "Maze.jpg" );
  }



void draw() {
  background(0);
  fill(255);
  rect(x, y, 10, 10);
  fill(0);
   rect(0,0,600,47);
   rect(0,75,138,27);
   rect(0,75,27,597);
   rect(0,580,600,27);
   rect(560,74,600,597);
   rect(505,75,600,30);
  }



void keyPressed(){
  if (key == CODED) {
    if (keyCode == UP) {
      y = y - 5;
    }
    if (keyCode == DOWN) {
      y = y + 5;
    }
    if (keyCode == LEFT) {
      x = x - 5;
    }
    if (keyCode == RIGHT) {
      x = x + 5;
    }
   
    
  }
 if (key == 'r')
 {
   x = 5;
   y = 55;
 }
}
void mousePressed(){
 image(img,0,0);
     fill(57,56,56);
}
1 Like

I think instead of hard coding the rectangles, it’s better:

See the labyrinth as a grid

See tutorials, two dimensional arrays.

Store for each cell in the grid/labyrinth if it’s way or wall.

To check for a collision, check whether the cell in front of you (or in front of the direction you move to) is way or wall.

I know it’s not too easy

3 Likes

Do you have any links to other projects that would help me with doing this.

Chris meant this tutorial: https://processing.org/tutorials/2darray/

You’ll probably find more topics on this forum if you look for terms such as ‘collision’.

1 Like