package com.paulinemenage.bumple.game;

import com.paulinemenage.bumple.physics.Circle;
import com.paulinemenage.bumple.physics.Point;
import processing.core.PApplet;

public class BubbleGenerator {

    private class Bubble {

        public Circle circle;
        public float vy;

        public Bubble(Point center, float radius, float vy) {
            circle = new Circle(center, radius);
            this.vy = vy;
        }

    }

    private static final int STOCK = 15;

    private int numberOfBubbles = STOCK;
    private Bubble[] bubbles = new Bubble[STOCK];

    public BubbleGenerator() {
        for (int i = 0; i < STOCK; i++)
            bubbles[i] = new Bubble(new Point((float) Math.random() * 2, 3.1f), (float) Math.random() * .2f, (float) Math.random());
    }

    public void draw(Bumple bumple, PApplet pApplet) {
        pApplet.fill(176,224,230);
        pApplet.stroke(255, 255, 255);
        for (Bubble bubble : bubbles)
            pApplet.ellipse(
                    bumple.metersToPixels(bubble.circle.center.x),
                    bumple.metersToPixels(bubble.circle.center.y),
                    bumple.metersToPixels(bubble.circle.radius),
                    bumple.metersToPixels(bubble.circle.radius)
            );
    }

    public void update(float delta) {
        for (Bubble bubble : bubbles)
            bubble.circle.center.y -= bubble.vy * delta;
    }

}

@@ -249,16 +249,49 @@
 e circle
+ = new Circle(new Point(0, 0), 0)
 ;%0A      
@@ -314,24 +314,26 @@
 y;%0A%0A        
+/*
 public Bubbl
@@ -454,24 +454,26 @@
 y;%0A        %7D
+*/
 %0A%0A    %7D%0A%0A   
@@ -473,91 +473,8 @@
  %7D%0A%0A
-    private static final int STOCK = 15;%0A%0A    private int numberOfBubbles = STOCK;%0A
     
@@ -511,21 +511,18 @@
  Bubble%5B
-STOCK
+15
 %5D;%0A%0A    
@@ -580,19 +580,30 @@
 i %3C 
-STOCK
+bubbles.length
 ; i++)
+ %7B
 %0A   
@@ -639,51 +639,239 @@
 ble(
-new Point((float) Math.random() * 2, 3.1f),
+);%0A            resetBubble(bubbles%5Bi%5D);%0A        %7D%0A    %7D%0A%0A    public void resetBubble(Bubble bubble) %7B%0A        bubble.circle.center.x = (float) Math.random() * 2;%0A        bubble.circle.center.y = 3.1f;%0A        bubble.circle.radius =
  (fl
@@ -894,17 +894,37 @@
 () * .2f
-,
+;%0A        bubble.vy =
  (float)
@@ -937,16 +937,181 @@
 random()
+;%0A    %7D%0A%0A    public void regenerateBubble() %7B%0A        for (Bubble bubble : bubbles)%0A            if (bubble.circle.center.y %3C -0.1)%0A                resetBubble(bubble
 );%0A    %7D
@@ -1726,16 +1726,44 @@
  delta;%0A
+        regenerateBubble();%0A
     %7D%0A%0A%7D

Reset bubbles when they leave the frame