Hi, I managed to make my player ( the car ) collide with the obstacles that are falling down. I tried to make a class so I would be able to make the position, speed, and size of each obstacle random. But it doesn’t work and I don’t see why.
here is my code for the collision:
if (dist(obstacleXPos, obstacleYPos, mouseX, y) < 60) {
background (0);
noLoop();
textSize(80);
fill(#3279D8);
text(“You lose!”, 180, height/2);
}
This is the class I made:
class ObstacleMovement {
int x;
int y;
int size;
int obstacleXPos;
int speed;
ObstacleMovement( int newX, int newY, int newSize, int newobstacleXPos, int newobstacleY, int newSpeed ) {
x = newX;
y = newY;
size = newSize;
obstacleXPos = newobstacleXPos;
speed = newSpeed;
}
void move() {
obstacleYPos = obstacleYPos + speed;
if (obstacleYPos > height) {
obstacleYPos = -20;
}
}
void display() {
fill (random(255), random(255), 255);
rect(obstacleXPos, obstacleYPos, 65, 80); // obstacle rectangle
//fill(255);
//ellipse(obstacleXPos+400, obstacleYPos, 72, 72); // Obstacle circle
}
void run() {
move();
display();
}
}
and this is how I create a new obstacle with the class:
ObstacleMovement obstacle1 = new ObstacleMovement(100, 200, 80, 100, 10, 3);
If someone knows how to help me I would be very grateful