2012年3月25日 星期日
My Mosquito - Anthony 97470105
Here's what my mother likes to do in the middle of the night, buzzing the mosquitoes!
Hopefully this game can make her sleep earlier from defending her kids from mosquitoes!
Enjoy!
int state=1;
int killed = 0;
int totalMosquito = 50;
PImage racket;
PImage img;
MyMosquito[] mosquito = new MyMosquito[totalMosquito];
PFont font;
void setup()
{
size(600,600);
background(255);
racket = loadImage("racket.jpg");
img = loadImage("mosquito.gif");
for(int x=0;x<50;++x)
{
MyMosquito m = new MyMosquito();
m.x = (int) random(0,550);
m.y = (int) random(0,550);
mosquito[x] = m;
}
font = loadFont("Ziggurat-32.vlw");
textFont(font, 40);
frameRate(60);
}
void draw()
{
background(255);
if (state==1)
{
for(int x=0;x<50;++x)
{
if(mosquito[x].isAlive == true)
image(img, mosquito[x].x, mosquito[x].y);
}
image(racket, mouseX, mouseY, 50, 50);
for (int x=0; x<totalMosquito; ++x)
{
if(mousePressed && mouseButton==LEFT)
{
if((mouseX >= mosquito[x].x) && (mouseX <= mosquito[x].x+35) &&
(mouseY >= mosquito[x].y) && (mouseY <= mosquito[x].y+33))
{
mosquito[x].isAlive = false;
mosquito[x].x = -50;
mosquito[x].y = -50;
++killed;
} // End of if #2
} // End of if #1
} // End of for
fill(0, 102, 153);
text("Score is: " + killed , 10, 35);
if (killed == totalMosquito)
{
state = 2;
}
} // End of State 1
else if (state == 2)
{
PFont fontWin;
fontWin = loadFont("Ziggurat-32.vlw");
textFont(fontWin, 70);
fill(0, 102, 153);
text("You Win!!!" , 600/6, 600/2);
}
}
class MyMosquito
{
public int x;
public int y;
public boolean isAlive = true;
}
訂閱:
張貼留言 (Atom)


沒有留言:
張貼留言