//// Juan Vaccalluzzo - Midterm String title= "CST 112 M I D T E R M"; String author= "Juan Vaccalluzzo"; 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; //// 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(); if (key == '?') { help(); return; } boat(); octo(); school(); messages(); } void messages() { text( title, width/3, 20 ); text( author, 10, height-15 ); // +++++ INSERT YOUR CODE HERE ++++ help(); } void help() { float x=width*2/3, y=bottom-100; fill(0); text( "q to quit; r to reset; ? for help", x, y ); text( "Click octopus to remove it.", x, y+15 ); text( "Click boat to catch fish", x, y+30 ); } //// scene: sky, sun, ocean void scene() { sunX += sunDX; sunY = 75; noStroke(); if (day) { background( 160,220,255 ); // light blue sky fill(250,255,50); // yellow sun ellipse( sunX, sunY, 40,40 ); } else { background( 5,50,220 ); // dark blue night sky fill(250,210,255); // pale pink moon ellipse( sunX, sunY, 40,40 ); } if (sunX > right-20) { // sun & moon move slowly right sunX= left+20; // across the sky 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; // +++++ 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; } //// EVENT HANDLERS: mousePressed(), keyPressed() void keyPressed() { if ( key == 'q' ) exit(); if ( key == 'r' ) reset(); if ( key == '?' ) help(); } //////// GRADING NOTES: String notes="\n\nNOTES:" +"\n Day/night." +"\n No fish." +"\n Boat does not turn around." +"\n Octopus goes up, not down; No random X." +"\n No clicks." ; //////// END NOTES STRING //////// String grading="" //////// PASTE GRADING HERE //////// +" SYNTAX read SCENE move keys | BOAT move click | OCTO move click | FISH move school :\t MID 51CST112 +" compile // sky+sea right q,r | rect left/rt stop/go | dome up/dn kill | ellipse right behind&below :\t 5 MW93 +" draw() modular sun day/nite score | tri <> catch | 8 leg wiggle ran x | many rand y ran # :\t 5 31 +" 10 10 10 10 10 | 10 10 10 | 10 10 10 | 10 10 10 :\t 175 *1.25 +" 10 8 8 10 5 | 10 5 0 | 10 5 0 | 0 0 0 :\t 98 Vaccalluzzo ; //////// END GRADING STRING //////// /** Display grading string. */ char lastkey='#'; void grading() { if (keyPressed) lastkey=key; fill(0); if (lastkey == '=') text( grading+notes, 2, height/3 ); else if (lastkey=='#') text( "Press '=' key for grading.", 10, height/3 ); }