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.

避免超出負值
void mousePressed(){
  if(life>0) life--;
  if(life<=0) gameOver=true;
}


倒數計時




倒數計時囉!

int state=0;//0:OP opening, 1: playing2:ED ending
int remainTime=0;
void setup(){
  size(800,600);
}
void draw(){
  if(state==0){
    drawOP();//開始畫面
    if(key=='1') {state=1; remainTime=5*60;}  
}else if(state==1){
  drawPlayer();//玩的畫面
}else if(state==2){
  drawED();//結束畫面
  }
}

void drawED(){
  background(0);
  fill(#DFF005); text("Game Over",100 ,100);
}
void drawPlayer(){
  background(#2514F2);
  fill(#F2EB14); 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(#FF24FC);
  textSize(30); text("Opening...You can press 1 to play",10,100);
}

顏色代碼可以從工具中的顏色選擇器去搜尋


沒有留言:

張貼留言