2018年10月11日 星期四

week5_劉沛潔

校園參訪在台北車站水源街

接雞蛋
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<100; i++){
    eggX[i]=random(100,700);
    eggY[i]=-random(2000);
    eggDie[i]=false;
  }
}
void draw(){
  background(255);
  rect(mouseX-50, mouseY-25, 100, 50);
  for(int i=0; i<100; i++){
    if(eggDie[i])continue;
    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;
    }
  }
}


加分數
int score=0;
void draw(){
  background(255);
  fill(255);rect(mouseX-50, mouseY-25, 100, 50);
  for(int i=0; i<100; i++){
    if(eggDie[i])continue;
    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;
      score+=100;
    }
  }
  fill(255, 0, 0);textSize(80);text("Score:"+score, 100, 100);
}


水果忍者


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("pie.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;
  }
  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;
  for(int i=1;i<10; i++){
    line(sword[i].x, sword[i].y, sword[i-1].x, sword[i-1].y);
  }
}

沒有留言:

張貼留言