/*NO SERIOUSLY. THESE PLANTS ARE BAD NEWS!!!
*/
int numFrames = 29;
PImage[] bite = new PImage[30];
Plant[] monster;
void setup() {
size(600, 400);
frameRate(30);
smooth();
for (int i=0; i < bite.length; i++){
String imageName = "carnivorous_plant_" + nf(i+1, 2) + ".gif";
bite[i] = loadImage(imageName);
}
monster = new Plant[9];
for(int i = 0; i < monster.length; i++){
monster[i] = new Plant(227 + (70*i), 550, 0.2);
}
}
void draw() {
background(255);
for (int i = 0; i<monster.length; i++) {
monster[i].display();
}
}
class Plant {
int x, y;
float w, h;
float plantwidth;
float plantheight;
int frame;
Plant(int xpos, int ypos, float plantheight) {
x = xpos;
y = ypos;
h = plantheight;
frame = 0;
}
void display() {
println(x + ":" + y + ":" + h);
if ((mouseX > (x-bite[frame].width/2)) && (mouseX < (x+bite[frame].width/4)) && (mouseY > (y-bite[frame].height/1)) && (mouseY < (y-bite[frame].height/4))){
//if (frame == numFrames){
frame = constrain(frame+1, 0, 29);
//}
//frame++;
}
else {
frame = constrain(frame-1, 0, 29);
}
image(bite[frame], x-bite[frame].width/2, y-bite[frame].height, bite[frame].width*h, bite[frame].height*h);
}
}
Dougal - M
on Monday, Nov 24, 2008 – 12:45 pm