2015年6月15日 星期一

week16

<貓咪可旋轉>


PImage imgCat;
PImage q5_R;
float angle=0,dX=0,dY=0,vel=1;
void setup(){
  size(600,700,P3D);
  imgCat=loadImage("cat.png");
// q5_R=loadImage("q5_R.png");
// image(q5_R,0,0);
}
void draw(){
  background(255);
    //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);
 //   }
    //    }
        q5_R=loadImage("q5_R.png");
         image(q5_R,0,0);
  pushMatrix();
    translate(width/2,height/2);
    rotateZ(angle);
    image(imgCat,-100,-50,200,100);
   // rect(0,0,100,100);
   popMatrix();
   dX-=vel*cos(angle);
   dY-=vel*sin(angle);

}
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=='l') angle++;
  if(key=='r') angle--;
  if(keyCode==UP) vel*=1.1;
  if(keyCode==DOWN) vel*=0.9;
  println("vel:"+vel);

  }

<貓咪可上下左右移動+音效>

PImage imgCat;
PImage q5_R;
PImage a1,a2,a3,a5;

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

float angle=0,dX=0,dY=0,vel=1;
void setup(){
  size(600,700,P3D);
  imgCat=loadImage("cat.png");
  a1=loadImage("a1.png");
  a2=loadImage("a2.png");
  a3=loadImage("a3.png");
  a5=loadImage("a5.PNG");
  

}
void draw(){
  background(255);
    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);
   }
    } 
        q5_R=loadImage("q5_R.png");
         image(q5_R,0,0);
  pushMatrix();
    translate(width/2,height/2);
    rotateZ(angle);
    image(imgCat,imgCatX,imgCatY);
    image(a1,200,200);  
    
   // 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;
}
   

}
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);

  }



沒有留言:

張貼留言