Lab3 - FlyingBird



void setup() {
  size(530, 530);
  frameRate(60);
}
float global_BX, global_BY, global_BL, global_BW;
void draw() {
  background(#87CEFA);
  Cloud();
  Body(width/2, height/2, width*3/16, height*3/16);
  motion_bird(3);
  motion_cloud();
}
void Body(float BX, float BY, float BL, float BW) {
  global_BX=BX; //Bird_X
  global_BY=BY; //Bird_Y
  global_BL=BL; //Bird_Lenght
  global_BW=BW; //Bird_Width
  stroke(#8B7355);
  fill(#DEB887);
  strokeWeight(5);
  ellipse(width/2, height/2, width*3/16, height*3/16);


  bezier(BX+BL/6, BY-BW/6, BX+BL*2/3, BY-BW/2, BX+BL*2/3, BY-BW/2+End_R/3, BX*14/8, BY+End_R);
  //line(BX+BL/6, BY-BW/6, BX+BL*2/3, BY-BW/2);
  //line(BX+BL*2/3, BY-BW/2,BX*14/8, BY);
  bezier(BX-BL/6, BY-BW/6, BX-BL*2/3, BY-BW/2, BX-BL*2/3, BY-BW/2+End_R/3, BX*2/8, BY+End_R);
  //line(BX+BL/6, BY-BW/6, BX*14/8, BY+End_R);
  //line(BX-BL/6, BY-BW/6, BX*2/8, BY+End_R);

  strokeWeight(3);
  ellipse(BX, BY, BL/2, BW/2);
  fill(#8B7355);
  ellipse(BX-BL/18, BY-BW/13, BL/50, BW/50);
  ellipse(BX+BL/18, BY-BW/13, BL/50, BW/50);

  noFill();
  beginShape();
  vertex(BX-BL/10, BY);
  vertex(BX, BY+BW/7);
  vertex(BX+BL/10, BY);
  endShape();
}
float End_R=0;
boolean Ending_R=false;
void motion_bird(int speed) {
  if (mouseButton == LEFT)speed+=2;
  else if (mouseButton == RIGHT)speed-=2;
  if (End_R<-global_BW/3)Ending_R=true;
  else if (End_R>global_BW/3)Ending_R=false;

  if (Ending_R)End_R+=speed;
  else if (!Ending_R)End_R-=speed;
}
void Cloud() {
  noStroke();
  fill(255);
  ellipse(width*3/16+motion_C1, height*3/16, width*5/16, height*2/16); //Cloud 1
  ellipse(width*12/16+motion_C2, height*5/16, width*7/16, height*3/16); //Cloud 2
  ellipse(width*2/16+motion_C3, height*11/16, width*8/16, height*5/16); //Cloud 3
  ellipse(width*15/16+motion_C4, height*13/16, width*13/16, height*6/16); //Cloud 4
}
boolean limitC1X, limitC2X, limitC3X, limitC4X;
float motion_C1, motion_C2, motion_C3, motion_C4;

void motion_cloud() {
  if (motion_C1<-width*0.3/16)limitC1X=true;
  else if (motion_C1>width*0.3/16)limitC1X=false;
  if (limitC1X)motion_C1+=0.05;
  else motion_C1-=0.05;

  if (motion_C2<-width*0.5/16)limitC2X=true;
  else if (motion_C2>width*0.5/16)limitC2X=false;
  if (limitC2X)motion_C2+=0.15;
  else motion_C2-=0.15;

  if (motion_C3<-width*1/16)limitC3X=true;
  else if (motion_C3>width*1/16)limitC3X=false;
  if (limitC3X)motion_C3+=0.33;
  else motion_C3-=0.33;

  if (motion_C4<-width*1/16)limitC4X=true;
  else if (motion_C4>width*1/16)limitC4X=false;
  if (limitC4X)motion_C4+=0.55;
  else motion_C4-=0.55;
}