I’m guessing you’re in the same class as the person who posted this. I’d suggest mostly the same code for you. You just may need to account for where you are drawing the ellipse.
maze1.loadPixels();
boolean isValidLocation(x, y) { // custom function that takes in an x and y and returns true or false
x += 249; //accounts for where you are drawing the ellipse
y += 187;
if (maze1.pixels[x + y * width] == color(255)) {
return true;
}
return false;
}
// then change your all your keyPressed if statements to something like this
if (keyCode == DOWN && isValidLocation(x, y - 8)) { // won't move if ellipse would hit a wall
// all the same code
}