29 ตุลาคม 2556

Assignment 2_BB

..# Assignment 2_BB #.. 
~ ~ Assignment 2_B ~

 
Assignment 2_B  Processing.js code




void setup() {
  size(600, 400);
}

///////////////////
float[][] B2 = {
  {
    100, 140, 180, 220, 260, 300, 340, 380
  }
  ,
  {
    260, 215, 177, 146, 122, 105, 95, 90
  }
};

float[][] B1 = {
  {
    100, 140, 190, 240, 290, 335, 380
  }
  ,
  {
    260, 220, 192, 176, 172, 173, 180
  }
};

float[][] B0 = {
  {
    100, 160, 220, 275, 330, 380
  }
  ,
  {
    260, 245, 241, 248, 266, 295
  }
};

float[][] G0 = {
  {
    112, 112, 179, 246, 313, 380
  }
  ,
  {
    175, 175, 190, 215, 250, 295
  }
};

float[][] G1 = {
  {
    120, 120, 185, 250, 315, 380
  }
  ,
  {
    130, 130, 135, 145, 160, 180
  }
};

float[][] G2 = {
  {
    112, 112, 179, 246, 313, 380
  }
  ,
  {
    92, 92, 81, 77, 80, 90
  }
};

int r = 20;  //รัศมีลูกบอล

int b; //สุ่มตำแหน่งลูก
int b2;
int b3;
int b4;

int po = 0;  //pow ท่าตี
int pow2 = 0; //ท่าตี
int score;  //นับคะแนน

int snoopyY = 300;  //float[] ball
int sno = 0;

int pass = 1;  //คววามเร็ว
int level;  //ระดับ
int life = 3; //ชีวิตที่หลือ

int number = 0;  //หน้าเริ่ม


int ball;
int ball2 = 1;
int ball3 = G0[0].length;
int ball4 = G0[0].length;

int step;  //snoopy ตีลูกกลับ
int step2;
int step3;
int step4;

int i = 0;
int j = 0;
int m = 0;
int n = 0;

int space = 50; //boy เดิน

int miss;
int count;
int nu = 60;
int ni = 50;

int over;

int boy =1;
int back;
////////////////////
void keyPressed() {
  if (keyCode == UP&&sno>=0&&sno<2) {
    sno = sno+1;
    snoopyY = snoopyY-100;
  }
  if (keyCode == DOWN&&sno>0&&sno<=2) {
    sno = sno-1;
    snoopyY = snoopyY+100;
  }
  if (sno==b||sno==b2||sno==b3||sno==b4) {
    if (key=='T'||key=='t') {
      if (i==ball-1) {
        score = score+2;  //score
        ball = G0[0].length;   //ตีกลับ boy
        step = sno+1;
        i = ball-1;
      }
      else if (j==ball2-1) {
        score = score+2;  //score
        ball2 = G0[0].length;   //ตีกลับ boy
        step2 = sno+1;
        j = ball2-1;
      }
      else if (m==ball3-1) {
        score = score+3;
        ball3 = G0[0].length;  //ตีกลับ girl
        step3 = sno+1;
        m = ball3-1;
      }
      else if (n==ball4-1) {
        score = score+3;  //score
        ball4 = G0[0].length;  //ตีกลับ girl
        step4 = sno+1;
        n = ball4-1;
      }
      po = po+1;  //ท่าตี snoopy
      if (score==4||score>4&&score%3==0) {
        back = 1;
      }
    }
  }
}

