/* Midterm JOE MANINGLELLI 10-31-14 */ String title="CST 112 Midterm"; String author="Joe Manginelli"; boolean day; int score; float surface; float bottom; float birdX, birdY, birdDX= 3; float oneX, oneY, oneDX, oneDY; float twoX, twoY, twoDX, twoDY; float threeX, threeY, threeDX, threeDY; float witchX, witchY, witchDX= -2; float witchEyeX, witchEyeY; float octX, octY, octDY= 1; float helpX, helpY, helpDY=0; float moonX, moonY; float waveX=30, waveY=10; float weedX=10, weedY=10; void setup() { size(600, 500); surface= height/2; bottom= height; score=0; day= true; begin(); } void begin() { //// Move creatures back to starting positions birdX=50; birdY=surface/2; octX= random( 100, width-100 ); octY=surface; witchX= width; witchY= random( 50, surface-50 ); witchDX= -2; // moonX= 50 + random( width-100 ); moonY= witchY + random( 50 ); helpX=width*2/3; helpY=height/3; } void draw() { //// Draw the frame scene(); if (day) { bird(); } else { witch(); octopus(); } //// messages are last, so they're always shown messages(); } void messages() { //// Messages on screen //// Text on screen fill(0); text( title, 200, 20 ); text( author, 20, height-20); text( witchX, 10, 10 ); // Score fill(255); if (score<0) fill(255, 0, 0); if (score != 0) text( "SCORE: "+score, width*3/4, surface-50 ); fill(255); //-- text( "MOON: "+moonX+","+moonY, helpX, helpY-20 ); } void scene() { //////// Sky & ocean if (day) { background( 200, 200, 255 ); fill( 255, 255, 0 ); ellipse( width-100, 50, 50, 50 ); // sun } else { background( 100, 100, 255 ); fill( 200, 100, 100 ); noStroke(); ellipse( moonX, moonY, 70, 70 ); // moon } /////////// Ocean fill( 100, 200, 100 ); noStroke(); rectMode(CORNER); rect(0, surface, width, height-surface ); waves( surface ); seaweed( bottom ); } void waves( float y ) { //// Make waves on surface of ocean. if (frameCount % 10 == 0) { waveX= 30 + random(0, 10); // Randomize wave width, every ten frames waveY= 20 + random(0, 4); if (day) waveX += 20; waveX = waveX -1 + random(2); } // Make waves across width of screen. for (float x=0; x width-50) { background( 255, 255, 200 ); // Flash (sunrise); day=false; begin(); return; } // Draw bird. fill(200, 0, 200); triangle( birdX, birdY, birdX-80, birdY-10, birdX-80, birdY+10 ); fill(150, 0, 150); if (frameCount / 10 % 2 == 0) { triangle( birdX-30, birdY, birdX-80, birdY-30, birdX-80, birdY+30 ); } else { } } void witch() { //// Witch move & draw witchX += witchDX; if (witchX < 50) { background(255, 255, 200); // Flash (sunrise) day=true; score -= 25; begin(); return; } //// Draw witch fill(100, 50, 50); rectMode(CENTER); rect( witchX, witchY, 40, 60 ); // Brown rectangle fill(255, 0, 0); // Red face ellipse( witchX, witchY-40, 20, 20); // Yellow eye fill(255, 255, 0); ellipse( witchX-5, witchY-43, 5, 5 ); // Black hat. fill(0); triangle( witchX-10, witchY-50, witchX+10, witchY-50, witchX, witchY-70 ); strokeWeight(3); stroke(0); line( witchX-20, witchY-50, witchX+20, witchY-50 ); // Hat brim drawBroom( witchX-60, witchX+60, witchY+30 ); } void drawBroom( float x1, float x2, float y ) { //// Broom from x1 to x2, at y strokeWeight(6); stroke(200, 150, 100); line( x1, y, x2, y ); //// Bristles at x2. strokeWeight(1); float yy= y-10; for (int j=0; j<8; j++ ) { line( x2, yy, x2+40, yy ); yy += 3; } noStroke(); // Reset } void octopus() { //// Octopus- moving up & down octY += octDY; if (octY < surface) { //// Octopus surfaces: lose 25 points, flash black, reverse begin sinking. octDY = +1; // Sink slowly. background( 0, 50, 100 ); // Flash, darker blue score -= 50; } else if (octY > height-50) { // Hit bottom octDY = -3; // Rise faster } if (octY > height-70) { background( 0, 50, 100 ); // Prolonged flash at bottom fill(0, 255, 255); text( "o\n o\n o\n gurgle\n gurgle\n gurgle", octX+20, octY-120 ); fill(255, 255, 0); text( "SCORE DROPS BY 50, WHEN I SURFACE!", octX-100, surface ); } //// Draw body & slanty legs; fill( 50, 50, 150 ); rectMode(CENTER); rect( octX, octY, 40, 50 ); ellipse( octX, octY-30, 40, 40 ); // Eye fill(200, 150, 0); ellipse( octX, octY-35, 15, 10 ); fill(0); ellipse( octX-2+random(4), octY-35, 4, 4 ); // Legs stroke( 50, 50, 150 ); strokeWeight(2); float slant=0; if (octDY<0) { //making him go up slant = (frameCount % 10 < 5) ? -3 : +3; } for ( float x=octX-20+2; x