賽車遊戲
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);
image(imgCar, -100,-100,200,200);
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;
}
沒有留言:
張貼留言