import processing.core.*; import java.applet.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.text.*; import java.util.*; import java.util.zip.*; public class sisyphus extends PApplet {rock r;
boolean flash = false;
int rockscore = 0;
int yourscore  = 0;


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





public void draw() {


  if(! flash){
    background(0,0,128);  
  } 
  else {
    background(128,0,0);  
  }
  stroke(0);
  strokeWeight(2);
  fill(0,128,0);
  rect(0,100,150,75);
  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,75,140);

}

public 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;
  } 
}

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

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

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

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

  public 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++;
    }


  }

  public 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  ;
  }
}

  static public void main(String args[]) {     PApplet.main(new String[] { "sisyphus" });  }}