2014年10月20日 星期一

Week06-期中作品

期中作品

            殺螞蟻遊戲

程式Demo↓






int antx=0, anty=0, anty1=0, anty2=0;
int score=0;
int lasttime=60;
PImage imgBG, imgHANT, imgUP, imgSTOP, imgSTART, ant;
void setup(){
  size(380,600);
  ant = loadImage("ant.png");
  imgHANT = loadImage("hant.png");
  imgBG = loadImage("BG.png");
  imgBG.resize(380, 600);
  imgUP = loadImage("up.png");
  imgSTOP = loadImage("stop.png");
  imgSTOP.resize(50, 50);
  imageMode(CENTER);
}
void draw(){
  background(imgBG);
  image(imgHANT, mouseX, mouseY, 120, 60);
  image(imgUP, 190, 20);
  image(imgSTOP, 190, 20);

  anty-=3;
  image(ant,antx+300,anty+600,80,80);
  if(anty+600<0)
  {
    score-=5;
    anty=0;
  }
  anty1-=2;
  image(ant,antx+200,anty1+500,80,80);
  if(anty1+500<0)
  {
    score-=5;
    anty1=0;
  }
  anty2-=3;
  image(ant,antx+100,anty2+700,80,80);
  if(anty2+700<0)
  {
    score-=5;
    anty2=0;
  }
  world();
}
void mousePressed(){
  if (mouseX > antx+300 && mouseX< antx+400 && mouseY<anty+700 && mouseY>anty+600)
   {
     anty=600;
     score+=5;
   }

  if (mouseX > antx+200 && mouseX< antx+300 && mouseY<anty1+600 && mouseY>anty1+500)
   {
   anty1=500;
   score+=5;
   }
  if (mouseX > antx+100 && mouseX< antx+200 && mouseY<anty2+800 && mouseY>anty2+700)
   {
   anty2=700;
   score+=5;
   }
}
void world()
  {
     textFont(createFont("Georgia", 30));
      fill(255);
  text("score:"+score, 25, 30);

  textFont(createFont("Georgia", 30));
      fill(255);
  text("Time:"+lasttime, 250, 30);
  lasttime=60-millis()/1000;

      if(lasttime==0)
      {
      stop();
      textFont(createFont("Georgia", 40));
      background(#FAC17C);
      fill(255,255,255);
      text("Game Over",80,200);
      text("Your score:"+score,40,250);
   
      }

  }

沒有留言:

張貼留言