2015年6月29日 星期一

期末


貓咪冒險記



============================================================
下列為程式碼
PImage imgCat;
PImage q5_R;
PImage a1,a2,a3,a5;

int imgCatX = 100;
int imgCatY = 100;
int imgCatMove = 10;

int score=100;
//int countDown=5*30;

float angle=0,dX=0,dY=0,vel=1;

//  6/15
import ddf.minim.*;   
Minim minim;
AudioPlayer kk;
int countDown=60*30;

int ff[] = new int[1000];
float runX[] = new float[1000];
float runY[] = new float[1000];
float positionX=2000;
float positionY=2000;

void setup(){
  size(600,700,P3D);
  imgCat=loadImage("cat.png");
  imgCat.resize(100, 120);

  a1=loadImage("a1.png");
  a1.resize(50, 50);

  a2=loadImage("a2.png");
  a2.resize(50, 50);

  a3=loadImage("a3.png");
  a3.resize(50, 50);

  a5=loadImage("a5.PNG");
  a5.resize(100, 100);

  imageMode(CENTER);

  minim = new Minim(this);
  kk= minim.loadFile("Kenji Wu.mp3");

  runX[0]=100;
  runY[0]=-50;

  kk.rewind();
  kk.play();

  for (int i=1; i<100; i++)
  {
    runX[i] = int(random(50, 450));
  }
  for (int i=1; i<100; i++)
  {
    runY[i] = -10 * int(random(1, 1500));
  }
  for (int i=0; i<100; i++)
  {
    ff[i] = int(random(1, 9));
  }

}
void draw(){
  background(0);
    countDown--;
    down();
    
   /* for(int i=-1;i<=8;i++){
   for(int j=-1;j<=8;j++){
   rect(i*100+dX%100,j*100+dY%100,100,100);
   }
    } */
    
    pushMatrix();
      translate(width/2,height/2);
      rotateZ(angle);
      image(imgCat,imgCatX,imgCatY);
    // rect(0,0,100,100);
    popMatrix();
   dX-=vel*cos(angle);
   dY-=vel*sin(angle);
   
if(keyPressed == true && key == 'w' || keyPressed == true && key == 'W'){
imgCatY -= imgCatMove;
}
if(keyPressed == true && key == 's' || keyPressed == true && key == 'S'){
imgCatY += imgCatMove;
}
if(keyPressed == true && key == 'd' || keyPressed == true && key == 'D'){
imgCatX += imgCatMove;
}
if(keyPressed == true && key == 'a' || keyPressed == true && key == 'A'){
imgCatX -= imgCatMove;
}
  textSize(40);
  fill(255,0,0);
  text("Time:",350,40);
  
  textSize(40);
  fill(255, 0, 0);
  text(countDown/30,470,40);
  
  textSize(40);
  fill(0, 0, 255);
  text("Score:",10,40);
    
  textSize(40);
  fill(0, 0, 250);
  text(score,140,40);

  if(countDown==0)
  {   
     background(0, 0, 0);
     textSize(50);
     fill(250, 150, 100);
     text("oh oh Time's up:",135,160);
     text("Your score is:",135,210);
     textSize(100);
     if(score>=1000)
     {
       text(score, 525/4,450);
     }
     else
     text(score, 525/3,450);
     noLoop();
  }

}


void mouseMoved(){
  int x=mouseX-pmouseX;
  int y=mouseY-pmouseY;
//  if(x>0) angle+=1/40.0;
 // if(x<0) angle-=1/40.0;
  
}
void keyPressed(){
  if(key=='w') imgCatX++;
  if(key=='s') imgCatX--;
  if(key=='d') imgCatY++;
  if(key=='a') imgCatY--;
  
 // if(key=='l') angle++;
 // if(key=='r') angle--;
  if(keyCode==UP) vel*=1.1;
  if(keyCode==DOWN) vel*=0.9;
  println("vel:"+vel);

  }
  
  void down()
{
  for (int i=0; i<100; i++)
  {
    if (ff[i]==1)
    {
      image(a1, runX[i],runY[i]+=5, 50, 50);
      if ((runX[i] >= positionX-80 && runX[i] <= positionX+80) && (runY[i] >= positionY-50 && runY[i] <= positionY+50))
      {
        runX[i]+=1000;
        runY[i]+=1000;
        score+=10;
      }
    }
    if (ff[i]==2)
    {
      image(a2, runX[i], runY[i]+=5, 70, 70);
      if ((runX[i] >= positionX-80 && runX[i] <= positionX+80) && (runY[i] >= positionY-50 && runY[i] <= positionY+50))
      {
        runX[i]+=1000;
        runY[i]+=1000;
        score+=20;
      }
    }
        if (ff[i]==3)
    {
      image(a3, runX[i], runY[i]+=5, 50, 50);
      if ((runX[i] >= positionX-80 && runX[i] <= positionX+80) && (runY[i] >= positionY-50 && runY[i] <= positionY+50))
      {
        runX[i]+=1000;
        runY[i]+=1000;
        score+=30;
      }
    }
        if (ff[i]==4)
    {
      image(a5, runX[i], runY[i]+=5, 60, 60);
      if ((runX[i] >= positionX-80 && runX[i] <= positionX+80) && (runY[i] >= positionY-50 && runY[i] <= positionY+50))
      {
        runX[i]+=1000;
        runY[i]+=1000;
        score+=50;
      }
    }
    
  }
}


沒有留言:

張貼留言