/* Midterm Andrew Urrutia 11-3-14 */ String title="CST 112 Midterm"; String author="Andrew Urrutia"; 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= -4; float witchEyeX, witchEyeY; float octX, octY, octDY= 2; float helpX, helpY, helpDY=0; float moonX, moonY; float waveX=20, waveY=20; float weedX=50, weedY=50; 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(); } //// message appear at the end message(); } void message() { //// Message on screen //// Text on screen fill(0); text( title, 250, 30 ); text( author, 20, height-20); text( witchX, 10, 10 ); // Score fill(250); 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 and ocean if (day) { background( 200, 250, 255 ); fill( 255, 255,200 ); ellipse( width-100, 50, 50, 50 ); // sun } else { background( 100, 100, 200 ); 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= 40 + random(0, 15); // Randomize wave width, every ten frames waveY= 30 + random(0, 2); if (day) waveX += 30; waveX = waveX -2 + random(4); } // Make waves across width of screen. for (float x=0; x width-50) { background( 250, 255, 250); // Flash (sunrise); day=false; begin(); return; } // Draw bird. fill(250, 200, 250); triangle( birdX, birdY, birdX-80, birdY-10, birdX-80, birdY+10 ); fill(150, 0, 150); if (frameCount / 10 % 2 == 0) { triangle( birdX-20, birdY, birdX-40, birdY-50, birdX-40, birdY+40 ); } else { } } void witch() { //// Witch move & draw witchX += witchDX; if (witchX < 50) { background(250, 200, 255); // Flash (sunrise) day=true; score -= 25; begin(); return; } //// Draw witch fill(200, 250, 255); rectMode(CENTER); rect( witchX, witchY, 40, 60 ); // Brown rectangle fill(255, 0, 0); // Red face ellipse( witchX, witchY-30, 20, 40); // Yellow eye fill(250, 250, 200); ellipse( witchX-5, witchY-40, 5, 5 ); // grey hat. fill(200); triangle( witchX-10, witchY-50, witchX+10, witchY-50, witchX, witchY-70 ); strokeWeight(4); 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( 200, 250, 100 ); // Prolonged flash at bottom fill(200, 250, 2200); 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 and the legs; fill( 250, 255, 255 ); rectMode(CENTER); rect( octX, octY, 20, 40 ); ellipse( octX, octY-30, 40, 40 ); // Eye fill(255, 250, 200); ellipse( octX, octY-35, 15, 10 ); fill(0); ellipse( octX-2+random(4), octY-35, 4, 4 ); // Legs stroke( 40, 40, 250 ); strokeWeight(4); float slant=0; if (octDY<0) { //make octo go up slant = (frameCount % 10 < 5) ? -3 : +3; } for ( float x=octX-20+2; x