2015年5月25日 星期一

week14


PImage imgCar;
float angle=0, dX=0, dY=0, vel=1;
void setup(){
  size(800,600, P3D);
  imgCar = loadImage("car.png");
}
void draw(){
  background(255);
  for(int i=-1;i<=8;i++){
    for(int j=-1;j<=6;j++){
      rect(i*100+dX%100,j*100+dY%100, 100,100);
    }
  }
  pushMatrix();
    translate(width/2, height/2);
    rotateZ(angle/180);
    image(imgCar, -100, -50, 200, 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.02;
  if(keyCode==DOWN) vel*=0.98;
  println("Vel:"+vel);
}

沒有留言:

張貼留言