I want to make it so when the ball hits the white finish box it says you win and restarts the code.
//Varaibles for images
PImage frankenstein,ghost;
PImage startscreen;
//variables for start screen
int screensizex,screensizey,stage;
//Variables for walls
wall[]walls;
//circle variables
int x=180;
int y=60;
float start=30;
float stop=30;
//wall color
color colorOfWall = color(255);
color c;
//rectangle stopping point variables
int xr=275,yr=50,wr=90,hr=40;
//Sets the enviroment for the code
void setup() {
//background setup
size(1200, 790);
startscreen=loadImage("maze.jpg");
image (startscreen,0,0,1200,790);
//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, 84, 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() {
if(stage==1);{
textAlign(CENTER);
textSize(60);
fill(0);
text("Haunted Maze",550,150);
textSize(18);
fill(255,255,255);
text("Press any key to start game",550,175);
text("Instructions:",1000,30);
textSize(15);
text("Reach the end of the Maze by using ",1000,60);
text("arrow keys or W,A,S,D to move the ball",1000,75);
if (keyPressed==true){
stage=2;
}
}
if (stage==2){
//for background
background (225, 225, 225);//refreshing the background
background(255,116,0);
//image(frankenstein, 1050, 650, 150, 150);
//image(ghost, 20, 20, 120, 120);
textSize(32);
fill(0);
text(millis()/1000, 1100, 30);//sets up a timer in millaseconds so divided by 1000 to get it in seconds
for (int i = 0; i < walls.length; i++) {
walls[i].draw();
}
Circle();//cirlce function
stoprect();
}
}
//creats a class for the walls of the maze
class wall {
float x;
float y;
float w;
float h;
wall(float x1, float y1, float w1, float h1) {
x = x1;
y = y1;
w = w1;
h = h1;
}
//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(keyPressed==true) {
if((keyCode == LEFT || key == 'a')&&get(x-16,y)!=color(0,0,0)) {
x += -2;
}
else if (c==colorOfWall){
x+=0;
}
if ((keyCode == RIGHT || key == 'd')&&get(x+16,y)!=color(0,0,0)) {
x += 2;
}
if ((keyCode == UP || key == 'w')&&get(x,y-16)!=color(0,0,0)) {
y += -2;
}
if ((keyCode == DOWN || key == 's')&&get(x,y+16)!=color(0,0,0)) {
y += 2;
}}}
void stoprect(){
fill(255);
rect(xr,yr,wr,hr);
fill(0);
textSize(18);
text("FINISH",317,70);
}