Hello, I am new to processing and I have to work on a school project. For my project, I need objects that are falling down to collide with my own moving character. I have been searching quite a bit but I can’t find how to work with collisions on moving objects. If someone knows how I can end my game if my obstacles and character touch each other that would be very helpful.
(This is my code so far)
float stripeYPos;
float b;
float obstacleYPos;
int x = 0;
int y = 450;
void setup() {
size (720, 600);
stripeYPos = -40;
obstacleYPos = -80;
b = -70;
//fill (#626161);
//rect (0, 0, 240, 600); // links weg
//fill (#F7F7F7);
//rect (240, 0, 240, 600); // midden weg
//fill (#626161);
//rect (480, 0, 240, 600); // rechts weg
}
void keyPressed() {
if ( key == ‘d’ ) {
x = x + 50;
}
if ( key == ‘a’)
x = x - 50;
}
void draw () {
background (#484646);
smooth();
strokeWeight(2);
line(240, 0, 240, 600);
line(480, 0, 480, 600);
obstacleYPos = obstacleYPos + 8;
if (obstacleYPos > height) {
obstacleYPos = -20;
}
stripeYPos = stripeYPos + 5;
if (stripeYPos > height + 70) {
stripeYPos = -20;
}
fill (#F7F7F7);
rect(100, stripeYPos, 40, 70); // all the moving stripes
rect(340, stripeYPos, 40, 70);
rect(580, stripeYPos, 40, 70);
fill(255);
ellipse(400, obstacleYPos, 72, 72); // Obstacle circle
fill (#F20F0F);
rect(100, obstacleYPos, 80, 80); // obstacle rectangle
fill (#F00F0F);
rect(mouseX+5, y-12, 50, 20); //x,y,w,h body
fill (#F00F0F);
rect(mouseX+5, y+60, 50, 20); //x,y,w,h body
fill (#F00F0F);
rect(mouseX, y-5, 60, 80); //x,y,w,h car
fill (#050505);
rect(mouseX-15, y+2, 15, 25); // top left tire
fill (#050505);
rect(mouseX-15, y+40, 15, 25); // bottom left tire
fill (#050505);
rect(mouseX+60, y+2, 15, 25); // top right tire
fill (#050505);
rect(mouseX+60, y+40, 15, 25); // bottom right tire
}