Hello all, I am trying to make a simple interactive game in Processing 3. I currently have a class set up to create bubbles on the screen starting at the bottom and slowly floating to the top. I also have the bubbles disappear upon being clicked by the mouse. I would like to create another class which tracks the amount of bubbles that have been clicked and displays that information on the screen. In addition, if possible, I would like to have the Processing window display “Game Over” if three or more bubbles reach the top of the screen without being clicked. Here is my code:
//Main code:
Bubble b1;
Bubble b2;
void setup() {
size(500, 500);
b1 = new Bubble(2, 64);
b2 = new Bubble(4, 32);
}
void draw() {
background(255);
b1.ascend();
b1.display();
b1.top();
b2.ascend();
b2.display();
b2.top();
}
void mousePressed() {
b1.clicked(mouseX, mouseY);
b2.clicked(mouseX, mouseY);
}
//Bubble class:
class Bubble {
float x;
float y;
float diameter;
boolean popped = false;
Bubble(float tempX, float tempD) {
x = width/tempX;
y = height;
diameter = tempD;
}
void clicked(float mx, float my) {
float d = dist(x, y, mx, my);
if (d < diameter/2) {
popped = true;
}
}
void ascend() {
y--;
x = x + random(-4, 4);
}
void display() {
if (!popped) {
stroke(0);
fill(125, 255, 255);
ellipse(x, y, diameter, diameter);
}
}
void top() {
if (y < diameter/2) {
y = diameter/2;
}
}
}
Any and all help is appreciated. Thanks in advance!