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 preggers extends PApplet {
boolean gamePlaying = false;
boolean gameTitle = true;
eggclass egg;
int SCREENSIZE = 400;
HashSet sperms = new HashSet();

int score = 0;

public void setup(){
  size(400,400);
  ellipseMode(CENTER_RADIUS);
  textFont(loadFont("Arial-Black-14.vlw"),14);
  egg = new eggclass();
  framerate(60);

}
boolean freeze = false;
public void keyPressed(){
 //  freeze = true; 
}

public void mouseReleased(){
  if(! gamePlaying){
    gamePlaying = true;
    gameTitle = false;
    sperms.clear();
    addSperm();
    score = 1;
  } 
  else {
    score++;
    addSperm();
  }
}



public void draw(){
  background(180,40,40);

  if(gamePlaying){
    Iterator i = sperms.iterator();
    while(i.hasNext()){
      spermclass sperm = (spermclass)i.next(); 
      if(! freeze){sperm.move();}

    }

  } // end if(gamePlaying)
 
  egg.draw();

  Iterator i = sperms.iterator();
  while(i.hasNext()){
    spermclass sperm = (spermclass)i.next(); 
    sperm.draw();
    
      if(sperm.hit(egg)){
        gamePlaying = false;
        gameTitle = false;
      }

  }
       fill(255);
      textAlign(CENTER); 
  if(!gameTitle) { text("score: "+score,200,20);}
  if((! gamePlaying) ){
 

          if(! gameTitle){
      text("OH NOES!",200,100);
      text("YOUR PREGGERS!!!!!!",200,150);
            text("SEMEN HAS MILLIONS OF SPERMS!!!",200,200);
      text("remember sometimes the only way to win",200,250);
      text("is not to play!!!!!!!",200,300);
            text("~o ~o ~o click to try again o~ o~ o~",200,350);
          } else {
           text("~o ~o ~o look out! o~ o~ o~",200,100);
      text("you are a precious egg cell!",200,150);
      text("try not to get PREGGERS!!!!!",200,200);
      text("click to start and look out for SPERMS!!!",200,250);
      text("then click to add more SPERMS!!!",200,300);

      
          }      
     
  }


}



//--------------------------------add sperm
public void   addSperm(){
  float x,y;
  x = mouseX;
  y = mouseY;
  while(abs(mouseX - x ) < 80 ||abs(mouseY - y ) < 80){
    if( PApplet.toInt(random(2)) == 0){
      if( PApplet.toInt(random(2)) ==0){
        x = -20;
      } 
      else {
        x = SCREENSIZE + 20; 
      }
      y = random(SCREENSIZE - 30)+ 30;
    } 
    else {
      if( PApplet.toInt(random(2)) ==0){
        y = -20; 
      } 
      else {
        y = SCREENSIZE + 20; 
      }
      x = random(SCREENSIZE - 30)+ 30;

    }

  }
  
  sperms.add( new spermclass(x,y));
}



//--------------------------------EGG CLASS
class eggclass{
    public float x,y;
    public void draw(){

    if(gamePlaying || gameTitle){
       x = mouseX;
      y = mouseY ;
    }
    
        stroke(0);
    fill(0);
    ellipse(x,y,5,5);
    noFill();
    ellipse(x,y,10,10);
  } 
  eggclass(){
  }

}



//--------------------------------SPERM CLASS
class spermclass{
  float xs, ys, x, y;
  float tailx[] = new float[100] ;
  float taily[] = new float[100];

  float accel = .05f;
  int tailsize = 20;

  spermclass(float px, float py){
    x = px;
    y = py;
    for(int i = 0; i < tailsize; i++){
      tailx[i] = x;
      taily[i] = y;
    } 
  }

  public void move(){
    for(int i = tailsize-1; i > 0; i--){
      tailx[i] = tailx[i-1];
      taily[i] = taily[i-1];
    } 
    tailx[0] = x;
    taily[0] = y;     

    if(x < mouseX) {
      xs += accel;
    } 
    else {
      xs -= accel;
    }
      
      if(y < mouseY) ys += accel;
      else ys -= accel;

      xs *= .99f;
      ys *= .99f;
      x += xs;
      y += ys;
      
    }

    public void draw(){
      stroke(0);
      for(int i = 1; i < tailsize; i++){
        line(tailx[i],taily[i],tailx[i-1],taily[i-1]);
      } 

      fill(0);
      ellipse(x,y,3,3);
    } 

    public boolean hit(eggclass egg){
      if(sqrt(   
          ((x - egg.x) *(x - egg.x) )
          +
          ((y - egg.y) *(y - egg.y) )
           )  < 13   ){
               return true;
           }
      return false;
    }

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