///////////////////////////
void draw() {
  if (miss<=4) {
    background(195, 255, 230);
    sceen();
    Life(life, width-150, 15);
    textFont(createFont("Arial", 17));
    fill(0, 0, 255);
    text("score = "+score+"     Level "+level+"      Life "+life, 30, 30);
    if (boy==1) {
      Boy1(space, height-25);
    }
    else if (boy==2) {
      Boy2(300, height-25);
    }
  }

  /////////// ตำแหน่ง boy

  /////////// ตำแหน่ง snoopy
  if (sno==0) {
    if (pow2==1) {
      pow2(width-200, snoopyY);
      if (count%nu==0) {
        pow2 = 0;
      }
    }
    else if (po==1) {
      pow1(width-200, snoopyY);
      if (count%nu==0) {
        pow2 = 1;
      }
    }
    else {
      tennis(width-200, snoopyY);
    }
    Snoopy(width-200, snoopyY);
  }

  else if (sno==1) {
    if (pow2==1) {
      pow2(width-200, snoopyY);
      if (count%nu==0) {
        pow2 = 0;
      }
    }
    else if (po==1) {
      pow1(width-200, snoopyY);
      if (count%nu==0) {
        pow2 = 1;
      }
    }
    else {
      tennis(width-200, snoopyY);
    }
    Snoopy1(width-200, snoopyY); //เปลี่ยนภาพได้
  }
  else if (sno==2) {
    if (pow2==1) {
      pow2(width-200, snoopyY);
      if (count%nu==0) {
        pow2 = 0;
      }
    }
    else if (po==1) {
      pow1(width-200, snoopyY);
      if (count%nu==0) {
        pow2 = 1;
      }
    }
    else {
      tennis1(width-200, snoopyY);
    }
    Snoopy2(width-200, snoopyY);
  }
  else if (sno==3) {
    Snoopyover(560, 300);
  }

  if (count%nu==0) {
    po = 0;
  }

  ////////////  ตำแหน่ง บอล
  fill(0);
  // boy ตีโต้
  if (i>0&&i<ball) {
    if (b==0) {
      if (step==1) {
        ellipse(G0[0][i], G0[1][i], r, 2*r/3);
        if (count%ni==0) {
          i = i-1;
        }
      }
      else {
        ellipse(B0[0][i], B0[1][i], r, 2*r/3);
        if (count%nu==0) {
          i = i+1;
        }
      }
    }
    else if (b==1) {
      if (step==2) {
        ellipse(G1[0][i], G1[1][i], r, 2*r/3);
        if (count%ni==0) {
          i = i-1;
        }
      }
      else {
        ellipse(B1[0][i], B1[1][i], r, 2*r/3);
        if (count%nu==0) {
          i = i+1;
        }
      }
    }
    else if (b==2) {
      if (step==3) {
        ellipse(G2[0][i], G2[1][i], r, 2*r/3);
        if (count%ni==0) {
          i = i-1;
        }
      }
      else {
        ellipse(B2[0][i], B2[1][i], r, 2*r/3);
        if (count%nu==0) {
          i = i+1;
        }
      }
    }
  }

  if (j>0&&j<ball2) {
    if (b2==0) {
      if (step2==1) {
        ellipse(G0[0][j], G0[1][j], r, 2*r/3);
        if (count%ni==0) {
          j = j-1;
        }
      }
      else {
        ellipse(B0[0][j], B0[1][j], r, 2*r/3);
        if (count%nu==0) {
          j = j+1;
        }
      }
    }
    else if (b2==1) {
      if (step2==2) {
        ellipse(G1[0][j], G1[1][j], r, 2*r/3);
        if (count%ni==0) {
          j = j-1;
        }
      }
      else {
        ellipse(B1[0][j], B1[1][j], r, 2*r/3);
        if (count%nu==0) {
          j = j+1;
        }
      }
    }
    else if (b2==2) {
      if (step2==3) {
        ellipse(G2[0][j], G2[1][j], r, 2*r/3);
        if (count%ni==0) {
          j = j-1;
        }
      }
      else {
        ellipse(B2[0][j], B2[1][j], r, 2*r/3);
        if (count%nu==0) {
          j = j+1;
        }
      }
    }
  }

  // girl โต้กลับ
  if (m>0&&m<ball3) {
    fill(0);
    if (b3==0) {
      if (step3==1) {
        ellipse(G0[0][m], G0[1][m], r, 2*r/3);
        if (count%ni==0) {
          m = m-1;
        }
      }
      else {
        ellipse(G0[0][m], G0[1][m], r, 2*r/3);
        if (count%ni==0) {
          m = m+1;
        }
      }
    }
    else if (b3==1) {
      if (step3==2) {
        ellipse(G1[0][m], G1[1][m], r, 2*r/3);
        if (count%ni==0) {
          m = m-1;
        }
      }
      else {
        ellipse(G1[0][m], G1[1][m], r, 2*r/3);
        if (count%ni==0) {
          m = m+1;
        }
      }
    }
    else if (b3==2) {
      if (step3==3) {
        ellipse(G2[0][m], G2[1][m], r, 2*r/3);
        if (count%ni==0) {
          m = m-1;
        }
      }
      else {
        ellipse(G2[0][m], G2[1][m], r, 2*r/3);
        if (count%ni==0) {
          m = m+1;
        }
      }
    }
  }

  if (n>0&&n<ball4) {
    fill(0);
    if (b4==0) {
      if (step4==1) {
        ellipse(G0[0][n], G0[1][n], r, 2*r/3);
        if (count%ni==0) {
          n = n-1;
        }
      }
      else {
        ellipse(G0[0][n], G0[1][n], r, 2*r/3);
        if (count%ni==0) {
          n = n+1;
        }
      }
    }
    else if (b4==1) {
      if (step4==2) {
        ellipse(G1[0][n], G1[1][n], r, 2*r/3);
        if (count%ni==0) {
          n = n-1;
        }
      }
      else {
        ellipse(G1[0][n], G1[1][n], r, 2*r/3);
        if (count%ni==0) {
          n = n+1;
        }
      }
    }
    else if (b4==2) {
      if (step4==3) {
        ellipse(G2[0][n], G2[1][n], r, 2*r/3);
        if (count%ni==0) {
          n = n-1;
        }
      }
      else {
        ellipse(G2[0][n], G2[1][n], r, 2*r/3);
        if (count%ni==0) {
          n = n+1;
        }
      }
    }
  }

  /////////////
  if (back==1) {
    Girl(100, 50);
    //level = level+1;
    if (i==0) {
      m = 1;
      b3 = b;
      back = 0;
    }
    else if (j==0) {
      n = 1;
      b4 = b;
      back = 0;
    }
  }


  if (i==0||j==0&&i==5) { //สุ่มตำแน่ง
    float a = random(0, 3);
    if (a<=1) {
      if (i==0) {
        ball = B0[0].length;
        b = 0;
        step = 0;
        i = 1;
      }
      else if (j==0) {
        ball2 = B0[0].length;
        b2 = 0;
        step2 = 0;
        j = 1;
      }
    }
    if (a<=2&&a>1) {
      if (i==0) {
        ball = B1[0].length;
        b = 1;
        step = 0;
        i = 1;
      }
      else if (j==0) {
        ball2 = B1[0].length;
        b2 = 1;
        step2 = 0;
        j = 1;
      }
    }
    if (a<=3&&a>2) {
      if (i==0) {
        ball = B2[0].length;
        b = 2;
        step = 0;
        i = 1;
      }
      else if (j==0) {
        ball2 = B2[0].length;
        b2 = 2;
        step2 = 0;
        j = 1;
      }
    }
  }

  ////////// miss
  if(count%60==0){
    if (i>=ball) {
      j = 0;
      m = 0;
      n = 0;
      over = b+1;
    }
    if (j>=ball2) {
      i = B2[0].length+1;
      m = 0;
      n = 0;
      over = b2+1;
    }
    if (m>=ball3) {
      j = 0;
      i = B2[0].length+1;
      n = 0;
      over = b3+1;
    }
    if (n>=ball4) {
      j = 0;
      i = B2[0].length+1;
      m = 0;
      over = b4+1;
    }
  }


  if (miss==1) {
    fill(0);
    if (over==1) {
      ellipse(width-90, 300, r, 2*r/3);
    }
    if (over==2) {
      ellipse(width-90, 200, r, 2*r/3);
    }
    if (over==3) {
      ellipse(width-90, 100, r, 2*r/3);
    }  
  }

  if (i>=ball||j>=ball2||m>=ball3||n>=ball4) {
    if (life==1) {
      background(0);
      sceen();
      fill(252, 120, 252);
      textFont(createFont("Arial", 50));
      text("Game Over", 150, 150);
      textFont(createFont("Arial", 15));
      text("score = "+step+"     Level "+level, 200, 200);
      Snoopyover(560, 300);
      Boy2(300, 350);
    }
    else if (miss==4) {
      if (count%40==0) {
        boy = 2;
      }
      if (count%120==0) {
        sno = 0;
        snoopyY = 300;
        boy = 1;
        space = 50;
        life = life-1;
        step = 0;
        step2 = 0;
        step3 = 0;
        step4 = 0;
        i = 0;
        j = 0;
        m = 0;
        n = 0;
        count = 0;
        miss = 0;
      }
    }
    else {
      if (count%nu==1) {
        space = space+60;
      }
      if (count%nu==0) {
        if (miss==2) {
          sno = 3;
        }
        miss++;
      }
    }
  }
  count++;
}


