2020年10月19日 星期一

WEEK06

 

先加入貼圖 等等加入滑鼠做一個小遊戲

int [][]A={{2,2,2,2},

           {0,1,1,1},

           {0,1,1,1},

           {2,2,2,2}};

PImage bird,pig;

void setup(){

  size(300,400);

  bird=loadImage("bird.png");

  pig =loadImage("pig.png");

}

void draw(){

  background(255);

  for(int i=0;i<4;i++)

  {

     for(int j=0;j<4;j++)

    {

      if(A[i][j]==1)image(bird,j*100,i*100,100,100);

      if(A[i][j]==2)image(pig,j*100,i*100,100,100);

    }

  }

}


                    加入滑鼠 點擊後圖片消失

int [][]A={{2,2,2,2},
           {0,1,1,1},
           {0,1,1,1},
           {2,2,2,2}};
PImage bird,pig;
void mousePressed()
{
  int i=int(mouseY/100);
  int j=int(mouseX/100);
  A[i][j]=0;
}
void setup(){
  size(300,400);
  bird=loadImage("bird.png");
  pig =loadImage("pig.png");
}
void draw(){
  background(255);
  for(int i=0;i<4;i++)
  {
     for(int j=0;j<4;j++)
    {
      if(A[i][j]==1)image(bird,j*100,i*100,100,100);
      if(A[i][j]==2)image(pig,j*100,i*100,100,100);
    }
  }
}


沒有留言:

張貼留言