rock r;
boolean flash = false;
int rockscore = 0;
int yourscore  = 0;


void setup(){
  frameRate(60);
  size(150,150);
  r = new rock();
  r.x = 100;
  r.y = 110;
  smooth();
  
  textFont(loadFont("Arial-Black-12.vlw"),12);
  
}





void draw() {


  if(! flash){
    background(0,0,128);  
  } 
  else {
    background(128,0,0);  
  }

noStroke();
  fill(0,128,0);
  rect(0,100,150,75);
  stroke(0);
  strokeWeight(2);
  fill(128);
  triangle(75,25,0,100,150,100);
  r.checkDrop();
  r.move();
  r.draw();
  fill(0);
  text("rock:"+rockscore,10,140);
  text("you:"+yourscore,100,140);

}

void mousePressed() {
  if(   sqrt(
  (mouseX - r.x)*(mouseX - r.x) 
    +
    (mouseY - r.y)*(mouseY - r.y)
    )  < r.sz ){
    r.held = true;
    r.dropping = false;
    r.offx = mouseX - r.x;
    r.offy = mouseY - r.y;
  } 
}

void mouseDragged(){
  if(r.held){
    r.x = mouseX - r.offx;
    r.y = mouseY - r.offy;
  } 
}

void mouseReleased(){
  r.held = false; 
}

class rock{
  float x, y, sz, offx,offy,xs;
  boolean held, dropping;
  rock(){
    sz  = 10 ;
  }

  void draw(){
    fill(128);
    ellipse(x,y,sz,sz);  
  }

  void checkDrop(){
    flash = false;
    boolean miss = false;
    if(held){
    if(y  < 30) {
      miss = true;
    } else {
      if(x < 75){
        if(x < 100 - y){
          miss = true;
//                    flash = true;
        }
      } else { //x >= 75
          if((x - 75)  > (y-25)){
//            flash = true;
            miss = true;
        } 
   
      }     
    } //END NOT Y < 25

    }

    
    if(miss){
      held = false;
      dropping = true; 
      xs = ( x - 75) / 45;

    }
    if(dropping && y > 115){
      dropping = false;
            rockscore++;
    }


  }

  void move(){
    if(dropping){
      y = y +2;
      x = x + xs;

    } 
  
    if(x < 10)  x = 10;
    if(x > 140)  x = 140;

if(y<10) y = 10  ;
if(y>140) y = 140  ;
  }
}