2012年3月18日 星期日

HW-6 (97473011)




I've learn how to use arrays and practice overall matter such as text, condition loop ect..
///////////////////////////////////////////////////////////////////////////////////////////////////

int num=50;
int score;
int[] x= new int[num];;
int[] y= new int[num];;
int[] b= new int[num];;
PImage img; PImage Kill; PImage C;

void setup()
{
 size(1000, 800);
 background(0);
 score=0; 
 textSize(40);
 img = loadImage("mosquito.jpg");
 C= loadImage("Racket.jpg");

 for(int i=0;i<50;i++) {
   b[i]=1;
   x[i]=int(random(1000));
   y[i]=int(random(800));
 }

 for(int i=0; i<50;i++)
   if(b[i]==1)
      image(img,x[i],y[i]);
 frameRate(20);
}

void draw()
{
 background(255);
  for ( int i=0; i<50;++i){
    if (mousePressed==true){
      if (mouseButton==LEFT){
        if (x[i]<=mouseX && x[i]>=mouseX-50 && y[i]<=mouseY && y[i]>=mouseY-50 && b[i]==1 && score<50){
          b[i]=0;
          score++;
        }
      }
    }
  }
 
  for (int i=0; i<50;i++)
  if(b[i]==1) image(img,x[i],y[i],55,55);

   if(score==50){
     background(255);
     fill(0);
    
     text("You Win!!",400,400);
    
}
fill(0);
text("Score:",630,50);
text(score,750,50);
image(C,mouseX-40,mouseY-20,85,85);
}

沒有留言:

張貼留言