2018年10月25日 星期四

Week07_陳示珮

Week07


做出遊戲血條

















(1) 按滑鼠會減少血量

程式碼 :

int life=10;
boolean gameOver=false;
void setup(){
 size(500,500);
}
void draw(){
 background(0,0,205);
 fill(255);rect(50,50,100,20);
 fill(255,0,0);rect(50,50,life*10,20);
 if(gameOver){
   textSize(40);
   text("Game Over",150,150);
 }
}
void mousePressed(){
 life--;
 if(life<=0)gameOver=true;
}

















(2) 當血量用完了會跑出game over


切換畫面+倒數計時

















(1) 開始畫面,按下1即可開始

程式碼 :

int state=0;
int time=0;
void setup(){
 size(800,600);
}
void draw(){
 if(state==0){
  open();
  if(key=='1'){state=1;time=5*60;}//60=1秒 5*60=5秒
 }
 else if(state==1){
   if(key=='2')state=2;
   play();
 }
 else if(state==2){
   end();
 }
}
void end(){
 background(0);
 fill(255,0,0);text("game over",100,100);
}
void play(){
 background(0,255,0);
 fill(255,0,0);text("playing press 2 end",10,100);
 text("Time"+time,10,200);
 time--;
 if(time<=0)state=2;
}
void open(){
 background(0);
 fill(0,0,255);
 textSize(30);text("open press 1 play",10,100);
}


















(2)開始倒數計時,倒數5秒結束或按2會跑到結束畫面

















(3)結束畫面

沒有留言:

張貼留言