///////////////////
void tennis(float x, float y) {
  stroke(0);
  noFill();
  strokeWeight(3);
  ellipse(x+100, y, 36, 46);
  line(x+82, y-5, x+118, y+5);
  line(x+88, y-18, x+114, y-9);
  line(x+86, y+9, x+112, y+18);
  strokeWeight(6);
  line(x+86, y+20, x+73, y+35);
  fill(255);
  strokeWeight(1);
  ellipse(x+65, y+35, 15, 10);
}

void tennis1(float x, float y) {
  stroke(0);
  noFill();
  strokeWeight(3);
  ellipse(x+100, y+70, 36, 46);
  line(x+82, y+80, x+118, y+60);
  line(x+86, y+62, x+112, y+50);
  line(x+93, y+88, x+116, y+75);
  strokeWeight(6);
  line(x+86, y+50, x+67, y+35);
  strokeWeight(1);
  fill(255);
  ellipse(x+65, y+35, 15, 10);
}

//////////////
void pow1(float x, float y) {
  stroke(0);
  fill(0);
  ellipse(x, y-10, 10, 46);
  strokeWeight(3);
  line(x, y-15, x, y+30);
  fill(255);
  noStroke();
  quad(x, y+33, x, y+28, x+35, y+37, x+35, y+43);
  stroke(0);
  strokeWeight(1);
  ellipse(x, y+30, 20, 15);
}

