影片展示
程式碼:
PImage bg,blu,white,yellow,blu2,white2;
int N=3;
int count = 1500;
float []thingX=new float[6], thingY=new float[6],thingType = new float[6];
int grade=0;
int val;
int []light=new int [5];
void setup(){
for(int i=0;i<5;i++){
light[i]=0;
}
bg = loadImage("bg.jpg");
blu = loadImage("blu.jpg");
white = loadImage("white.jpg");
yellow = loadImage("yellow.jpg");
blu2 = loadImage("blu2.jpg");
white2 = loadImage("white2.jpg");
size(400,600);
for(int i=0;i<N;i++){
newThing(i);
}
}
int countDown=10*30;
void draw(){
image(bg,0,0, 400,600);
image(blu,13,475,60,15);
image(white,73,475,66,15);
image(yellow,139,475,88,15);
image(blu2,293,475,64,15);
image(white2,227,475,66,15);
if(countDown>0){
background(0,0,0);
countDown--;
text("Count Down"+countDown/50,170,300);
return;
}
if(light[0]>0){
fill(#0046FF,90);
rect(10,475,66,-500);
light[0]--;
}
if(light[1]>0){
fill(255,90);
rect(73,475,66,-500);
light[1]--;
}
if(light[2]>0){
fill(#FFF700,90);
rect(139,475,66,-500);
light[2]--;
}
if(light[3]>0){
fill(255,90);
rect(227,475,66,-500);
light[3]--;
}
if(light[4]>0){
fill(#0046FF,90);
rect(293,475,66,-500);
light[4]--;
}
for(int i=0;i<N;i++){
switch(int(thingType[i])){
case 1:
drawblu(i);
break;
case 2:
drawwhite(i);
break;
case 3:
drawyellow(i);
break;
case 4:
drawwhite2(i);
break;
case 5:
drawblu2(i);
break;
}
thingY[i]+=4;
if(thingY[i]>700){
newThing(i);
}
}
/* for(int i=0;i<N;i++){
if(thingType[i]==1)
{
drawblu(i);
if(keyPressed)
{
println("key="+key);
if(key=='d')
if(450<thingY[i] && thingY[i]<700)
{
thingY[i] = 650; grade++; println(grade);
}
}
}
else if(thingType[i]==2)
{
drawwhite(i);
if(keyPressed)
{
if(key=='f')
if(450<thingY[i] && thingY[i]<700)
{
thingY[i] = 650; grade++; println(grade);
fill(255,90);
rect(73,475,66,-500);
}
}
}
else if(thingType[i]==3)
{
drawyellow(i);
if(keyPressed)
{
if(key=='b')
if(450<thingY[i] && thingY[i]<700)
{
thingY[i] = 650; grade++; println(grade);
fill(#FFF700,90);
rect(139,475,66,-500);
}
}
}
else if(thingType[i]==5)
{
drawblu2(i);
if(keyPressed)
{
if(key=='k')
if (450<thingY[i] && thingY[i]<700)
thingY[i] = 650; grade++; println(grade);
fill(#0046FF,90);
rect(293,475,66,-500);
}
}
else if(thingType[i]==5)
{
drawwhite2(i);
if(keyPressed)
{
if(key=='j')
if (450<thingY[i] && thingY[i]<700)
{
thingY[i] = 650; grade++; println(grade);
fill(255,90);
rect(227,475,66,-500);
}
}
}
thingY[i]+=4;
if(thingY[i]>600) newThing(i);
}*/
if(count>0){
count--;
text("Time: "+count/50,170,300);
}
if(count==0){
background(#000302);
textSize(48);
text("Score: "+grade,90,300);
fill(0, 102, 153);
}
}
void keyPressed(){
switch(key){
case 'd':
for(int i=0;i<N;i++){
if(thingX[i]==13 && thingY[i]<580 &&thingY[i]>400){
grade++;
thingY[i] = 800;
light[0]=10;
newThing(i);
drawblu(i);
}
}
break;
case 'f':
for(int i=0;i<N;i++){
if(thingX[i]==73 && thingY[i]<580 &&thingY[i]>400){
grade++;
thingY[i] = 800;
light[1]=10;
newThing(i);
drawwhite(i);
}
}
break;
case 'b':
for(int i=0;i<N;i++){
if(thingX[i]==139 && thingY[i]<580 &&thingY[i]>400){
grade++;
thingY[i] = 800;
light[2]=10;
newThing(i);
drawyellow(i);
}
}
break;
case 'j':
for(int i=0;i<N;i++){
if(thingX[i]==227 && thingY[i]<580 &&thingY[i]>400){
grade++;
thingY[i] = 800;
light[3]=10;
newThing(i);
drawwhite2(i);
}
}
break;
case 'k':
for(int i=0;i<N;i++){
if(thingX[i]==293 && thingY[i]<580 &&thingY[i]>400){
grade++;
thingY[i] = 800;
light[4]=10;
newThing(i);
drawblu2(i);
}
}
break;
}
}
void newThing(int i){
thingY[i] = -random(200);
thingX[i] = random(400);
thingType[i] = int(random(5))+1;
}
void drawblu(int i){
thingX[i]=13;
image(blu,thingX[i],thingY[i],60,15);
}
void drawwhite(int i){
thingX[i]=73;
image(white,thingX[i],thingY[i],66,15);
}
void drawyellow(int i){
thingX[i]=139;
image(yellow,thingX[i],thingY[i],88,15);
}
void drawblu2(int i){
thingX[i]=293;
image(blu2,thingX[i],thingY[i],66,15);
}
void drawwhite2(int i){
thingX[i]=227;
image(white2,thingX[i],thingY[i],66,15);
}
沒有留言:
張貼留言