String title=  "cst112 project3";
String author=  "Brian Salaway";
float left, right, top, bottom;
float middle= width/2;


float ratX, ratY, ratDX, ratDY;
float l;
float m;
float n;
boolean wall=true;
int grassX=1;
int grassY=460;
Button1  b1;
Button2  b2;
Ball e1; /////balls=ellipses e1-e5
Ball e2;
Ball e3;
Ball e4;
Ball  e5;
Cloud c1;

void setup() 
  {size(700,500);
  left=   50;
  right=  width-100;
  top=    100;
  bottom= height-100;
  middle= left + (right-left) / 2;
   background(200,0,100);  
  reset();
 }
  void reset(){
b1=new Button1();////wall button
b2=new Button2();////reset button
///balls 
e1 = new Ball(color(255,255,255),left +(right-left)/4, top +(bottom-top)/2, 0, 0);////cue ball
e2 = new Ball(color(255,0,0),random( width/2 ,right ), random( top, bottom ),random( 1,3 ), random( 1,3 ) );   ////red ball
e3 = new Ball(color(255,255,0),random( width/2 ,right ), random( top, bottom ),  random( 1,3 ), random( 1,3 ) );   ////yellow ball
e4 = new Ball(color(0,0,255),random( width/2 ,right ), random( top, bottom ),  random( 1,3 ),  random( 1,3 ));   ////blue ball 
e5 = new Ball(color(255,128,0),random( width/2 ,right ), random( top, bottom ),  random( 1,3 ),  random( 1,3 ));   ////orange ball
c1=  new Cloud();
} 
void draw() {
    { background(200,0,100);
     //clouds();
      table();
      wall();
      grass();
      rat();
     /// bird();
  
b1.display();////buttons
b2.display();  
e1.display();/////balls
e2.display();
e3.display();
e4.display();
e5.display();
e1.move();
e2.move();
e3.move();
e4.move();
e5.move(); 
c1.drawCloud();
c1.moveCloud();
/////overlaps();
}
//}void clouds(){///////////////////////////////////////////////////clouds
   
//cloudY=50; 

//int spacing=100;
///stroke(10);
//f//ill(250);
//for( cloudX=i;cloudX<=width; cloudX+=spacing){
 // ellipse(cloudX,cloudY, 60,30);
//}
//cloudDX=1;
 ///cloudX=cloudX+cloudDX; i=+20;  

//}
}

void table(){ fill(0,200,50);//////////////////////////table
  strokeWeight(20);
  stroke(127,0,0);
  rect(left, top-20, right, bottom-20); }
  
  void wall (){if (wall){
  float middle=(left+right)/2;
  stroke(0,127,0);
  strokeWeight (20);
  line (middle, top+20, middle, bottom+20);} else {middle=left;}
if (wall){
   middle=(left+right)/2;} 
  fill(0,255,0);}
  
  void grass() { int spacing=3;
int len=40;
int endlegs=700;
     fill(0,255,0);
     stroke(0);
     strokeWeight(0);
while(grassX<=endlegs){
  rect(grassX,grassY,2,grassY+len);
  grassX=grassX+spacing; }}  
   
    
    
void rat(){
   ratX= left;       ratY= bottom;    
    ratDX= (0);      ratDY= (0); 
    //////rat
 if(frameCount %30>15){l=(ratY-10);}else{l=(ratY+10);}
   if(frameCount %30>15){m=(ratX+20);}else{m=(ratX-50);}
   if(frameCount %30>15){n=(ratX+30);}else{m=(ratX-20);}
 fill(150);
  ellipse (ratX, ratY, 50, 50);
  ellipse (ratX, ratY-25, 30,30);
  triangle(ratX-5, ratY-35, ratX+2, ratY-50, ratX+5, ratY-35);
  fill(0);
  ellipse(ratX+8, ratY-30, 5,5);
  line(ratX, ratY, ratX+30, l);
  line(ratX-15, ratY+15, ratX-50, ratY+30);
  strokeWeight(10);
  line (ratX, ratY+10, m, ratY+30);
  line(ratX, ratY+10, n, ratY+30);

}

/////void bird()
class Cloud{
float cloudX, cloudY, cloudDX, cloudDY;
int spacing=100;

Cloud(){cloudY=50;cloudX=0;
}

void drawCloud(){
stroke(10);
fill(250);
for( float i=cloudX ;i<=width; i+=spacing){
  ellipse(i,cloudY, 60,30);
}
//=1;
 ///cloudX=cloudX+cloudDX;
}  void moveCloud(){ if (cloudX>width){cloudX=0;}else {cloudX++;}}
}

class Ball{  
color c;
  float xpos;
  float ypos;
  float xspeed;
  float yspeed;
  float diam;   
  Ball(color tempC, float tempXpos, float tempYpos, float tempXspeed, float tempYspeed){
   c = tempC;
   xpos = tempXpos;
   ypos = tempYpos;
   xspeed = tempXspeed;
   yspeed = tempYspeed; 
  diam=30; } 
  
 void move() {xpos=xpos + xspeed; ////move bounce off sides and wall
 ypos += yspeed;
 xpos +=xspeed; 
if (xpos<middle+10 || xpos>right) xspeed *= -1;  
if ((ypos > bottom+30) || (ypos < top)) {yspeed *= -1;}
 }
   //// void overlaps(Ball other) { float d=dist(xpos,ypos,other.xpos, other.ypos);
    ///if(d< (diam+other.diam)/2){xspeed*= -1;}
    void display(){
    strokeWeight(0);
    stroke(0);
    fill(c);
    ellipse(xpos,ypos,diam,diam);}
}

class Button1{
  float c;
   float x;
   float y;
   Button1 (){
      c=color(0);
  x=width/4;
  y=height/10;     }     
     void display(){
       stroke(0);
       fill(0);
       rect(x, y, 50,25);
       fill(255);
       text("wall", x+10, y+15);}
    }
     class Button2{
  float c;
   float x;
   float y;
   Button2(){
      c=color(0);
  x=width*3/4;
  y=height/10; }     
     void display(){
       stroke(0);
       fill(0);
       rect(x, y, 50,25);
       fill(255);
       text("reset", x+10, y+15);
}

 void mousePressed(){ //////resetting balls to right side
 ////////removing wall

 //////reset
 {if (  mouseX >= b2.x && mouseX <=  b2.x+50 
 && mouseY >= b2.y && mouseY <= b2.y+25)    
    reset(); wall=true;}
    
    { if (  mouseX >= b1.x && mouseX <= b1.x+50 
 && mouseY >= b1.y && mouseY <= b1.y+25)   {wall=false;}
}
 }////////////////////////clouds
////////////////////rat


     }