void pow2(float x, float y) {
  noFill();
  stroke(0);
  strokeWeight(3);
  ellipse(x-20, y+63, 46, 36);
  line(x-40, y+63, x-23, y+78);
  line(x-35, y+50, x-7, y+78);
  line(x-20, y+45, x, y+68);
  strokeWeight(6);
  line(x+30, y+43, x, y+50);
  fill(255);
  strokeWeight(1);
  ellipse(x+25, y+43, 15, 10);
}
////////////////////
void Snoopy(float x, float y) {
  strokeWeight(1);
  fill(255);
  noStroke();
  ellipse(x+55, y, 35, 45);
  ellipse(x+40, y+3, 60, 38);
  ellipse(x+45, y+39, 28, 35);
  ellipse(x+52, y+50, 20, 5);
  quad(x+46, y+50, x+57, y+70, x+64, y+70, x+53, y+50);
  quad(x+36, y+50, x+32, y+70, x+39, y+70, x+43, y+50);
  fill(0);
  ellipse(x+10, y+7, 10, 7);
  ellipse(x+45, y-5, 5, 10);
  ellipse(x+70, y+10, 20, 35);
  stroke(0);
  fill(255);
  ellipse(x+30, y+70, 25, 15);
  ellipse(x+60, y+70, 25, 15);
  ellipse(x+40, y+40, 10, 10);
}
////////////////////
void Snoopy1(float x, float y) {
  strokeWeight(1);
  fill(255);
  noStroke();
  ellipse(x+55, y, 40, 50);
  ellipse(x+40, y+5, 60, 40);
  ellipse(x+45, y+41, 28, 35);
  ellipse(x+52, y+55, 20, 5);
  rect(x+46, y+50, 7, 20);
  quad(x+36, y+50, x+32, y+70, x+39, y+70, x+43, y+50);
  fill(0);
  ellipse(x+10, y+10, 10, 7);
  ellipse(x+45, y-5, 5, 10);
  ellipse(x+70, y+10, 20, 35);
  stroke(0);
  fill(255);
  ellipse(x+35, y+70, 25, 15);
  ellipse(x+48, y+70, 25, 15);
  ellipse(x+50, y+50, 10, 10);
}
/////////////////////
void Snoopy2(float x, float y) {
  strokeWeight(1);
  fill(255);
  noStroke();
  ellipse(x+50, y, 50, 50);
  ellipse(x+40, y+10, 60, 40);
  ellipse(x+45, y+45, 28, 35);
  ellipse(x+55, y+55, 20, 5);
  fill(0);
  ellipse(x+30, y+10, 10, 7);
  ellipse(x+40, y-5, 5, 10);
  ellipse(x+48, y-5, 5, 10);
  ellipse(x+70, y+10, 20, 35);
  stroke(0);
  fill(255);
  ellipse(x+30, y+50, 15, 25);
  ellipse(x+40, y+50, 15, 25);
  ellipse(x+55, y+50, 10, 10);
}
/////////////////////
void Snoopyover(int s, int p) {
  noStroke();
  fill(255); //head
  ellipse(s-40, p-20, 50, 45);
  ellipse(s-35, p-30, 40, 60);
  ellipse(s, p-15, 35, 25); //body
  rect(s+13, p-15, 15, 10);  //leg
  ellipse(s+28, p-15, 10, 25);  //foot
  fill(0, 0, 0);  //nose
  ellipse(s-35, p-60, 10, 10 );
  ellipse(s-50, p+15, 10, 35);  //ear
  stroke(0, 0, 0);
  fill(255);
  ellipse(s+5, p-5, 10, 10);  //hand
  line(s-50, p-35, s-45, p-30);  //eye
}
//////////////////

