Collision between moving objects

Hey i’m using PImage to make my game and i’m trying to record a collision between my caterpillar and the birds to reset the score back to 0 if it happens.
I know how to record collision with basic shapes such as rect but do i need to create a new variable for my each of my classes to check the positions?

The caterpillar is moved by mouseX and Y and the birds are an array that each move on a random y value and with this code `void move() {

x= x + xspeed * direcction;
if (x>1280) { 
  direcction=-1;
} else if (x<0) {
  direcction=1;
}`
1 Like

The only variables you need to check collision are positional variables such as X and Y and dimensions. Since your using PImage, you can get the exact dimensions pretty easily

float playerWidth = image.width;
float playerHeight = image.height;

Also if you’re stuck on collision detection, I’d bookmark this link

1 Like