//// Alex Dahlgren - Midterm String title= "M I D T E R M"; String author= "Alex Dahlgren"; String instructions="q to quit; r to reset; ? for help"; String news=""; //// GLOBAL DECLARATIONS //// boolean day=true; float surface; float left,right,top,bottom; float octY,octX,octDY=3; 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; // +++++ INSERT YOUR DECLARATIONS HERE ++++ //// Setup: size, reset, etc. void setup() { size( 600,400 ); surface= height/4; // Set top,left, etc. top= surface; left = 0; right = width; bottom = height; // +++++ INSERT YOUR CODE HERE ++++ // reset(); } //// reset: initialize all values; randomize some. void reset() { // +++++ INSERT YOUR CODE HERE ++++ boatX = 0; sunX = 0; day = true; } ////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" } //// EVENT HANDLERS: mousePressed(), keyPressed() void keyPressed() { // +++++ INSERT YOUR CODE HERE ++++ if (key == 'r') reset(); // reset function if (key == 'q') exit(); } 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() { sunY = height/4 - 50; sunX = sunX + 1; sunX += sunDX; noStroke(); if (day) { background(12,214,247); fill(234,234,43); ellipse(sunX, sunY,50,50); } else { background(3,17,106); fill(81,81,82); ellipse(sunX,sunY,50,50); } if(sunX > width) { day = !day; sunX = 1; } fill(49,175,0); rect(0,surface,width,height+1); // +++++ INSERT YOUR CODE HERE ++++ } /** boat: moves back and forth, across the surface. * Red hull points to direction of travel. * Boat stops while fishing. */ void boat() { // +++++ INSERT YOUR CODE HERE ++++ boatX += 4; boatY = top-20; fill(0); rect(boatX,boatY,70,20); if(boatX > width) { boatX = 0; } } //// octopus void octo() { // +++++ INSERT YOUR CODE HERE ++++ float octX; float octY; float octDY = 5; octX = width/2; ellipse(octX,octY,40,40); } /** school of fish: smaller 7 smaller, behind & below. */ void school() { fishX += fishDX; // +++++ INSERT YOUR CODE HERE ++++ } //// Text on screen 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 ); }