I’m working on a maze game and ran into a problem. I’m not sure how to make the circle, not through the walls. I know you can probably do it with Boolean but I’m not really familiar with that. Is there a different way such as detecting the color change?
//Varaibles for images
PImage frankenstein, ghost;
//Variables for walls
wall[] walls;
//circle variables
float x=180;
float y=60;
float start=30;
float stop=30;
//Sets the enviroment for the code
void setup() {
//background setup
size(1200, 790);
//calling images from the data file
frankenstein = loadImage("frankenstein.png");
ghost = loadImage("ghost.png");
//walls setup
walls=new wall[16];//creates an array(list) for the walls array starts at 0
walls[0]=new wall(150, 30, 10, 730);
walls[1]=new wall(200, 250, 750, 10);
walls[2]=new wall(250, 150, 10, 500);
walls[3]=new wall(200, 250, 10, 300);
walls[4]=new wall(150, 30, 850, 10);
walls[5]=new wall(150, 750, 860, 10);
walls[6]=new wall(300, 450, 10, 300);
walls[7]=new wall(200, 650, 80, 10);
walls[8]=new wall(300, 300, 80, 10);
walls[9]=new wall(370, 250, 10, 300);
walls[10]=new wall(400, 450, 10, 300);
walls[10]=new wall(370, 630, 300, 10);
walls[11]=new wall(370, 700, 300, 10);
walls[12]=new wall(370, 500, 300, 10);
walls[13]=new wall(400, 380, 10, 300);
walls[14]=new wall(1000, 30, 10, 720);
walls[15]=new wall(750, 100, 10, 500);
}
void draw() {
//for background
background (225, 225, 225);//refreshing the background
background(255, 165, 0);
image(frankenstein, 1050, 650, 150, 150);
image(ghost, 20, 20, 120, 120);
textSize(32);
fill(0);
text(millis()/1100, 1100, 30);//sets up a timer in millaseconds so divided by 1000 to get it in seconds
Circle();//cirlce function
//for walls
for (int i = 0; i < walls.length; i++) {
walls[i].draw();
}
}
//creats a class for the walls of the maze
class wall {
float x;
float y;
float w;
float h;
wall(float _x, float _y, float _w, float _h) {
x = _x;
y = _y;
w = _w;
h = _h;
}
//draws the walls
void draw() {
fill(0);
rect(x, y, w, h);
}
}
//user defined function for Circle
void Circle(){
fill(255);
ellipse(x, y, start, stop);
}
//if down,up,left,right keys are pressed circle will move 5 pixels
void keyPressed(){
if (keyCode==UP){
y=y-5;
}
if (keyCode==DOWN){
y=y+5;
}
if (keyCode==RIGHT){
x=x+5;
}
if (keyCode==LEFT){
x=x-5;
}
}