2017年11月6日 星期一

第八週

WEEK8  課堂der筆記筆記


作業
1.
程式碼:
void setup(){
  size(850,500);
}
int gameover=0;
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];


int user2J=3,user2I=5;
float user2X,user2Y;

void draw(){
  background(#80BF47);
  noStroke();
  for(int i=0;i<10;i++){
    for(int j=0;j<17;j++){
      if((j-i)%2 ==0) fill(#AFE380);
      else fill(#80BF47);
      rect(j*50,i*50,50,50);
    }
  }
  for(int i=0 ; i<10 ; i+=3){
    for(int j=0 ; j<17 ; j+=4)
    {
      fill(#AA8215);
      rect(j*50,i*50,50,50);
    }
  }

  fill(255,0,0);  ellipse(userJ*50+25,userI*50+25,50,50);  // User
  fill(0,0,255);  ellipse(user2J*50+25,user2I*50+25,50,50);  // User2
  for(int i=0; i<waterN; i++){
    if(waterT[i]>0){
    fill(#9EE7F5);  ellipse(waterJ[i]*50+25,waterI[i]*50+25,30,30);
    waterT[i]--;
    if(waterT[i]==0)  waterT[i]=-60;
    }
    
    if(gameover==1)   background(255,0,0);
    if(gameover==2)   background(0,0,255);
    
    if(waterT[i]<0){
      for(int k=-waterS[i]+3;k<=waterS[i]-3;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);
        if(dist(waterJ[i]+k,waterI[i], userJ,userI)==0)  gameover=1;
        if(dist(waterJ[i],waterI[i]+k, userJ,userI)==0)  gameover=1;
        if(dist(waterJ[i]+k,waterI[i], user2J,user2I)==0)  gameover=2;
        if(dist(waterJ[i],waterI[i]+k, user2J,user2I)==0)  gameover=2;
      }
      waterT[i]++;
    }
  }
  
}

void keyPressed(){
  if(keyCode==LEFT) userJ--;
  if(keyCode==RIGHT) userJ++;
  if(keyCode==UP) userI--;
  if(keyCode==DOWN) userI++;
  if(key=='0'){
    waterI[waterN]=userI;  waterJ[waterN]=userJ;
    waterS[waterN]=5;  waterT[waterN]=120;
    waterN++;
  }
  
  if(keyCode=='A') user2J--;
  if(keyCode=='D') user2J++;
  if(keyCode=='W') user2I--;
  if(keyCode=='S') user2I++;
  if(key==' '){
    waterI[waterN]=user2I;  waterJ[waterN]=user2J;
    waterS[waterN]=5;  waterT[waterN]=120;
    waterN++;
  }
}




154654351321321352416546546541354324


void setup(){
  size(850,500);
}
int gameover=0;
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];
int map[][]={{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
             {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
             {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
             {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
             {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
             {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
             {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
             {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
             {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
             {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};

int user2J=3,user2I=5;
float user2X,user2Y;

void draw(){
  background(#80BF47);
  noStroke();
  for(int i=0;i<10;i++){
    for(int j=0;j<17;j++){
      if((j-i)%2 ==0) fill(#AFE380);
      else fill(#80BF47);
      rect(j*50,i*50,50,50);
      if(map[i][j]==1) fill(#7E610F);
      rect(j*50,i*50,50,50);
    }
  }

  fill(255,0,0);  ellipse(userJ*50+25,userI*50+25,50,50);  // User
  fill(0,0,255);  ellipse(user2J*50+25,user2I*50+25,50,50);  // User2
  for(int i=0; i<waterN; i++){
    if(waterT[i]>0){
    fill(#9EE7F5);  ellipse(waterJ[i]*50+25,waterI[i]*50+25,30,30);
    waterT[i]--;
    if(waterT[i]==0)  waterT[i]=-60;
    }
    
    if(gameover==1)   background(255,0,0);
    if(gameover==2)   background(0,0,255);
    
    if(waterT[i]<0){
      for(int k=-waterS[i]+3;k<=waterS[i]-3;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);
        if(dist(waterJ[i]+k,waterI[i], userJ,userI)==0)  gameover=1;
        if(dist(waterJ[i],waterI[i]+k, userJ,userI)==0)  gameover=1;
        if(dist(waterJ[i]+k,waterI[i], user2J,user2I)==0)  gameover=2;
        if(dist(waterJ[i],waterI[i]+k, user2J,user2I)==0)  gameover=2;
      }
      waterT[i]++;
    }
  }
  
}

void keyPressed(){
  if(keyCode==LEFT && map[userI][userJ-1]==0) userJ--;
  if(keyCode==RIGHT && map[userI][userJ+1]==0) userJ++;
  if(keyCode==UP && map[userI-1][userJ]==0) userI--;
  if(keyCode==DOWN && map[userI+1][userJ]==0) userI++;
  if(key=='0'){
    waterI[waterN]=userI;  waterJ[waterN]=userJ;
    waterS[waterN]=5;  waterT[waterN]=120;
    waterN++;
  }
  
  if(keyCode=='A') user2J--;
  if(keyCode=='D') user2J++;
  if(keyCode=='W') user2I--;
  if(keyCode=='S') user2I++;
  if(key==' '){
    waterI[waterN]=user2I;  waterJ[waterN]=user2J;
    waterS[waterN]=5;  waterT[waterN]=120;
    waterN++;
  }
}




-----------------------------------------------------------------------------------------------
import ddf.minim.*;
Minim minim;
AudioPlayer player;
void setup(){
  size(850,500);
  wall=loadImage("1.png");
  wall2=loadImage("2.png");
  wall3=loadImage("3.png");
  play1=loadImage("play1.png");
  play2=loadImage("play2.png");
  water=loadImage("water1.png");
  minim=new Minim(this);
  player = minim.loadFile("music1.mp3",2048);
  player.play();
  
  /*sound=new SoundFile(this,"music1.mp3");
  sound.play();
  sound.loop();*/
}

PImage wall,wall2,wall3;
PImage play1;
PImage play2;
PImage water;
int gameover=0;
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];
int map[][]={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             {0,2,0,2,0,0,0,0,0,0,0,0,3,0,3,0,3},
             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             {0,2,0,2,0,0,0,0,0,0,0,0,3,0,3,0,3},
             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             {1,0,1,0,1,0,0,0,0,0,0,0,2,0,2,0,2},
             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             {1,0,1,0,1,0,0,0,0,0,0,0,2,0,2,0,2},
             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             {1,0,1,0,1,0,0,0,0,0,0,0,2,0,2,0,2}};

int user2J=3,user2I=5;
float user2X,user2Y;

void draw(){
  background(#80BF47);
  noStroke();
  for(int i=0;i<10;i++){
    for(int j=0;j<17;j++){
      if((j-i)%2 ==0) fill(#AFE380);
      else fill(#80BF47);
      rect(j*50,i*50,50,50);
      if(map[i][j]==1) 
      image(wall,j*50,i*50,50,50);
      if(map[i][j]==2) 
      image(wall2,j*50,i*50,50,50);
      if(map[i][j]==3) 
      image(wall3,j*50,i*50,50,50);
      /*fill(#7E610F);
      rect(j*50,i*50,50,50);*/
    }
  }
  
  image(play1,userJ*50-10,userI*50-10,70,70);
  image(play2,user2J*50-25,user2I*50-25,90,90);

 /* fill(255,0,0);  ellipse(userJ*50+25,userI*50+25,50,50);  // User
  fill(0,0,255);  ellipse(user2J*50+25,user2I*50+25,50,50);  // User2*/
  for(int i=0; i<waterN; i++){
    if(waterT[i]>0){
      
      image(water,waterJ[i]*50-25,waterI[i]*50-25,100,100);
      /*fill(#9EE7F5);  ellipse(waterJ[i]*50+25,waterI[i]*50+25,30,30);*/
      waterT[i]--;
      if(waterT[i]==0)  waterT[i]=-60;
    }
    
    if(gameover==1)   background(255,0,0);
    if(gameover==2)   background(0,0,255);
    
    if(waterT[i]<0){
      for(int k=-waterS[i]+3;k<=waterS[i]-3;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);
        if(dist(waterJ[i]+k,waterI[i], userJ,userI)==0)  gameover=1;
        if(dist(waterJ[i],waterI[i]+k, userJ,userI)==0)  gameover=1;
        if(dist(waterJ[i]+k,waterI[i], user2J,user2I)==0)  gameover=2;
        if(dist(waterJ[i],waterI[i]+k, user2J,user2I)==0)  gameover=2;
      }
      waterT[i]++;
    }
  }
  
}

void keyPressed(){
  if(keyCode==LEFT && map[userI][userJ-1]==0) userJ--;
  if(keyCode==RIGHT && map[userI][userJ+1]==0) userJ++;
  if(keyCode==UP && map[userI-1][userJ]==0) userI--;
  if(keyCode==DOWN && map[userI+1][userJ]==0) userI++;
  if(key=='0'){
    waterI[waterN]=userI;  waterJ[waterN]=userJ;
    waterS[waterN]=5;  waterT[waterN]=120;
    waterN++;
  }
  
  if(keyCode=='A'&& map[user2I][user2J-1]==0) user2J--;
  if(keyCode=='D'&& map[user2I][user2J+1]==0) user2J++;
  if(keyCode=='W'&& map[user2I-1][user2J]==0) user2I--;
  if(keyCode=='S'&& map[user2I+1][user2J]==0) user2I++;
  if(key==' '){
    waterI[waterN]=user2I;  waterJ[waterN]=user2J;
    waterS[waterN]=5;  waterT[waterN]=120;
    waterN++;
  }

}


-----------------------------------------------------------------------------------------------

import ddf.minim.*;
Minim minim;
AudioPlayer player;
void setup(){
  size(850,500);
  wall=loadImage("1.png");
  wall2=loadImage("2.png");
  wall3=loadImage("3.png");
  play1=loadImage("play1.png");
  play2=loadImage("play2.png");
  water=loadImage("water1.png");
  minim=new Minim(this);
  player = minim.loadFile("music1.mp3",2048);
  player.play();

  /*sound=new SoundFile(this,"music1.mp3");
  sound.play();
  sound.loop();*/
}
PImage wall,wall2,wall3;
PImage play1;
PImage play2;
PImage water;
int stage=0;
//int gameover=0;
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];
int map[][]={{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2},
             {1,2,0,2,0,0,0,3,2,0,0,0,3,0,2,0,1},
             {2,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,2},
             {1,2,0,2,0,0,0,3,3,0,0,0,3,0,3,0,1},
             {2,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,2},
             {1,0,1,0,1,0,0,3,3,0,0,0,2,0,2,0,1},
             {2,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,2},
             {1,0,2,0,1,0,0,3,2,0,0,0,2,0,2,0,1},
             {2,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,2},
             {1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1}};

int user2J=3,user2I=5;
float user2X,user2Y;

void draw(){
  background(#80BF47);
  noStroke();
  for(int i=0;i<10;i++){
    for(int j=0;j<17;j++){
      if((j-i)%2 ==0) fill(#AFE380);
      else fill(#80BF47);
      rect(j*50,i*50,50,50);
      if(map[i][j]==1)
      image(wall,j*50,i*50,50,50);
      if(map[i][j]==2)
      image(wall2,j*50,i*50,50,50);
      if(map[i][j]==3)
      image(wall3,j*50,i*50,50,50);
      /*fill(#7E610F);
      rect(j*50,i*50,50,50);*/
    }
  }

  image(play1,userJ*50-10,userI*50-10,70,70);
  image(play2,user2J*50-25,user2I*50-25,90,90);

 /* fill(255,0,0);  ellipse(userJ*50+25,userI*50+25,50,50);  // User
  fill(0,0,255);  ellipse(user2J*50+25,user2I*50+25,50,50);  // User2*/
  for(int i=0; i<waterN; i++){
    if(waterT[i]>0){
     
      image(water,waterJ[i]*50-25,waterI[i]*50-25,100,100);
      /*fill(#9EE7F5);  ellipse(waterJ[i]*50+25,waterI[i]*50+25,30,30);*/
      waterT[i]--;
      if(waterT[i]==0)  waterT[i]=-60;
    }
   
    //if(gameover==1)   background(255,0,0);
    //if(gameover==2)   background(0,0,255);
    if(stage==1){
      background(0,0,0);
      fill(#FF2121);  textSize(80);
      text("Red Game Over",130,200);
    }
    if(stage==2){
      background(0,0,0);
      fill(#212AFF);  textSize(80);
      text("Blue Game Over",130,200);
    }
    if(waterT[i]<0){
       for(int k=0;k<2;k++){  
         
          if(waterI[i]>=0 && waterI[i]<=9 && waterJ[i]+k>=0 && waterJ[i]+k<=16 && (map[waterI[i]][waterJ[i]+k]==2 || map[waterI[i]][waterJ[i]+k]==1)) break;
          fill(255);  rect((waterJ[i]+k)*50,(waterI[i])*50,50,50);
          if(dist(waterJ[i]+k,waterI[i], userJ,userI)==0)  stage=1;
          if(dist(waterJ[i],waterI[i]+k, userJ,userI)==0)  stage=1;
          if(dist(waterJ[i]-k,waterI[i], user2J,user2I)==0)  stage=2;
          if(dist(waterJ[i],waterI[i]-k, user2J,user2I)==0)  stage=2;
          if(waterI[i]>=0 && waterI[i]<=9 && waterJ[i]+k>=0 && waterJ[i]+k<=16 && map[waterI[i]][waterJ[i]+k]==3)
            map[waterI[i]][waterJ[i]+k]=0;
       }
       for(int k=0;k<2;k++){  
        
         if(waterI[i]+k>=0 && waterI[i]+k<=9 && waterJ[i]>=0 && waterJ[i]<=16 &&  (map[waterI[i]+k][waterJ[i]]==2 || map[waterI[i]+k][waterJ[i]]==1)) break;
         fill(255);  rect((waterJ[i])*50,(waterI[i]+k)*50,50,50);
          if(dist(waterJ[i]+k,waterI[i], userJ,userI)==0)  stage=1;
          if(dist(waterJ[i],waterI[i]+k, userJ,userI)==0)  stage=1;
          if(dist(waterJ[i]-k,waterI[i], user2J,user2I)==0)  stage=2;
          if(dist(waterJ[i],waterI[i]-k, user2J,user2I)==0)  stage=2;
          if(waterI[i]+k>=0 && waterI[i]+k<=9 && waterJ[i]>=0 && waterJ[i]<=16 &&  map[waterI[i]+k][waterJ[i]]==3)
            map[waterI[i]+k][waterJ[i]]=0;
         
       }
       for(int k=0;k<2;k++){  
         
          if(waterI[i]>=0 && waterI[i]<=9 && waterJ[i]-k>=0 && waterJ[i]-k<=16 && (map[waterI[i]][waterJ[i]-k]==2 || map[waterI[i]][waterJ[i]-k]==1)) break;
          fill(255);  rect((waterJ[i]-k)*50,(waterI[i])*50,50,50);
          if(dist(waterJ[i]+k,waterI[i], userJ,userI)==0)  stage=1;
          if(dist(waterJ[i],waterI[i]+k, userJ,userI)==0)  stage=1;
          if(dist(waterJ[i]+k,waterI[i], user2J,user2I)==0)  stage=2;
          if(dist(waterJ[i],waterI[i]+k, user2J,user2I)==0)  stage=2;
          if(waterI[i]>=0 && waterI[i]<=9 && waterJ[i]-k>=0 && waterJ[i]-k<=16 && map[waterI[i]][waterJ[i]-k]==3)
          map[waterI[i]][waterJ[i]-k]=0;
       }
       for(int k=0;k<2;k++){  
         
          if(waterI[i]-k>=0 && waterI[i]-k<=9 && waterJ[i]>=0 && waterJ[i]<=16 && (map[waterI[i]-k][waterJ[i]]==2 || map[waterI[i]-k][waterJ[i]]==1)) break;
          fill(255);  rect((waterJ[i])*50,(waterI[i]-k)*50,50,50);
          if(dist(waterJ[i]+k,waterI[i], userJ,userI)==0)  stage=1;
          if(dist(waterJ[i],waterI[i]+k, userJ,userI)==0)  stage=1;
          if(dist(waterJ[i]+k,waterI[i], user2J,user2I)==0)  stage=2;
          if(dist(waterJ[i],waterI[i]+k, user2J,user2I)==0)  stage=2;      
          if(waterI[i]-k>=0 && waterI[i]-k<=9 && waterJ[i]>=0 && waterJ[i]<=16 && map[waterI[i]-k][waterJ[i]]==3)
            map[waterI[i]-k][waterJ[i]]=0;
       }
         waterT[i]++; 

    }
  }
}

void keyPressed(){
  if(keyCode==LEFT && map[userI][userJ-1]==0) userJ--;
  if(keyCode==RIGHT && map[userI][userJ+1]==0) userJ++;
  if(keyCode==UP && map[userI-1][userJ]==0) userI--;
  if(keyCode==DOWN && map[userI+1][userJ]==0) userI++;
  if(key=='0'){
    waterI[waterN]=userI;  waterJ[waterN]=userJ;
    waterS[waterN]=5;  waterT[waterN]=120;
    waterN++;
  }

  if(keyCode=='A'&& map[user2I][user2J-1]==0) user2J--;
  if(keyCode=='D'&& map[user2I][user2J+1]==0) user2J++;
  if(keyCode=='W'&& map[user2I-1][user2J]==0) user2I--;
  if(keyCode=='S'&& map[user2I+1][user2J]==0) user2I++;
  if(key==' '){
    waterI[waterN]=user2I;  waterJ[waterN]=user2J;
    waterS[waterN]=5;  waterT[waterN]=120;
    waterN++;
  }
}
void mousePressed(){
  if(stage==1 || stage==2)  stage=0;

}

沒有留言:

張貼留言