2011年12月26日 星期一

上機考




int num = 50; //設定蚊子數量
int[] x = new int[num];
int[] y = new int[num];
int j,w=50,h=50,sum=0;
void setup()
{
size(1000,800);
background(255);
frameRate(25);
smooth();
for(int i=0;i<50;i++){ //設定蚊子位置
int a=(int)random(0,900);
int b=(int)random(75,700);
x[i]=a;
y[i]=b;
PImage img1 = loadImage("f.jpg");
image(img1,a,b,w,h);
}
PFont font = loadFont("AndaleMono-24.vlw");
textFont(font);
textSize(18);
fill(0);
text("SCORE = ", 800, 50);
}


void draw(){
if(sum<50){
background(255);
PFont font = loadFont("AndaleMono-24.vlw");
textFont(font);
textSize(18);
fill(0);
for(int i=0;i<50;i++)
{
PImage img1 = loadImage("f.jpg");
image(img1,x[i],y[i],w,h);
}
text("SCORE = "+sum, 800, 50);
if(mousePressed == true)
{ //蚊子死掉
PImage img3 = loadImage("h.jpg");
image(img3,mouseX-25,mouseY-25,w,h);
for(int i=0;i<50;i++)
{
if(mouseX<=x[i]+50 && mouseX>=x[i] && mouseY<=y[i]+50 && mouseY>=y[i] )
{
x[i]=1000;
y[i]=800;
sum++;
}
}
}
else
{
PImage img2 = loadImage("g.jpg");
image(img2,mouseX-25,mouseY-25,w,h);
}
}
else if(sum==50)
{
background(0);
for(int i=0;i<300;i++)
{
PImage img1 = loadImage("f.jpg");
image(img1,random(0,950),random(0,750),w,h);
}
textSize(125);
fill(random(50,255),random(50,255),random(50,255));
text("YOU WIN !!", random(100,450), random(100,350));
}
}

沒有留言:

張貼留言