Composite shape collision detection

I really need some help, I’m trying to make a composite shape of 2 ellipses, shaped like a snow man’s body with no arms, move (using arrows) towards 3 randomly positioned small circles that were created with an array, upon collision with any one of those 3 circles, the circle that is touched, would disappear, the rest would not, only when touched. Thing is, only the composite snow man’s “head” can remove the circle, I’m not sure how to separate the variables between the composite shape’s 2 objects so that only the object on top clears the small circle away, while the bottom circle (belly of the snow man), doesn’t affect it.
Any advice at all would be insanely stress relieving.
So far all I have is the snow man and the small circles, I’m assuming you have to use dist() for the collision detection but I’m lost on the variables needed to connect 1 piece of a composite shape and a small circle that’s in an array

Mines[] mines = new Mines [3];
int count =1;
float x = 45;
float y = 120;
float xSpeed = 0;
float ySpeed = 0;
boolean blinkM = true;
int diameter= 30;
boolean begin = false;
boolean keyUp, keyDown, keyLeft, keyRight;
void setup() {
  size(1200, 600);
  for (int i = 0; i < mines.length; i++) {
    mines[i] = new Mines ();
  }
}


void draw() {
  background(255);
  twoCircles(x,y,90);
     directionalSpeed();  
    position(); 
    xSpeed *= 0.9;
    ySpeed *= 0.9;
  for (int i = 0; i < mines.length; i++) {
    mines[i].display();
  }

  count();
}

void directionalSpeed() {
  if (keyLeft) xSpeed-= 0.5;
  if (keyRight) xSpeed+= 0.5;
  if (keyUp) ySpeed-= 0.5;
  if (keyDown) ySpeed+= 0.5;
}

void position() {
  x+=xSpeed;
  y+=ySpeed;
}


void keyPressed() {
  if (key == 's') {
    begin = true;
  }
  if (keyCode == UP) {
    keyUp = true;
  }
  if (keyCode == DOWN) {
    keyDown = true;
  }
  if (keyCode == LEFT) {
    keyLeft = true;
  }
  if (keyCode == RIGHT) {
    keyRight = true;
  }
}
void keyReleased() {
  //  if (key == CODED) {
  if (keyCode == UP) {
    keyUp = false;
  }
  if (keyCode == DOWN) {
    keyDown = false;
  }
  if (keyCode == LEFT) {
    keyLeft = false;
  }
  if (keyCode == RIGHT) {
    keyRight = false;
  }
  //  }
}

class Mines {
  float x;
  float y;


  Mines() {
    x = random(15, width - diameter);
    y = random(15, height - diameter);
    diameter = 30;
  }

  void display() {
    if (count % 60 < 30) {
      blinkM = true;
    } else {
      blinkM = false;
    }

    if (blinkM == true) {
      diameter = 30;
    } else {
      diameter = 0;
    }
    noStroke();
    fill(0);
    ellipse(x, y, diameter, diameter);
  }
}

void count() {
  count++;
}



void twoCircles(float xB, float yB, int dia){
  fill(240,0,0);
  ellipse(xB,yB,dia,dia);
  ellipse(xB, yB-60, 50, 50);
}

I need to keep the circles blinking/flashing as part of the homework, you can ignore that, thanks

1 Like