String title="Shooting Fish in a Barrel"; String author="Kelmor Amaya; Exam #1"; String news=""; //data// float left=50, right, top=100, bottom, bW, bH; float fx, fy, fd; //F's in each means Fish// // float gun; float bulletX, bulletY; int score=0; //setup// void setup () { size (900, 500); rectMode (CENTER); //cask// left =50; right= width-50; top= 100; bottom= height-50; bW= right-left; bH= bottom-top; //rifle gun= left+bW*0.25; resetall (); } void resetall () { reset1(); bulletY=0; score=0; } //speed & random positions of fish// void reset1 () { fx=left+45; fy=random(top+90, bottom-20); fd=random (1, 19); score=score-1; } void draw () { scene (); show (); action(); msgs(); bulletY=0; score=0; } // scene- cask & gun; void scene () { background (137, 158, 225); // cask fill (173, 224, 250); //water stroke(138, 43, 226); //violet border// strokeWeight (10); //thickness of border// rectMode(CORNER); rect(left, top, bW, bH); strokeWeight (3); stroke (178, 34, 34); //redish border around fish// //rifle fill(255); // white gun rect( gun, top-40, 12, 80 ); fill(100, 124, 120); // purple stock rect( gun-25, top-40, 30, 15 ); fill(255); text( 1, gun-15, top-28 ); } void show() { // Draw the bullets fill(255,122,232); if (bulletY>top) rect( bulletX, bulletY, 5, 10 ); float tailX; // tailX=fx-25; fill(250, 128, 114); //salmon fish// ellipse (fx, fy, 50, 16); triangle(tailX, fy, tailX-20, fy-12, tailX-20, fy+12); } void action () { fx+=fd; if (fx>right) reset1(); // if (bulletY>top) bulletY += 20; if (bulletY>bottom) bulletY=0; } void msgs() { fill(255); textSize(34); text( title, width/3, 30 ); textSize(15); text( news, 10, 90); text( author, 40, height-20 ); } void hits() { if ( dist( bulletX, bulletY, fx, fy ) < 20 ) score= score + 50; news= "Salmon fish was caught"; reset1(); background( 255, 255, 0 ); } void keyPressed() { if (key == 'q') exit(); if (key == 'r') resetall(); // Shoot if (key == '1') { bulletX=gun; bulletY=top+10; score=score-5; } } void mousePressed() { if ( dist( mouseX, mouseY, gun, top ) < 50) { bulletX=gun; bulletY=top+10; score=score-5; } }