//Tristan Szakacs //Project Two //Could not get the score to work. Also did not know how to //use Random for the fish Y coordinate without them refreshing all over the screen. float boatX, boatY, boatDX; String name1 = "Steve"; String name2 = "Carl"; String name3 = "John"; String button1 = "GO"; String button2 = "CATCH"; String button3 = "RESET"; float cloudX = 20, cloudY = 20, cloudDX = 0.4, cloudDY = 0.2; float fish1X, fish1Y; float fish2X, fish2Y; float fish3X, fish3Y; float fish1DX, fish2DX, fish3DX; float fish1m = 1, fish2m = 0.5; float lineX, lineY; float boyoX, boyoY; float rodX, rodY; boolean go; boolean fish; boolean resetti; int score = 0; void setup() { size(800, 800); fresh(); } void fresh() { resetFish1(); resetFish2(); resetFish3(); } void draw() { background( 50,100, 200); sea(); showButton( button1, 0, 0); showButton( button2, 125, 0); showButton( button3, 250, 0); buttonPress(); } //Creates Button Pressed Function. void buttonPress() { if(mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 50 && mousePressed){ go = true; } if(mouseX > 125 && mouseX < 225 && mouseY > 0 && mouseY < 50 && mousePressed){ fish = true; } else { fish = false; } if(mouseX > 250 && mouseX < 350 && mouseY > 0 && mouseY < 50 && mousePressed){ resetti = true; } else { resetti = false; //Stops reset from looping when you let go of mouse. } if(go){ display(); movement(); } if(fish){ twine(); } if(resetti) { resetFish1(); resetFish2(); resetFish3(); } } //Toggles buttons. void mousePressed() { if ( mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 50){ go = !go; } if ( mouseX > 125 && mouseX < 225 && mouseY > 0 && mouseY < 50){ fish = !fish; } if ( mouseX > 250 && mouseX < 350 && mouseY > 0 && mouseY < 50){ resetti = !resetti; } else{ resetti = false; } } //Displays all images. void display() { fill( 150, 30, 50); //Displays Carl newFish( name1, fish1X, fish1Y); fill( 100, 30, 150); //Displays Steve newFish( name2, fish2X, fish2Y); fill(150, 200, 100); newFish( name3, fish3X, fish3Y); showCloud( cloudX, cloudY); //Displays Cloud showBoat( boatX); //Displays Boat } //Creates Buttons. void showButton( String type, float x, float y) { fill(100); rect( x, y, 100, 50); //Draws button shape. fill(0); text( type, x+20, y+25); //Names the button. } //Creates Fish. void newFish( String name, float x, float y) { triangle( x-75, y+15, x-50, y, x-75, y-15); //Tail ellipse ( x, y, 100, 50); //Body fill(0); text( name, x-40, y); //Displays Name. fill(250); ellipse( x+25, y-5, 5,5); //Displays Eye. int position = int (x) / 100; if ( position % 2 == 0) { triangle( x,y, x+20, y, x+10, y+20); } else{ triangle( x,y, x+20, y, x+10, y-20); } } void showCloud( float x, float y) { fill( 250); ellipse( cloudX, cloudY, 100, 50); ellipse( cloudX-30, cloudY-20, 60, 30); } //Creates Boat. void showBoat(float x) { fill( 100, 50, 50); rect( x, 150, 100, 50); //Base of boat. triangle( x+100, 200, x+100, 150, x+150, 150); //Bow. fill( 10, 100, 100); ellipse(boyoX + 30, boyoY, 50, 50); boyoX = boatX; boyoY = 100; line(boyoX + 30, boyoY+20, boyoX + 30, boyoY + 50); stroke(3); line(rodX+30, rodY + 30, rodX + 80, rodY - 40); rodX = boyoX; rodY = boyoY; } void twine() { lineX = boatX + 1; lineY = lineY + 4; line(rodX+80, rodY-40, lineX, lineY); if( lineY > 800){ lineY = rodY - 40; } } //Creates Sea. void sea() { fill( 0, 90, 30); rect( 0, 200, 800, 600); } void movement() //Controls all movement. { //Causes the fish to move. fish1X += fish1DX; fish2X += fish2DX; fish3X += fish3DX; //Resets fish when it gets to the end. if (fish1X > 800) resetFish1(); if (fish2X > 800) resetFish2(); if (fish3X > 800) resetFish3(); //Moves boat. boatX = boatX + boatDX; if( boatX - 50 < 0){ boatDX = 2;} if( boatX + 100 > width + 100){ boatDX = -2;} //Moves Cloud. cloudX = cloudX + cloudDX; if( cloudX<0) cloudDY *= -1; if( cloudX>800) cloudDX *= -1; cloudY = cloudY + cloudDY; if(cloudY<0) cloudDY*= -1; if(cloudY>150) cloudDY *= -1; } //Resets fish location and speed. void resetFish1() { fish1X = 0; fish1Y = random( 200, 700); fish1DX = random( 1, 8); } void resetFish2() { fish2X = 0; fish2Y = random(200,700); fish2DX = random( 2, 5); } void resetFish3() { fish3X = 0; fish3Y = random(200,700); fish3DX = random( 2, 6); }