2012年3月18日 星期日

Case Study 1


int ImageCount = 50;
int Score;
mosquito[] myMosquitos = new mosquito[ImageCount];
PImage mos;
PImage racket;
void setup()
{
  size(1200, 800);
  background(0);
  mos = loadImage("mosquito.png");
  racket = loadImage("racket.png");
  for(int i=0;i<ImageCount;i++)
  {
    mosquito aMosquito = new mosquito();
    aMosquito.X = (int)random(0,1100);
    aMosquito.Y = (int)random(0,700);
    myMosquitos[i] = aMosquito;
  }
  frameRate(8);
}
void draw()
{
 
  background(0);
  image(racket, mouseX, mouseY);
 
  for(int i=0;i<ImageCount;i++)
  {
     if(mousePressed && mouseButton==LEFT)
     {
       int CurrentXAndRacketTolarance = mouseX + 20;
       int CurrentYAndRacketTolarance = mouseY + 20;
          if(CurrentXAndRacketTolarance >= myMosquitos[i].X && CurrentXAndRacketTolarance <= myMosquitos[i].X + 88
          && CurrentYAndRacketTolarance+20 >= myMosquitos[i].Y && CurrentYAndRacketTolarance+20 <= myMosquitos[i].Y + 67 && myMosquitos[i].isAlive)
           { 
               myMosquitos[i].isAlive = false;
               Score++;
           }
     }
  }
 
  for(int i=0;i<ImageCount;i++)
  {
    if(myMosquitos[i].isAlive)
       image(mos, myMosquitos[i].X + (int)random(-10, 10) , myMosquitos[i].Y + (int)random(-10,10));  
  }
 
    PFont font;
    font = loadFont("Andalus-40.vlw");
    textFont(font, 40);
    fill(0, 102, 153);
    text("Anton Carlson says your score is: " + Score , 10, 35);
   
    if(Score==ImageCount)
    {
        PFont fontWin;
        fontWin = loadFont("Andalus-40.vlw");
        textFont(fontWin, 70);
        fill(0, 102, 153);
        text("You Win!!!" , 1200/2 - 150, 800/2 - 100);
    }
}

class mosquito
{
   public int X;
   public int Y;
   public boolean isAlive = true;
}

沒有留言:

張貼留言