> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.8wwDuDGT2PI/rev.3865
 * 
 * authors: 
 *   
 *   husk
 *   

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// This sketch builds on a prior work, "testing arraylist", created by husk
// http://studio.sketchpad.cc/sp/pad/view/ro.9U1W$-cDmDtXj/rev.246


ArrayList drops;
ArrayList bars;
ArrayList splash;
ArrayList bonus;

int inicio;
int lightningFrame = 5;
bolean game;
Points p;
bolean barcreation;
int level;


void setup() {
game =1;
  size(320, 240);
  drops = new ArrayList();  // Create an empty ArrayList
  drops.add(new Drop());  // Start by adding one element
  bars= new ArrayList();
  splash= new ArrayList();
  bns=new ArrayList();
  bns.add(new Bonus());
  
    p=new Points();
    level=1;

}

void draw() {

if(game == 0){
    font = loadFont("FFScala.ttf"); 

textFont(font); 

fill(0, 102, 153);
text("bienvenido en DropS", 15, 30); 
fill(100, 100, 100,10);
rect(0,0,320,100);

    } else{
 blur(50);
lightning();


p.draw();
    for (int i = bars.size()-1; i >= 0; i--) { 
    Bar bar = (Bar) bars.get(i);
    bar.draw();
}
  for (int i = drops.size()-1; i >= 0; i--) { 
    Drop drop = (Drop) drops.get(i);
    drop.calculate();
    drop.draw();
    if (drop.position.y>height) {
                        drops.remove(i);
                        float rand = random(0,100);
                        p.sub();
                        if (drops.size()<150) drops.add(new Drop());
                    }
    if (random(0, 10) > 6.9 && drops.size()<1) {
                        drops.add(new Drop());
    }
   
  }
 
for (int i = drops.size()-1; i >= 0; i--) { 
   for (int j = bars.size()-1; j >= 0; j--) { 
          for (int k = bns.size()-1; k >= 0; k--) { 
       Drop drop = (Drop) drops.get(i);
       Bar bar = (Bar) bars.get(j);
       Bonus b = (Bonus) bns.get(k);
       if(drop.position.y> bar.position.y && drop.position.x < bar.pposition.x && drop.position.x > bar.position.x || drop.position.y> bar.position.y && drop.position.x > bar.pposition.x && drop.position.x < bar.position.x ){
               bar.touched=1;
               drops.remove(i);
               startLightning();
                p.add();
                b.draw();
                if (drops.size()<150) drops.add(new Drop());
            for (int k = 0 ; k<random(5,10) ; k++) {
                            splash.add(new Splash(drop.position.x,drop.position.y));
                        }
 }
           }
       }
}
               for (int i=0 ; i<splash.size() ; i++) {
                    Splash spl = (Splash) splash.get(i);
                    spl.calculate();
                    spl.draw();
                    if (spl.position.y>height)
                    splash.remove(i);
                }
}
}


void startLightning() {
                lightningFrame = 1;
            }
            void lightning() {
                if (lightningFrame < 4) {
                    fill(204, 102, 0);
                    rect(0,0,320,240);
                    lightningFrame++;
                }
            }

void blur(float trans) {
                noStroke();
                fill(255,trans);
                rect(0,0,width,height);
            }

void mousePressed() {
    inicio = mouseX;
 
    if (bars.size()< 4){
  // A new ball object is added to the ArrayList, by default to the end
    bars.add(new Bar(mouseX, mouseY, mouseX+1,mouseY));
    barcreation =1
    }

}
void mouseReleased(){
    barcreation=0;
    }
void mouseDragged() 

{   if(barcreation==1){
    Bar lastbar = bars.get(bars.size()-1);
    lastbar.pposition.x =mouseX;

    if (lastbar.pposition.x - lastbar.position.x > 60){
        lastbar.pposition.x= lastbar.position.x+60;
        }
    if (lastbar.pposition.x < lastbar.position.x-60){
        lastbar.pposition.x= lastbar.position.x-60;
        }                                       
}
}



public class Drop {
                PVector position,pposition,speed;
                float col;
                
                public Drop() {
                    position = new PVector(random(0,width),0);
                    pposition = position;
                    speed = new PVector(0,0);
                    col = random(30,100);
                   
                    
                }

                void draw() {
                    stroke(0,col);
                    strokeWeight(2);
                    line(position.x,position.y,pposition.x,pposition.y);


                }

                void calculate() {
                    pposition = new PVector(position.x,position.y);
                    gravity();
                }

                void gravity() {
                    speed.y += .1;
                    speed.x += .01;
                    position.add(speed);
                }
            }
public class Bar {
                PVector position,pposition,speed;
                float col;
                bolean touched;
                int counter;
                bolean delete;
                public Bar(float x, float y, float x2, float y2) {
                    position = new PVector(x,y);
                    pposition = new PVector(x2,y2);
                    speed = new PVector(0,0);
                    col = random(30,100);
                    touched = 0;
                    counter = 0;
                    delete = 0;
                }

                void draw() {
                    //println(position.y);
                    if(touched== 1){
                        stroke(204, 102, 0);  
                        strokeWeight(10);
                        counter +=1;
                        } else {
                    counter =0
                    stroke(0,col);
                    strokeWeight(10); 
                    }
                     if(counter == 30){
                        delete = 1;
                        touched = 0;
                        counter = 0;
                        bars.remove(this);
                         }              
                    line(position.x,position.y,pposition.x,pposition.y);

                }

            }


            public class Splash {
                PVector position,speed;

                public Splash(float x,float y) {
                    float angle = random(PI,TWO_PI);
                    float distance = random(1,5);
                    float xx = cos(angle)*distance;
                    float yy = sin(angle)*distance;
                    position = new PVector(x,y);
                    speed = new PVector(xx,yy);
                }

                public void draw() {
                    strokeWeight(1);
                    stroke(100,50);
                    fill(100,100);
                    ellipse(position.x,position.y,2,2);
                }

                void calculate() {
                    gravity();
                      
                    speed.x*=0.98;
                    speed.y*=0.98;
                            
                    position.add(speed);
                }

                void gravity() {
                    speed.y+=.2;
                }

            }

public class Points {
                    int num;
public Points() {
                      font = loadFont("FFScala.ttf"); 
                      num=0;
                }

public void draw() {
                    textFont(font); 
                   fill(0, 102, 153);
                    text("SCORE: "+num, 15, 10);                   
                }
        void add(){
                num+=30
            }
        void sub(){
                num-=5
            }
}

public class Bonus {
                    int type;
                    PVector position,speed;
                    
public Bonus() {
                      font = loadFont("FFScala.ttf"); 
                      type=0;
                      position= new PVector(random(0,320),50);
                      speed = new PVector(0,0);
                }

 void display() {    println("diplay");
                    /*textFont(font); 
                    stroke(204, 102, 0); 
                    ellipse(30,30,30,30);
                    fill(0, 102, 153, 50);
                    text("C", position.x, position.y);*/
                                       
                }
                public void draw() {
                    textFont(font); 
                   fill(0, 102, 153);
                    text("bananan: ", 15, 100);                   
                }
       public void calculate(){
                if(random(1,10)> (level*1)){
                    floating();
                    }
            }
        void floating(){
                speed.x+=0.1
                speed.y+=1;
                display();
            }
}