void Boy1(int b, int o) {
  fill(255, 250, 205);
  stroke(255, 250, 205);
  //neck
  rect(b-5, o-80, 7, 10);
  //head
  ellipse(b, o-100, 50, 50);
  //nose
  ellipse(b+28, o-100, 10, 10);
  //ear
  stroke(0);
  ellipse(b-10, o-100, 10, 10);
  //eye
  fill(0);
  ellipse(b+15, o-105, 6, 8);
  ellipse(b+50, o-110, 15, 15);

  //arm1
  fill(255, 250, 205);
  stroke(255, 250, 205);
  ellipse(b+20, o-60, 40, 10);
  ellipse(b+40, o-65, 15, 15);

  //arm2
  ellipse(b+20, o-50, 10, 10);
  ellipse(b+30, o-45, 15, 15);

  //leg
  fill(255, 250, 205);
  stroke(255, 250, 205);
  rect(b, o-25, 10, 20);
  rect(b-15, o-20, 10, 20);

  //pant
  fill(0, 0, 128);
  stroke(0, 0, 128);
  rect(b-20, o-30, 40, 15);

  //foot
  fill(28, 28, 28);
  stroke(255, 250, 205);
  ellipse(b+10, o, 20, 10);
  ellipse(b-5, o+3, 20, 10);

  //body
  fill(255, 255, 0);
  stroke(255, 255, 0);
  rect(b-10, o-70, 15, 15);
  quad(b-10, o-70, b+10, o-70, b+20, o-30, b-20, o-30);
  stroke(205, 155, 29);
  rect(b+10, o-70, 15, 15);
  stroke(0);
  strokeWeight(5);
  line(b-15, o-45, b-10, o-37);
  line(b-10, o-37, b-5, o-45);
  line(b-5, o-45, b, o-37);
  line(b, o-37, b+5, o-45);
  line(b+5, o-45, b+10, o-37);
  line(b+10, o-37, b+15, o-45);

  //tennis
  strokeWeight(2);
  fill(255);
  line(b+35, o-40, b+45, o-30);
  ellipse(b+47, o-20, 20, 40);
  strokeWeight(1);
  line(b+42, o-35, b+56, o-25);
  line(b+39, o-27, b+56, o-15);
  line(b+36, o-19, b+55, o-5);

  line(b+44, o-37, b+40, o-17);
  line(b+50, o-37, b+42, o-3);
  line(b+56, o-35, b+50, o-3);

  //hair
  line(b+15, o-120, b+25, o-130);
  line(b-25, o-90, b-35, o-95);
}

