Help with my homework!

I have to create a game where “balloons” float up the screen and when you click them they disappear. I’m having trouble making them disappear on mouse press and don’t know how to do this. Keep it simple please!

Balloon[] b = new Balloon[100];

void setup(){
  size(600,600);
  for(int i=0;i<b.length;i++){
    b[i]=new Balloon(random(width),random(600,1500),random(15,40));
  }
}

void draw(){
  background(#0981AF);
  for(int i=0;i<b.length;i++){
    b[i].drawBalloon();
    b[i].moveBalloon();
    b[i].wrapBalloon();
  }
}

class Balloon{
  float bX;
  float bY;
  float bD;
  float bS=random(0.5,2);
  
  Balloon(float tempX,float tempY,float tempD){
    bX=tempX;
    bY=tempY;
    bD=tempD;
  }
  void drawBalloon(){
    ellipse(bX,bY,bD,bD);
  }
  void moveBalloon(){
    bY=bY-bS;
    bX=bX+random(-1,1);
  }
  void wrapBalloon(){
    if(bY<-20){
      bY=900;
    }
  }
}

pls format your code / by edit above post and use

</> code formatter

to paste your code.


yes, nice balloon code,
is that the version they give you to add the mouseclick into?

-a- first need to detect
mouse over balloon
best is the distance between mouse pointer and balloon center
https://processing.org/reference/dist_.html
could just change the stroke color for indication

-b- on click delete balloon?

2 Likes