成員:01160394溫庭豐 01160766吳逸凡
遊戲介紹及玩法:
這是一個賽車的小遊戲,可以透過鍵盤的上下左右來控制車子位置,這個遊戲就是控制車子來躲避其他的車子,隨著躲避車子的時間增加,分數也就會越來越高,然後只要碰到其他的車子就遊戲結束。
這是一個賽車的小遊戲,可以透過鍵盤的上下左右來控制車子位置,這個遊戲就是控制車子來躲避其他的車子,隨著躲避車子的時間增加,分數也就會越來越高,然後只要碰到其他的車子就遊戲結束。
程式碼:
PImage car[]=new PImage[4];
float carX[]={0,0,0,400},carY[]={0,0,0,300};
void setup(){
size(900,500);
for(int i=0;i<4;i++) car[i]=loadImage("car"+(i+1)+".png");
for(int i=0;i<3;i++){ carX[i]=int(random(7))*100+100; carY[i]=-random(400);}
}
int gameOver=0;
int score=0;
void draw(){
/*textSize(20);
fill(250, 160, 0);
text("Click to Start!", floor(900/3), floor(500/2));
*/
if(gameOver>0){
for(int i=0;i<3;i++){ carX[i]=int(random(7))*100+100; carY[i]=-random(400);}
fill(255,0,0,1); rect(0,0,900,500);gameOver--;
score=0;
textSize(100);
fill(255, 0, 0);
text("GameOver!!", floor(200), floor(200));
carX[3]=400;
carY[3]=300;
return;
}
background(254,235,156);
for(int i=1;i<=7;i++){
if(i%2==1) fill(77);
else fill(111);
rect(i*100,0,100,500);
textSize(15);
fill(255, 0, 0);
text("Score:"+score, floor(0), floor(100));
}
for(int i=0;i<3;i++) image(car[i],carX[i],carY[i],100,150);
image(car[3],carX[3],carY[3],100,150);
for(int i=0;i<3;i++){
carY[i]+=5;
if(carY[i]>500){carY[i]=-random(100); carX[i]=int(random(7))*100+100;}
if(carX[i]==carX[3] && abs(carY[i]-carY[3])<130) gameOver=300;
}
score+=3;
// if(frameCount%60==0)score+=1;
}
void keyPressed(){
if(keyCode==RIGHT &&carX[3]<700) carX[3]+=100;
if(keyCode==LEFT &&carX[3]>100) carX[3]-=100;
if(keyCode==UP && carY[3]>200) carY[3]-=100;
if(keyCode==DOWN && carY[3]<400)carY[3]+=100;
}
沒有留言:
張貼留言