/////////////
void Boy2(int b, int o) {
  fill(255, 250, 205);
  stroke(255, 250, 205);
  rect(b-5, o-80, 7, 10);//neck
  ellipse(b, o-100, 50, 50);  //head
  ellipse(b+28, o-100, 10, 10);  //ear
  ellipse(b-27, o-100, 10, 10);
  stroke(0);  //nose
  ellipse(b, o-95, 7, 7);
  fill(0);//eye
  ellipse(b+10, o-100, 4, 6);
  ellipse(b-10, o-100, 4, 6);
  line(b-5, o-85, b+5, o-85);//mouse
  fill(255, 250, 205);  //arm1
  stroke(255, 250, 205);
  ellipse(b+20, o-60, 40, 10);
  ellipse(b+40, o-65, 15, 15);
  ellipse(b-20, o-60, 40, 10);  //arm2
  ellipse(b-40, o-65, 15, 15);
  fill(255, 250, 205);  //leg
  stroke(255, 250, 205);
  rect(b, o-25, 10, 20);
  rect(b-15, o-20, 10, 20);
  fill(0, 0, 128);  //pant
  stroke(0, 0, 128);
  rect(b-20, o-30, 40, 15);
  fill(28, 28, 28);  //foot
  stroke(255, 250, 205);
  ellipse(b+10, o, 20, 10);
  ellipse(b-5, o+3, 20, 10);
  fill(255, 255, 0);  //body
  rect(b-10, o-70, 15, 15);
  stroke(205, 155, 29);
  rect(b+10, o-70, 15, 15);
  rect(b-25, o-70, 15, 15);
  stroke(255, 255, 0);
  quad(b-10, o-70, b+10, o-70, b+20, o-30, b-20, o-30);
  stroke(0);
  strokeWeight(5);
  fill(255);
  line(b-15, o-45, b-10, o-37);
  line(b-10, o-37, b-5, o-45);
  line(b-5, o-45, b, o-37);
  line(b, o-37, b+5, o-45);
  line(b+5, o-45, b+10, o-37);
  line(b+10, o-37, b+15, o-45);
  strokeWeight(3);
  line(b-5, o-120, b, o-115);  //hair
  line(b, o-120, b+5, o-115);
  strokeWeight(1);
}

///////////////////
void Girl(int g, int l) {
  fill(255, 250, 205);
  stroke(255, 250, 205);
  //neck
  rect(g-55, l+70, 7, 10);
  //nose
  ellipse(g-22, l+50, 10, 10);
  //head
  ellipse(g-50, l+50, 50, 50);
  fill(0);
  stroke(0);
  //hair
  ellipse(g-40, l+25, 25, 15);
  ellipse(g-60, l+30, 35, 25);
  ellipse(g-70, l+45, 25, 35);
  ellipse(g-70, l+65, 40, 20);
  //mouse
  line(g-40, l+60, g-30, l+65);
  //eye
  line(g-40, l+40, g-35, l+46);
  line(g-35, l+40, g-35, l+46);
  //tennis
  strokeWeight(2);
  line(g-5, l+55, g-5, l+80);
  fill(255);
  stroke(0);
  ellipse(g-5, l+40, 20, 50);
  strokeWeight(1);
  line(g-10, l+20, g-10, l+60);
  line(g-5, l+15, g-5, l+65);
  line(g, l+20, g, l+60);
  line(g-15, l+30, g+5, l+30);
  line(g-15, l+40, g+5, l+40);
  line(g-15, l+50, g+5, l+50);
  //arm2
  fill(255, 250, 205);
  stroke(255, 250, 205);
  ellipse(g-30, l+90, 50, 10);
  ellipse(g-10, l+85, 25, 15);
  //leg
  fill(255, 250, 205);
  stroke(255, 250, 205);
  rect(g-40, l+130, 10, 20);
  rect(g-65, l+135, 20, 10);
  //foot2
  fill(139, 58, 98);
  stroke(139, 58, 98);
  ellipse(g-30, l+150, 20, 10);
  ellipse(g-60, l+143, 10, 20);
  //body
  fill(255, 110, 180);
  stroke(255, 110, 180);
  quad(g-60, l+80, g-40, l+80, g-20, l+130, g-75, l+130);
  ellipse(g-50, l+130, 65, 15);
  //arm1
  fill(255, 250, 205);
  stroke(255, 250, 205);
  ellipse(g-60, l+110, 10, 40);
  ellipse(g-60, l+130, 15, 15);
  fill(255, 110, 180);
  stroke(139, 58, 98);
  ellipse(g-60, l+90, 20, 20);
}

