1. Game Over顯示
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. 按'1' 開始遊戲,再來倒數計時,之後顯示Game Over
int state=0;
int remainTime=0;
void setup(){
size(800,600);
}
void draw(){
if(state==0){
drawOP();
if(key=='1'){state=1; remainTime=30*60; }
}else if(state==1){
drawPlayer();
}else if(state==2){
drawED();
}
}
void drawED(){
background(0);
fill(#05BAFA); text("Game Over", 100,100);
}
void drawPlayer(){
background(#C63C48);
fill(#FAE712); text("You can press 2 to End",10, 100);
text("remain: "+remainTime, 10,200);
remainTime--;
if(remainTime<=0) state=2;
}
void drawOP(){
background(0);
fill(#FA12C8);
textSize(30); text("You can press 1 to play", 10, 100);
}
3.




沒有留言:
張貼留言