2018年10月11日 星期四

Week05 徐如君

Week05

1.
讓雞蛋掉下去~
                  float[] eggX=new float[100];//使用陣列
float[] eggY=new float[100];
void setup(){
  size(800,600);
  for(int i=0;i<100;i++){
    eggX[i]=random(100,700);
    eggY[i]=-random(2000);
  }
}
void draw(){
  background(255);
  for(int i=0;i<100;i++){
    ellipse(eggX[i], eggY[i],80,100);
    eggY[i]+=5;
  }
}
2.
接雞蛋
float[] eggX=new float[100];
float[] eggY=new float[100];
                          boolean[] eggDie=new boolean[100];//使用boolean來讓盒子是否碰到雞蛋
void setup(){
  size(800,600);
  for(int i=0;i<100;i++){
    eggX[i]=random(100,700);
    eggY[i]=-random(2000);
               eggDie[i]=false;//一開始設為0
  }
}
void draw(){
  background(255);
  rect(mouseX-50, mouseY-25,100,50);
  for(int i=0;i<100;i++){//for all eggs
    if(eggDie[i])continue;//continue to for loop
    ellipse(eggX[i], eggY[i],80,100);
    eggY[i]+=5;
    if(eggY[i]>700) eggY[i]=-2000+600;
    if(dist(mouseX-50,mouseY-25,eggX[i],eggY[i])<50){
                        eggDie[i]=true;//touch the egg,the egg die //如果碰到,讓雞蛋消失
    }
  }
}
3.
計算分數(先貼圖檔)
PImage[] imgN=new PImage[10];
float[] eggX=new float[100];
float[] eggY=new float[100];
boolean[] eggDie=new boolean[100];
void setup(){
  size(800,600);
  for(int i=0;i<=9;i++) imgN[i]=loadImage(i+".jpg");

int score=0;
void draw(){
  background(255);
                                   fill(255);rect(mouseX-50, mouseY-25,100,50);//填顏色
  for(int i=0;i<100;i++){//for all eggs
    if(eggDie[i])continue;//continue to for loop
    ellipse(eggX[i], eggY[i],80,100);
    eggY[i]+=5;
    if(eggY[i]>700) eggY[i]=-2000+600;
    if(dist(mouseX,mouseY,eggX[i],eggY[i])<50){
    eggDie[i]=true;//touch the egg,the egg die
    score+=100;
    }
  }
             int now=score;//計算分數
  for(int i=0;i<7;i++){
    image(imgN[(now%10)],400-i*100, 100, 100, 150);
    now/=10;
   }
}

Fruit Ninja

1.
先把櫻桃讀出來
    PImage img;//讀圖檔
float cherryX=0, cherryY=700;//lower-left
float cherryVX=6,cherryVY=-40;//to right-top
void setup(){
  size(800,600);
  img=loadImage("cherry.png");
}
void draw(){
  background(255);
  image(img,cherryX,cherryY,100,150);
  cherryX +=cherryVX;
  cherryY +=cherryVY;
  cherryVY+=0.98;//gravity of earth
}
2.
畫刀出來囉!!
PImage img;
float cherryX=0, cherryY=700;//lower-left
float cherryVX=6,cherryVY=-40;//to right-top
void setup(){
  size(800,600);
  img=loadImage("cherry.png");
  for(int i=0;i<10;i++) sword[i]=new PVector();
}
PVector [] sword= new PVector[10];
void draw(){
  background(255);
  image(img,cherryX,cherryY,100,150);
  cherryX +=cherryVX;
  cherryY +=cherryVY;
  cherryVY+=0.98;//gravity of earth

 for(int i=9; i>0;i--){
   sword[i].x=sword[i-1].x; sword[i].y=sword[i-1].y;
 }
 sword[0].x=mouseX; sword[0].y=mouseY;//Update sword[0] to newest mouse
 for(int i=1;i<10;i++){
   line(sword[i].x, sword[i].y, sword[i-1].x, sword[i-1].y);
 }
}
3.
哇~好多水果
PImage []img=new PImage[8];
float []cherryX=new float[8];
float []cherryY=new float[8];
float []cherryVX=new float[8];
float []cherryVY=new float[8];

void cherryReborn(int i){
   cherryX[i]=random(800);
   cherryY[i]=700;
   cherryVX[i]=random(8)-4;
   cherryVY[i]=-40;
}
void setup(){
  size(800,600);
  for(int i=0;i<8;i++) img[i]=loadImage("cherry.png");
  for(int i=0;i<8;i++) cherryReborn(i);
  for(int i=0;i<10;i++) sword[i]=new PVector();
}
PVector [] sword= new PVector[10];
void draw(){
  background(255);
  for(int i=0;i<8;i++){
  image(img[i],cherryX[i],cherryY[i],100,150);
  cherryX[i] +=cherryVX[i];
  cherryY[i] +=cherryVY[i];
  cherryVY[i]+=0.98;//gravity of earth
 }
 for(int i=9; i>0;i--){
   sword[i].x=sword[i-1].x; sword[i].y=sword[i-1].y;
 }
 sword[0].x=mouseX; sword[0].y=mouseY;//Update sword[0] to newest mouse
 for(int i=1;i<10;i++){
   line(sword[i].x, sword[i].y, sword[i-1].x, sword[i-1].y);
 }

沒有留言:

張貼留言