/////////////////////
void Life(int count, int x, int y) {
  int n = 0;
  while (n<count) {
    strokeWeight(0);
    fill(255);
    noStroke();
    ellipse(x+50, y, 20, 25);
    ellipse(x+43, y+3, 30, 20);
    fill(0);
    ellipse(x+28, y+5, 5, 4);
    ellipse(x+45, y-2, 5, 7);
    ellipse(x+58, y+5, 13, 22);
    x = x+40;
    n = n+1;
  }
}

/////////////////////
int button(String s, int number) {
  fill(60, 227, 69);
  rect(150, 100, 300, 200);
  fill(255, 10, 47);
  textFont(createFont("Arial", 50));
  text(s, 220, 210);  
  if (mousePressed&&mouseX>150&&mouseX<450&&mouseY>100&&mouseY<300) {  
    if (number==0) {
      number=1;
    }
  }
  return number;
}

/////////////////////
//Background
void sceen() {
  Pole(80, 10);
  Tree(width-130, height-25, 60, 40, 20);
  Crate(width-80, height-100, 40, 30);
}


void Tree(int x, int y, int b, int h, int r) {
  noStroke();
  //leaf
  fill(46, 160, 26);
  ellipse(x+2*b, y-5*h-h/3, 2*r/3, r); //middle
  ellipse(x+2*b+r/2, y-5*h, r, 2*r/3);
  ellipse(x+2*b, y-5*h+h/3, 2*r/3, r);
  ellipse(x+2*b-r, y-5*h-h/4, r, 3*r/2);
  ellipse(x+2*b-2*r/3, y-5*h+2*h/3, r, 2*r/3);
  ellipse(x+2*b-3*r/2, y-4*h, r, 3*r/2);
  ellipse(x+b, y-5*h, 4*r/3, r);
  ellipse(x+b+r/2, y-5*h-h/2, 2*r/3, r);
  ellipse(x+b+r, y-5*h, 2*r/3, r);
  ellipse(x+2*b-b/4, y-9*h, 2*r/3, r); //top left
  ellipse(x+2*b, y-9*h-h/5, 2*r/3, r);
  ellipse(x+2*b+r/2, y-9*h+h/5, r, 2*r/3);
  ellipse(x+2*b-b/3, y-7*h-h/3, r, 3*r/2);
  ellipse(x+2*b, y-8*h+h/5, 3*r/2, r);
  ellipse(x+b+b/3, y-8*h+h/2, r, 2*r/3);
  ellipse(x+8*b/3, y-8*h-h/4, r, 2*r/3);
  ellipse(x+7*b/3+r/3, y-8*h, 2*r/3, r);
  ellipse(x-2*b+b/3, y-9*h, r, 2*r/3); //top right
  ellipse(x-2*b, y-9*h-h/5, 2*r/3, r);
  ellipse(x-2*b-r/2, y-9*h+h/5, r, 2*r/3);
  ellipse(x-2*b, y-8*h+h/4, r, 2*r/3);
  ellipse(x-2*b+b/5, y-7*h-h/3, 2*r/3, r);
  ellipse(x-2*b-b/6, y-7*h-h/3, r, 2*r/3);
  ellipse(x-2*b+b/4, y-8*h, 2*r/3, r);
  ellipse(x, y-8*h-h/4, 3*r/2, r);
  ellipse(x-2*b/5, y-8*h-h/3, 2*r/3, r);
  ellipse(x-b/2, y-9*h-h/5, 2*r/3, r);
  ellipse(x-b/3, y-9*h+h/5, r, 2*r/3);
  ellipse(x-4*b/5, y-9*h+h/5, r, 2*r/3);
  ellipse(x-b-b/4, y-9*h, r, 3*r/2);
  ellipse(x-b/2, y-7*h, r, 3*r/2);
  ellipse(x-4*b/5, y-7*h-h/3, 2*r/3, r);
  ellipse(x-5*b/4, y-7*h-h/4, 3*r/2, r);
  //stem
  stroke(157, 64, 14);
  fill(157, 64, 14);
  quad(x, y, x+5*b/4, y, x+4*b/3, y-h, x+b/3, y-4*h/3);
  quad(x+b/3, y-4*h/3, x+4*b/3, y-h, x+b, y-5*h/2, x, y-2*h);
  quad(x+b, y-5*h/2, x, y-2*h, x-b, y-2*h, x-4*b/3, y-9*h/4); //pole
  quad(x+b, y-5*h/2, x, y-2*h, x+b/4, y-3*h, x+5*b/4, y-7*h/2);
  quad(x+b/4, y-3*h, x+5*b/4, y-7*h/2, x+4*b/5, y-5*h, x, y-4*h-h/2);
  quad(x+b/2, y-5*h, x-b-b/4, y-5*h, x-b-b/2, y-5*h-h/2, x-b, y-5*h-h/4); //pole
  quad(x-b, y-5*h-h/4, x+b/2, y-5*h, x+b/2, y-5*h-h/4, x-b, y-5*h-h/4); //pole
  quad(x, y-4*h-h/2, x+4*b/5, y-5*h, x+2*b/3, y-6*h-h/4, x, y-6*h);
  quad(x, y-6*h, x+2*b/3, y-6*h-h/4, x+b, y-7*h-h/2, x+b/5, y-7*h);
  quad(x+b/5, y-7*h, x+b, y-7*h-h/2, x-b/2, y-8*h, x-b, y-8*h+h/5);
  quad(x-b, y-8*h+h/5, x-b/2, y-8*h, x-2*b+b/4, y-9*h+h/5, x-2*b, y-9*h);
  quad(x+b/5, y-7*h, x+b, y-7*h-h/2, x+3*b, y-9*h+h/4, x+b/2, y-8*h);
  //branch
  quad(x+b, y-4*h, x+2*b, y-5*h, x+3*b/2, y-5*h+h/4, x+b, y-4*h-h/4);
  triangle(x-2*b, y-8*h+h/2, x-b, y-8*h+h/5, x-b, y-8*h);
  triangle(x-b, y-8*h+h/5, x-2*b/3, y-8*h, x-b/2, y-9*h);
  triangle(x+2*b, y-9*h, x+2*b-b/4, y-8*h-h/3, x+3*b/2, y-8*h-h/4);
  //bird
  noStroke();
  fill(62, 30, 12);
  arc(x+b, y-8*h-h/2, 3*r, 3*r, 0, PI);
}
void Crate(int x, int y, int l, int r) {
  fill(106);
  stroke(0);
  strokeWeight(3);
  rect(x, y, 2*r, 2*l);
  quad(x, y, x-r, y+l, x+3*r, y+l, x+2*r, y);
}

void Pole(int l, int r) {
  fill(62, 30, 12);
  noStroke();
  quad(0, height/2+3*r, 0, height/2+4*r, l/2+2*r, height/2, l/2+r, height/2);
  rect(0, height/2, l, r);
  fill(15, 165, 58);
  rect(0, height-50, width, 50);
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น