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 prometheus extends PApplet {prom p = new prom();
bird b = new bird();

float showVictory = -200;
HashSet noms = new HashSet();

public void setup(){
  frameRate(60);
  size(150,150);
  smooth();

  textFont(loadFont("Arial-Black-12.vlw"),12);

  p.x = 75;
  p.y = 75;

}





public void draw() {
  background(0,0,128);
  stroke(0);
  strokeWeight(2);
  fill(0,128,0);
  rectMode(CORNER);
  rect(0,100,150,75);

  fill(128,0,0);
  text("liver:", 10,140);
  noStroke();

  p.drawbar();



  stroke(0);
  strokeWeight(2);


  fill(128);
  ellipse(75,75,100,100);
  p.move();
  p.heal();
  p.draw();


  Iterator i = noms.iterator();
  while(i.hasNext()){
    nom n= (nom)i.next();
    if(n.draw()){
      i.remove(); 
    }
  }


  b.move();
  b.draw();

  if(showVictory >= -300){
    fill(200+(5*(showVictory % 10)));
    text("EAGLE VICTORY!",showVictory,75);

    showVictory --; 
  }


}

public void mousePressed() {

  if(mouseX > (p.x - (p.sz/2)) &&
    mouseX < (p.x + (p.sz/2)) &&
    mouseY > (p.y - (p.sz/2)) &&
    mouseY < (p.y + (p.sz/2))){
    p.held = true;
    p.offx = mouseX - p.x;
    p.offy = mouseY - p.y;
  }


}

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

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

class prom{
  boolean held;
  float x,y,sz,offx,offy,xs,ys;
  float liver=100;
  float bloody;


  prom(){
    sz  = 30; 
  }
  public void draw(){
    stroke(0);
    strokeWeight(2);
    fill(128,128,0);
    rectMode(CENTER);

    line(50,50,x - (sz/2) , y - (sz/2));
    line(100,50,x +(sz/2) , y - (sz/2));
    line(50,100,x - (sz/2) , y + (sz/2));
    line(100,100,x +(sz/2) , y + (sz/2));
    rect(x,y,sz,sz);

    noStroke();
    fill(128,0,0,bloody);
    rect(x,y,5,5);

  }
  public void bite(){
    liver -= 30;
    bloody = 255; 
  }
  public void heal(){
    if(liver <= 0){
      bloody -= .6f;
      if(bloody <= 0){
        liver = 100;
        b.wait = 200;
      }   
    }

  }


  public void move(){
    if(!held){

      if(x < 75){
        xs += .4f;
      }  
      else {
        if(x > 76) {
          xs -= .4f; 
        }
      }
      if(y < 74){
        ys += .4f;
      }  
      else {
        if(y > 76){
          ys -= .4f;
        }
      }
      xs *= .9f;
      ys *= .9f;
      x += xs;
      y += ys;
    } 
    else {
      xs  =0;
      ys = 0; 
    }
  }


  public void drawbar(){
    if(liver > 0){
      rect(43,132,liver,8); 
    }

  }

}


class bird{
  float x = 75;
  float y = 10;
  float down = 5;
  float w = 12;
  float wdir = 1;
  int wait;
  int mode;
  int SEEK = 1;
  int HOVER = 2;
  int EAT  = 3; 

  int dir = 1;

  bird(){
    mode = HOVER;
    wait = 200; 
  }

  public void move(){
    down += wdir;
    if(down > 10){
      wdir = -2;
    } 
    if(down < 0){
      wdir = 2; 
    }

    if(mode == SEEK){
      if(x < p.x){
        x++;
      }  
      else {
        x--; 
      }
      if(y < p.y){
        y++;
      }  
      else {
        y--; 
      }

      if(abs(x - p.x) <= 1 && abs(y - p.y) <= 1){

        if(random(25) < 1){
          noms.add(new nom(x,y));
          p.bite();
        } 
      }
      if(p.liver <= 0){
        mode = HOVER; 
        showVictory = 150;
      }


    }//end mode == SEEK

    if(mode == HOVER){
      if(x > 140){ 
        dir = -1; 
      } 
      if(x < 10){ 
        dir = 1; 
      } 

      if(y < 10) { 
        y++; 
      }
      if(y > 10) { 
        y--; 
      }

      x += dir;
      wait--;

      if(wait <= 0 && p.liver > 0){
        mode = SEEK;
      }  
    } //end mode == HOVER




  }
  public void draw(){
    stroke(255);
    line(x-w, y+down,x,y);
    line(x+w, y+down,x,y);
  }  




}
class nom{
  float x,y,bright;
  nom(float px, float py){
    x = px;
    y = py;
    bright=255;
  }
  public boolean draw() {

    fill(255,255,255,bright);
    text("nom",x,y);
    y -= .2f;
    bright-= 5;
    return !(bright > 0);

  }

}

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