2017年10月23日 星期一

week06 3D的互動筆記

一、製作爆爆王

1.製作地圖框格


void setup(){
  size(850,500);
}
void draw(){
  background(#92AD28);
  noStroke();
  for(int x=0;x<17;x++){
    for(int y=0;y<10;y++){
      if((x-y)%2==0) fill(#7E9819);
      else fill(#92AD28);
      rect(x*50,y*50,50,50);
    }
  }

2.製作玩家角色


void setup(){
  size(850,500);
}
int userJ=9, userI=5;
float userX,userY;
void draw(){
  background(#92AD28);
  noStroke();
  for(int x=0;x<17;x++){
    for(int y=0;y<10;y++){
      if((x-y)%2==0) fill(#7E9819);
      else fill(#92AD28);
      rect(x*50,y*50,50,50);
    }
  }
  fill(255,0,0); ellipse(userJ*50+25 , userI*50+25,50,50);
}
void keyPressed(){
  if(keyCode==LEFT) userJ--;
  if(keyCode==RIGHT) userJ++;
  if(keyCode==UP) userI--;
  if(keyCode==DOWN) userI++;
}

3.讓角色可以放水球炸彈


void setup(){
  size(850,500);
}
int userJ=9, userI=5;
float userX,userY;
int waterN=0;
int []waterJ = new int[100];
int []waterI = new int[100];
void draw(){
  background(#92AD28);
  noStroke();
  for(int x=0;x<17;x++){
    for(int y=0;y<10;y++){
      if((x-y)%2==0) fill(#7E9819);
      else fill(#92AD28);
      rect(x*50,y*50,50,50);
    }
  }
  fill(255,0,0); ellipse(userJ*50+25 , userI*50+25,50,50);
  for(int i=0; i<waterN; i++){
    fill(#93E1F7); ellipse(waterJ[i]*50+25 , waterI[i]*50+25 ,30,30);
  }
}
void keyPressed(){
  if(keyCode==LEFT) userJ--;
  if(keyCode==RIGHT) userJ++;
  if(keyCode==UP) userI--;
  if(keyCode==DOWN) userI++;
  if(keyCode==' '){
    waterI[waterN]=userI;
    waterJ[waterN]=userJ;
    waterN++;
  }
}

4.讓水球會爆炸


void setup(){
  size(850,500);
}
int userJ=9, userI=5;
float userX,userY;
int waterN=0;
int []waterJ = new int[100];
int []waterI = new int[100];
int []waterS = new int[100];
int []waterT = new int[100];
void draw(){
  background(#92AD28);
  noStroke();
  for(int x=0;x<17;x++){
    for(int y=0;y<10;y++){
      if((x-y)%2==0) fill(#7E9819);
      else fill(#92AD28);
      rect(x*50,y*50,50,50);
    }
  }
  fill(255,0,0); ellipse(userJ*50+25 , userI*50+25,50,50);
  for(int i=0; i<waterN; i++){
    if(waterT[i]>0){
      fill(#93E1F7); ellipse(waterJ[i]*50+25 , waterI[i]*50+25 ,30,30);
      waterT[i]--;
      if(waterT[i]==0) waterT[i]=-60;
    }
    if(waterT[i]<0){
      for(int k=-waterS[i];k<=waterS[i];k++){
        fill(255); rect((waterJ[i]+k)*50 , (waterI[i])*50,50,50);
        fill(255); rect((waterJ[i])*50 , (waterI[i]+k)*50,50,50);
      }
      waterT[i]++;
    }
  }
}
void keyPressed(){
  if(keyCode==LEFT) userJ--;
  if(keyCode==RIGHT) userJ++;
  if(keyCode==UP) userI--;
  if(keyCode==DOWN) userI++;
  if(keyCode==' '){
    waterI[waterN]=userI;
    waterJ[waterN]=userJ;
    waterS[waterN]=5; waterT[waterN]=120;
    waterN++;
  }
}

二、製作鱷魚咬咬

1.製作鱷魚


void setup(){
  size(500,500);
}
void draw(){
  background(255);
  fill(0,155,0); ellipse(250,250,300,300);
  for(int i=0;i<9;i++){
    fill(255); rect(110+i*30,200,30,30);
    if(110+i*30 < mouseX&&mouseX<110+i*30+30&& 200<mouseY&&mouseY<200+30){
      fill(0); rect(110+i*30,200,30,30);
    }
  }
  for(int i=0;i<9;i++){
    fill(255); rect(110+i*30,300,30,30);
    if(110+i*30 < mouseX&&mouseX<110+i*30+30&& 300<mouseY&&mouseY<300+30){
      fill(0); rect(110+i*30,300,30,30);
    }
  }
}


沒有留言:

張貼留言