Dougal - L

By Dougal Henken
/*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); } }

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*