2018年10月25日 星期四

week07

製作血條

int life=10;///一格血量為10
boolean gameOver=false;
void setup(){
  size(500,500);
}
void draw(){
  background(0,0,200);
  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;
}
























畫面切換

int state=0;
int remainTime=0;
void setup(){
  size(800,600);
}
void draw(){
  if(state==0){
    drawOP();
    if(key=='1'){state=1;remainTime=5*60;}///1/60秒,所以要乘60
  }
  else if(state==1){ 
    drawPlayer();
  }
  else if(state==2){
    drawED();
  }
}
void drawED(){
  background(0);
  fill(#F0D90C);text("Game Over",100,100);
}
void drawPlayer(){
  background(#F0D90C);
  fill(#120FF2);text("Playing... You can press 2 to End",10,100);
  text("remain:"+remainTime,10,200);
  remainTime--;
  if(remainTime<=0)state=2;
}
void drawOP(){
  background(0);
  fill(#F5DE07);
  textSize(30);text("Opening... You can press 1 to play",10,100);
}












 text("remain:"+(remainTime+59)/60,10,200);
///+59在除60能自動進位成1







沒有留言:

張貼留言