///Justin Chen
///Interactivity 28
///Exercise M
///Click to shoot lazer
PShape wing;
Bat[]bats;
int numBats = 20;
void setup() {
size(600, 400);
smooth();
bats = new Bat [numBats];
for (int i=0; i<numBats; i++){
float x = random(0,600);
float y = random(0,400);
bats[i]=new Bat (x,y);
}
}
void draw() {
background (255);
for(int i=0; i<numBats; i++)
{
bats[i].display();
bats[i].move();
}
}
class Bat {
float x;
float y;
float e;
float turn;
float a;
Bat (float xpos, float ypos) {
x = xpos;
y = ypos;
wing = loadShape("leftblade.svg");
}
void display() {
float angle = atan2(mouseY-y, mouseX-x);
turn = cos(a)/16;
a += 0.5;
pushMatrix();
translate(x, y);
rotate(angle);
rotate(turn);
shape(wing, 20, -10, -100, 100);
shape(wing, 20, 5, -100, -100);
popMatrix();
if (mousePressed == true) {
fill(0);
ellipse(mouseX, mouseY, 50, 50);
noFill();
stroke(0);
ellipse(mouseX, mouseY, 80, 80);
fill(0);
triangle(x,y,mouseX+10, mouseY+10,mouseX-10, mouseY-10);
}
}
void move() {
x += ((mouseX - x)* e) ;
y += ((mouseY -y) * e);
}
}
Justin - M
on Monday, Nov 24, 2008 – 2:21 am