Help with collision in my basic game

Hello, for school I need to have collision in my game. I was messing around with dist but could not get it to work. What I want is to let the player collide with the eggs falling down. And on collision the eggs need to disappear. I don’t know how to do it.


int index = 0;
Player player1 = new Player();
Grass grass = new Grass();

Good_egg goodegg1;

Good_egg[] eggs = new Good_egg[40]; //makes the array.


void setup() { 
  size (1200, 800); 

  for (int i=0; i < eggs.length; i++) {
    eggs[i] = new Good_egg(i * 30, random(-500, 0)); //fills the array with as much eggs as indicated above and gives it the x and y values.
  }
} 

float haasX = 300; 
float haasY = 700;
float eggRadius = 20;
float rabbitRadius = 30;

void draw () {  
  background (#7185FF);
  smooth();
  strokeWeight(2); 

  for (int i=0; i < eggs.length; i++) {
    eggs[i].moveDown();
    eggs[i].display(); //activates the functions for the eggs in the array
    if (eggs[i].eggY > height) { //checks if the eggs fall out of the screen to place them at the top again.
      eggs[i].eggY = 0;
    }
  }

  pushMatrix();
  translate(100, haasY);
  grass.display();
  popMatrix();

  pushMatrix();
  translate(mouseX + haasX, 700);
  player1.display();
  popMatrix();

  if (keyPressed) {
    if (key == 'd' || key == 'D') {
      haasX += 7;
    }
  }

  if (keyPressed) {
    if (key == 'a' || key == 'A') {
      haasX -= 7;
    }
  }
}


class Good_egg {
  float eggX;
  float eggY;
  float eggWidth;
  float eggHeight;
  color eggColor;

  Good_egg(float eggX, float eggY) {
    this.eggX = eggX;
    this.eggY = eggY;
    this.eggWidth = eggRadius*2;
    this.eggHeight = eggRadius*2;
    this.eggColor = color(random(255), random(255), random(255)); //gives the egg it's values.
  }


  void display() {
    fill (eggColor);
    ellipse(eggX, eggY, eggWidth, eggHeight);  //egg, x y,w, h
  }

  void moveDown() {
    this.eggY += 5;
  }
}

Hello and welcome to the processing community!

Great to have you here with us!

Similar to

if (eggs[i].eggY

You can try:

float myDist = dist(eggs[i].eggX, eggs[i].eggY, player.x,player.y); 

if(myDist < 40) {
  eggs[i].eggY=-13; 
  score++; 
}