//// MingQing Peng - Midterm String title= "CST 112 MIDTERM"; String author= "MingQing Peng"; String instructions="q to quit; r to reset; ? for help"; String news=""; //// GLOBAL DECLARATIONS //// float x, y, w, h; boolean day=true; float surface; float left,right,top,bottom; float sunX,sunY,sunDX=1; float boatX,boatY,boatDX=2,boatDY=0,boatW=100,boatH=20; int boatCounter=0; float fishX,fishY,fishDX=3,fishDY,fishW=60,fishH=20; float octoX, octoY, octoDX, octoDY=-2, octoW=50, octoH=100; int numberfish= 7; int score= 0; //// Setup: size, reset, etc. void setup() { size( 600,400 ); surface= height/4; // Set top,left, etc. top= surface; left= 0; right= width; bottom= height; reset(); } //// reset: initialize all values; randomize some. void reset() { day= true; boatX= 0; boatY= top; octoX= random(left, right); octoY= bottom; } ////Next frame: scene, boat, octopus, school void draw() { scene(); // Sky and sea; day and night boat(); // Back & forth on surface (always pointing forward). octo(); // Rises slowly (8 legs waving), sinks quickly. school(); // Random number, each slightly smaller, behind, & below. messages(); // Text on screen: title, author, etc. AND a "score" grading(); } //// EVENT HANDLERS: mousePressed(), keyPressed() void keyPressed() { if ( key == 'q' ) exit(); if ( key == 'r' ) reset(); if ( key == '?' ) help(); } void mousePressed() { //// Click on boat to stop or start. // +++++ INSERT YOUR CODE HERE ++++ //// Click on octopus to destroy it. // +++++ INSERT YOUR CODE HERE ++++ } //// Check for hits. boolean hit( float x, float y, float xx, float yy, float ww, float hh ) { //// Return true if (x,y) is near (xx,yy) // +++++ INSERT YOUR CODE HERE ++++ return true; } //// scene: sky, sun, ocean void scene() { sunX += sunDX; sunY = 75; noStroke(); if (day) { background( 200,220,255 ); // light blue sky fill(255,255,0); // sun ellipse( sunX, sunY, 40,40 ); } else { background( 50,150,200 ); // dark sky fill(150,150,150); // moon ellipse( sunX, sunY, 40,40 ); } if (sunX > right-20) { sunX= left+20; day= ! day; } fill( 0, 225, 155 ); rect( left, top, right, bottom ); } /** boat: moves back and forth, across the surface. * Red hull points to direction of travel. * Boat stops while fishing. */ void boat() { boatX += boatDX; boatY= top-20; noStroke(); fill( 225, 50, 0 ); rect( boatX, boatY, boatW, boatH ); rect( boatX+30, boatY, boatW-50, boatH-30 ); triangle( boatX+100,boatY, boatX+130,boatY, boatX+100,top ); // Boat moves across surface if ( boatX > right-30 ) { boatDX= boatDX * -1; } stroke(1); } //// octopus void octo() { octoX= 300; octoY += octoDY; if ( octoY < top+30 ) { octoY= bottom; octoX= random( left, right ); } noStroke(); fill( 100, 0, 225 ); rect( octoX, octoY, octoW, octoH ); ellipse( octoX+25, octoY, octoW, octoW ); } /** school of fish: smaller 7 smaller, behind & below. */ void school( ) { fishX += fishDX; fishY = surface+150; float x=fishX, y=fishY, w=fishW, h=fishH; fill(100); noStroke(); ellipse( x, y, w, h ); } void flockDraw( int n, float x, float y, float w, float h ) { //// Draw flock of n birds float down=0; for (int j=0; j catch | 8 leg wiggle ran x | many rand y ran # :\t 5 56 \n\n" +" 10 10 10 10 10 | 10 10 10 | 10 10 10 | 10 10 10 :\t 175 0 \n" +" 10 5 10 10 5 | 10 5 0 | 5 3 0 | 5 2 0 :\t 70 Peng \n" ; //////// END GRADING STRING //////// /** Display grading string. */ char lastkey='#'; void grading() { if (keyPressed) lastkey=key; fill(0); if (lastkey == '=') text( grading+notes, 2, 10+height/3 ); else if (lastkey=='#') text( "Press '=' key for grading.", 10, height/3 ); }