程式碼:
int life=10;
boolean gameOver=false;
void setup(){
size(500,500);
}
void draw(){
background(0);
fill(255);rect(50,50,100,20);
fill(255,0,0);rect(50,50,life*10,20);
if(gameOver){
textSize(40);
text("GameOver",150,150);
}
}
void mousePressed(){
life--;
if(life<=0) gameOver=true;
}
程式碼:
PImage imgBG;
int remainTime=0;
int state=0;//0:OP opening, 1:playing, 2:ED end
void setup(){
size(600,600);
imgBG=loadImage("background.png");
}
void draw(){
if(state==0){
drawOP();
if(key=='1'){
state=1; remainTime=5*60;
}
}else if (state==1){
drawPlaying();
}else if(state==2){
drawED();
}
}
void drawOP(){
image(imgBG,0,0,width,height);
fill(255,255,0);
textSize(30); text("Press 1 To Play",180,300);
}
void drawPlaying(){
image(imgBG,0,0,width,height);
fill(255,255,0);
textSize(30); text("Press 2 To End",190,200);
text("remainTime: "+remainTime,180,300);
remainTime--;
if(remainTime<=0) state=2;
}
void drawED(){
image(imgBG,0,0,width,height);
fill(255,255,0);
textSize(30); text("GameOver",225,300);
}
程式碼:
PImage imgBG;
int remainTime=0;
int state=0;//0:OP opening, 1:playing, 2:ED end
void setup(){
size(600,600);
imgBG=loadImage("background.png");
}
void draw(){
if(state==0){
drawOP();
if(key=='1'){
state=1; remainTime=5*60;
}
}else if (state==1){
if(key=='2') state=2;
drawPlaying();
}else if(state==2){
drawED();
}
}
void drawOP(){
image(imgBG,0,0,width,height);
fill(255,255,0);
textSize(30); text("Press 1 To Play",180,300);
}
void drawPlaying(){
image(imgBG,0,0,width,height);
fill(255,255,0);
textSize(30); text("Press 2 To End",190,200);
text("remainTime: "+(remainTime+59)/60,180,300);
remainTime--;
if(remainTime<=0) state=2;
}
void drawED(){
image(imgBG,0,0,width,height);
fill(255,255,0);
textSize(30); text("GameOver",220,300);
}
沒有留言:
張貼留言