/*DON'T TOUCH THE PLANTS!!!
*/
Plant a1;
void setup() {
size(600, 400);
frameRate(30);
a1 = new Plant (350, 450, 0.8);
}
void draw() {
background(255);
a1.display();
println(a1.frame);
}
class Plant {
int numFrames = 29;
PImage[] bite = new PImage[30];
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;
for (int i=0; i < bite.length; i++){
String imageName = "carnivorous_plant_" + nf(i+1, 2) + ".gif";
bite[i] = loadImage(imageName);
}
}
void display() {
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 - L
on Monday, Nov 24, 2008 – 5:59 am