//constructs a 5 sided shape using fruit and ground images for textures // add bouncing red ball MButton lessx = new MButton(10,20,60,30,250,0,0,"Less X"); MButton morex = new MButton(80,20,60,30,0,250,0,"More X"); MButton lessy = new MButton(10,50,60,30,250,200,0,"Less Y"); MButton morey = new MButton(80,50,60,30,200,250,0,"More Y"); MButton lessz = new MButton(10,80,60,30,250,0,250,"Less Z"); MButton morez = new MButton(80,80,60,30,0,250,250,"More Z"); MButton[] allbuttons = {morex, lessx, morey, lessy, morez, lessz}; PFont myfont; float xpos = 0; float ypos = 0; float zpos = 0; float xd = 1; float yd = -1; float zd = 2; PImage ground; PImage fruit; PImage canopy; float leftwall = -100; float leftx = leftwall+3; float rightwall = 200; float rightx = rightwall-3; float topwall = -100; float topy = topwall+3; float botwall = 100; float boty = botwall-3; float backwall = 0; float backz = backwall+3; float frontwall = 200; float frontz = frontwall-3; void setup() { size(1000,600,P3D); myfont = createFont("Ariel",18); ground = loadImage("leaves.jpg"); fruit = loadImage("fruit.jpg"); canopy = loadImage("greenery.jpg"); frameRate(30); } void draw() { background(255); drawbuttons(); translate(width/2, height/2); beginShape(); texture(canopy); vertex (leftwall,topwall,frontwall,0,0); vertex (leftwall,topwall,backwall,0,200); vertex (rightwall,topwall,backwall,300,200); vertex(rightwall,topwall,frontwall,300,0); endShape(); beginShape(); texture(fruit); vertex (leftwall,topwall,backwall,0,0); vertex (rightwall,topwall,backwall,100,0); vertex (rightwall,botwall,backwall,100,100); vertex(leftwall,botwall,backwall,0,100); endShape(); beginShape(); texture(fruit); vertex (leftwall,topwall,frontwall,0,0); vertex (leftwall,topwall,backwall,100,0); vertex (leftwall,botwall,backwall,100,100); vertex(leftwall,botwall,frontwall,0,100); endShape(); beginShape(); texture(fruit); vertex (rightwall,topwall,backwall,0,0); vertex (rightwall,topwall,frontwall,100,0); vertex (rightwall,botwall,frontwall,100,100); vertex(rightwall,botwall,backwall,0,100); endShape(); beginShape(); texture(ground); vertex (leftwall,botwall,backwall,0,0); vertex (rightwall,botwall,backwall,100,0); vertex (rightwall,botwall,frontwall,100,100); vertex(leftwall,botwall,frontwall,0,100); endShape(); balloon(); } void balloon() { moveballoon(); translate(xpos,ypos,zpos); fill(0); stroke(255,0,0); sphere(10); } void moveballoon() { xpos +=xd; ypos +=yd; zpos +=zd; if ((xposrightx)) xd=-xd; if ((yposboty)) yd=-yd; if ((zposfrontz)) zd=-zd; } void drawbuttons() { for (int i=0;i=xpos)&&(x<=(xpos+xlen))&&(y>=ypos)&&(y<=(ypos+ylen))) return true; else return false; } }