Wall Collisions
in
Programming Questions
•
4 months ago
Hello! I am making this project where it's a maze and I want it to be so that when your character (movements controlled by variables x, and y) sends you to a game over screen. Here's my code -
int x, y, radius, index;
//image array for characters and shtuff
PImage[] myImage = new PImage[7];
void setup(){
radius = 20;
background(0);
size(1200, 600);
index = 0;
myImage[0] = loadImage("ABD.png");
myImage[1] = loadImage("RDonaldS.png");
myImage[2] = loadImage("SS.png");
myImage[3] = loadImage("WIZ.png");
myImage[4] = loadImage("WIN.png");
myImage[5] = loadImage("WINNER.jpg");
myImage[6] = loadImage("GOVR.jpg");
}
void draw(){
background(0);
fill(255, 0, 0);
ellipse(620, 400, 90, 90);
image(myImage[4], 460, 310);
image(myImage[3], x, y);
fill(250, 255, 0);
//draws maze
rect(50, 0, 30, 200);
rect(50, 200, 200, 30);
rect(50, 300, 200, 30);
rect(50, 300, 30, 180);
rect(250, 300, 30, 210);
rect(50, 480, 200, 30);
rect(250, 0, 30, 50);
rect(250, 150, 30, 80);
rect(340, 200, 150, 30);
rect(280, 480, 100, 30);
rect(330, 300, 200, 30);
rect(350, 410, 30, 80);
rect(350, 380, 180, 30);
rect(500, 330, 30, 50);
rect(490, -1, 30, 231);
rect(520, 200, 200, 30);
rect(520, 300, 200, 30);
rect(50, 500, 30, 100);
rect(700, 300, 30, 200);
rect(530, 500, 200, 30);
rect(530, 460, 30, 40);
rect(700, 200, 100, 30);
rect(800, 130, 30, 100);
rect(630, 100, 200, 30);
rect(890, 200, 100, 30);
rect(990, -70, 30, 300);
noFill();
ellipse(400, 200, 300, 300);
// checks if the characters is inside a circle
boolean inside = inside();
if(inside == true){
image(myImage[0], 100, 0);
}
boolean inside1 = inside1();
ellipse(600, 300, 300, 300);
if(inside1 == true){
image(myImage[1], 100, 0);
}
ellipse(300, 500, 300, 300);
boolean inside2 = inside2();
if(inside2 == true){
image(myImage[2], 100, 0);
}
boolean win = win();
if(win == true){
image(myImage[5], 500, 300);
}
if(x ==
}
void keyPressed(){
// moves the character
if(key==CODED){
if(keyCode==UP){
index=0;
y-=10;
}
else if(keyCode==DOWN){
index=3;
y+=10;
}
else if(keyCode==LEFT){
index=1;
x-=10;
}
else if(keyCode==RIGHT){
index=2;
x+=10;
}
}
}
//checks if the character is inside a circle
boolean inside(){
return dist(x, y, 200, 50)<=100;
}
boolean inside1(){
return dist(x, y, 350, 100)<=100;
}
boolean inside2(){
return dist(x, y, 350, 300)<=100;
}
boolean win(){
return dist(x, y, 450, 300)<=50;
}
1