import java.util.Vector; public class WineManager{ Vector wine; int curx, cury; WineBottle bottle; int my_width, my_height; int x, y; public WineManager(int n_width, int n_height, int x, int y){ my_width = n_width; my_height = n_height; this.x = x; this.y = y; wine = new Vector(); reset(); } public void clear(){ wine.clear(); reset(); WineBottle temp = new WineBottle(curx, cury); bottle = temp; } public void sip(){ // println("sipping"); if (bottle.isEmpty() ){ wine.add(bottle); curx += bottle.my_width+25; if( curx > my_width-100 ){ curx = round(random(18, 22)); cury += round(random(18, 22)); } WineBottle temp = new WineBottle(curx, cury); bottle = temp; } bottle.sip(); } public void render(){ //iterate and draw any shapes in the vector Iterator iter = wine.iterator(); while(iter.hasNext()){ ((WineBottle)iter.next()).renderEmpty(); } bottle.render(); } private void reset(){ curx = x+30; cury = y+10; bottle = new WineBottle( curx, cury); } } /* public class WineBottle * creates a wine bottle and draws it on the stage * the wine bottle can be emptied with calls to sip */ public class WineBottle{ static final color BLACK = #000000; static final color WINE = #DD2266; float full; Point location; int my_width, my_height; int full_height; public WineBottle(){ full = 1; location = new Point(0, 0); my_width = 128; my_height = 298; full_height = my_height-65; } public WineBottle(int x, int y){ full = 1; location = new Point(x, y); my_width = 128; my_height = 298; full_height = my_height-65; } public void sip(){ full -= 0.02; if(full < 0) full = 0; } public boolean isEmpty(){ if( full == 0) return true; else return false; } public void render(){ //draw the bottle stroke(0); strokeWeight(1); noFill(); pushMatrix(); translate(location.x, location.y); beginShape(); vertex(48, 0); bezierVertex(48, 0, 48, 0, 48, 0); bezierVertex(48, 65, 48, 66, 48, 66); bezierVertex(2, 72, -1, 142, 0, 164); bezierVertex(-2, 279, 10, 298, 10, 298); bezierVertex(63, 326, 124, 295, 124, 295); bezierVertex(134, 274, 128, 159, 128, 159); bezierVertex(130, 67, 78, 64, 78, 64); bezierVertex(78, 0, 78, 0, 78, 0); endShape(CLOSE); popMatrix(); //draw the wine color c; int countx = 0+location.x; int county = my_height + location.y + 11; int this_width = my_width + location.x +5 ; int curr_height = (int)(full * full_height); for(int i=0; ithis_width) break; } while( (c = get( countx, county)) == BLACK ){ if(++countx>this_width) break; } while( (c = get( countx, county)) != BLACK ){ set(countx, county, WINE); if(++countx>this_width) break; } countx = 0; county--; } } public void renderEmpty(){ //draw the bottle stroke(50); strokeWeight(1); noFill(); pushMatrix(); translate(location.x, location.y); beginShape(); vertex(48, 0); bezierVertex(48, 0, 48, 0, 48, 0); bezierVertex(48, 65, 48, 66, 48, 66); bezierVertex(2, 72, -1, 142, 0, 164); bezierVertex(-2, 279, 10, 298, 10, 298); bezierVertex(63, 326, 124, 295, 124, 295); bezierVertex(134, 274, 128, 159, 128, 159); bezierVertex(130, 67, 78, 64, 78, 64); bezierVertex(78, 0, 78, 0, 78, 0); endShape(CLOSE); popMatrix(); } } public class Point{ int x, y; public Point(int x, int y){ this.x = x; this.y = y; } }