//-- TAKE HOME MIDTERM....You told me to email you it because when i uploaded it before it came up with a bunch of letters and numbers, and i did but then you said to upload it here..thanks //variables int score=0; Gold[] balls=new Gold[3]; void setup(){//size/color size(300,500); //BAM: Move this to draw()// background(200,140,100); //objects balls[0]= new Gold (color(255,0,0),100,100,30,30,5,5); balls[1]= new Gold(color(0,255,0), 100,130,40,40,4,6); balls[2]= new Gold(color(255,130,25),100,160,10,10,2,3); } void initialize() { //// Random ball pos. balls[0].x=100+random(100); balls[0].y=100; balls[1].x=100+random(100); balls[1].y=130; balls[2].x=100+random(100); balls[2].y=160; } void draw(){ //draws next frame /*BAM*/ background(200,140,100); drawTable(); drawBalls(); //Pause if (key=='p') { fill(0,0,250); text( "PAUSED", width/2-58, height/2-30 ); text( "(press ''any key'' to resume)", width/2-58, height/2-10 ); } else{moveBalls(); } grade(); //// ADD THIS LINE TO draw() } void drawTable(){ //draw table fill(0); text(" ''Bouncing fruits'' ",80,25); text("Michael Goldberg",10,480); text( "SCORE: " +score, 200, 35 ); fill( 120,70,40); rectMode(CENTER); rect(150,250,260,420); fill(255,220,190); rect(150,250,225,375); float y=50; while (y<440){ line(38,y,260,y); y=y+40; } } void drawBalls() { //// Drawing ea. ball for (int k=0; k<3; k++) { balls[k].show(); } } void moveBalls() { //// move ea. ball (dx,dy), //// detects hit for (int j=0; j<3; j++) { balls[j].move(); } check(balls[0], balls[1]); check(balls[0], balls[2]); check(balls[1], balls[2]); } void check( Gold p, Gold q) { //// Check for collisions/ go opposite if hit if (dist( p.x,p.y, q.x,q.y) < 20) { score -= 10; p.dx= -p.dx; p.dy= -p.dy; q.dx= -q.dx; q.dy= -q.dy; // opp. veloc. float tmp; tmp = p.dx; p.dx= q.dx; q.dx= tmp; tmp = q.dx; q.dx= p.dx; p.dx= tmp; p.x += 2*p.dx; p.y += 2*p.dy; q.x += 2*q.dx; q.y += 2*q.dy; } } void keyPressed() { //quits game if (key == 'q') { exit(); } if (key=='r') { //random pos. when hit initialize(); } } class Gold { //// fruit color c; float x=0,y=0,w=0,h=0; // Pos. of this ball float dx=0,dy=0; // Vel. Gold( float x0, float y0,float w0,float h0,float dx0,float dy0 ) { x= x0; y= y0; w= w0; h= h0; dx= dx0; dy= dy0; } Gold( color c0, float x0, float y0,float w0,float h0,float dx0,float dy0) { c= c0; x= x0; y= y0; w= w0; h= h0; dx= dx0; dy= dy0; } Gold( ) { } // Method void move() { // Move ball by (dx,dy) x= x + dx; y= y + dy; // Bounce off walls. if (x < 75) { dx= -dx; } if (x > 250) { dx= -dx; } if (y < 75) { dy= -dy; } if (y > 435) { dy= -dy; } } void show() { //// Draw at (x,y) fill(c); // text(c, x, y+30); ellipseMode(CENTER); ellipse(x,y, w,h); // Diameter is 20. } void showBlack() { // Draw at (x,y) fill(0); ellipseMode(CENTER); ellipse(x,y, w,h); // Diameter is 20. } } String[] items={ "Field", "Fruits", "Action", "Score", "Click", "Text", "Keys", "Class", "Constr", "Coding" }; int[] points={ 10, 10, 6, 5, 00, 10, 8, 9, 7, 9, }; String letter="B - "; String name=" Gol-takehome-redo "; void grade() { //// Display grading info //// int total=0, col=100, line=4, h=18; fill(0); textSize(h); text( name, col, h*line++ ); line++; for ( int j=0; j