2012年12月9日 星期日

HW10


心得:
做的方法與老師的方法不太一樣~但效果是差不多的~~
雖然沒有老師的精緻,但是...我好強^^


PImage img,img1,img2,img3;
int x=1,q=0,o=2,f=20;
int[] a;
int[] b;
int[] s;

void setup()
{
size(600,800);
img=loadImage("s.png");
img1=loadImage("1.png");
img2=loadImage("2.png");
img3=loadImage("3.png");
a=new int[10];
b=new int[10];
s=new int[3];
s[0]=20;
s[1]=50;
s[2]=80;
for(x=0;x<10;x++)
{
  a[x]=int(random(600,1200));
  b[x]=int(random(50,620));
}
}


void draw()
{
PFont font;
font=loadFont("AndaleMono-24.vlw");
textFont(font);
background(0,0,255);
textSize(20);
fill(255,220,220);
rect(170,700,100,80);
rect(320,700,100,80);
fill(135,56,89);
text("Start",180,740);
text("Close",330,740);

if(mousePressed == true)
{
if(mouseButton==LEFT && mouseX<270 && mouseX>170 && mouseY<780 && mouseY>700) o=0;
if(mouseButton==LEFT && mouseX<420 && mouseX>320 && mouseY<780 && mouseY>700) exit();
}
if(o==0)
for(x=0;x<10;x++)
{
a[x]-=3;
if(a[x]<=-5)
{a[x]=700;
 b[x]=int(random(50,620));}

if(x<3)
image(img1,a[x],b[x],s[2],s[2]);
if(x>=3 && x<6)
image(img2,a[x],b[x],s[0],s[0]);
if(x>=6 && x<10)
image(img3,a[x],b[x],s[1],s[1]);
}

if(q==5)
{f+=30;
 q=0;}
image(img,mouseX-10,mouseY-10,f,f);

if(o==0)
      {for(x=0;x<10;x++)
       if(mouseX<a[x]+20 && mouseX>a[x]-20 && mouseY>b[x]-20 && mouseY<b[x]+20)
          {if(x<3 && f>=s[2])
              {a[x]=-5; q++;}
           else if(x>=3 && x<6 && f>=s[0])
              {a[x]=-5; q++;}
           else if(x>=6 && x<10 && f>=s[1])
              {a[x]=-5; q++;}
           else o++; 
          }
      }
if(o==1)
{
textSize(80);
fill(135,56,89);
text("YOU FAIL",100,200);
q=0;
}

if(f==110)
{
textSize(80);
fill(135,56,89);
text("YOU WIN",100,200);
o++;
}

println(a+""+b+":"+mouseX+""+mouseY);
}


沒有留言:

張貼留言