

import ddf.minim.*;
Minim minim;
AudioPlayer player;
PImage imgZombie,imgGun;
PImage[]num=new PImage[10];
int hp=2;
int score=0;
int Lscore=0;
int[] zombiePos=new int[10];
void setup(){
size(300,550);
for(int a=0;a<=9;a++)num[a]=loadImage(a+".png");
for(int i=0;i<10;i++){
zombiePos[i]= int(random(3));
print(zombiePos[i]+" ");
}
imgZombie=loadImage("zombie.jpg");
imgGun=loadImage("gun.png");
}
int stage=0;
void draw(){
if(stage==0){
background(255,255,0);
textSize(20);
fill(0);
text("START",125,275);
text("PressMouse to 1",75,300);
if(mousePressed) stage=1;
return;
}
else if(stage==1){
background(256,256,256);
int[]N=new int[5];
N[4]=score%10;
N[3]=score/10%10;
N[2]=score/100%10;
N[1]=score/1000%10;
N[0]=score/10000%10;
for(int a=0;a<5;a++)
{
int now=N[a];
image(num[now],150+a*30,0,25,25);
}
int W=hp;
image(num[W],0,0,25,25);
fill(128);
for(int i=9;i>=0;i--){
image(imgZombie,zombiePos[i]*100,350-i*30,100,100);
}
fill(255);
image(imgGun,0,450,100,100);
image(imgGun,100,450,100,100);
image(imgGun,200,450,100,100);
if(hp==0)
{
stage=2;
Lscore=score;
}
}
else if(stage==2){
background(255,0,0);
text("YOU DIE",120,275);
text("Press Mouse to 1",75,300);
text("Score:"+Lscore,120,350);
if(mousePressed)
{
hp=2;
score=00000;
Lscore=0;
stage=1;
}
}
}
void keyPressed(){
minim = new Minim(this);
player = minim.loadFile("GUN.wav");
if((key=='1'&&zombiePos[0]==0) || (key=='2'&&zombiePos[0]==1)||(key=='3'&&zombiePos[0]==2))
{
score+=1;
player.play();
println("Correct");
for(int i=0;i<9;i++)zombiePos[i] =zombiePos[i+1];
zombiePos[9]= int(random(3));
}else{
fill(250,55,0);
rect(0,0,width,height);
score-=1;
hp-=1;
}
if(hp<0)hp=0;
if(score<0)score=00000;
if(score>=100000)score=99999;
}
沒有留言:
張貼留言