//Maria Campagna - Midterm Spring 2016 //CST 112 - Professor Bam //"S.S. Corey - Tuna Fishing Master" //I couldn't figure out how to get objects to interact with one another //I wanted to make it so that the boat would catch the fish and the creature would also gain points if it crossed the fish's path int anenemyScore = 0; int sSCoreyScore = 0; int mrTunaScore = 0; //Classes Boat[] boats = new Boat[10]; Fish fish; Anenemy anenemy; //Setup void setup() { size(1000, 800); for (int i = 0; i < boats.length; i++) { boats[i] = new Boat(color(i*2)); } fish = new Fish(); anenemy = new Anenemy(); } //Drawing the program void draw() { background(174, 238, 238); fill(0, 199, 140); noStroke(); rect(0, height/4, width, height*3/4); //Calling the voids messages(); //Initialize voids in class boat for (int i = 0; i < boats.length; i++) { boats[i].display(); boats[i].move(); } fish.display(); fish.movefish(); anenemy.display(); anenemy.mousePressed(); } //Creating the fish class Fish { float fX, fY; float dX, dY; float fishX, fishD; float fishEx; Fish() { dX = 1; dY = 2; fishX = -80; fishD = -100; fishEx = 40; fX = random(height/4, 800); fY = random(400, 1000); } void display() { fill(198, 113, 113); ellipse(fX, fY, 200, 50); //FINS triangle(fX - 20, fY - 25, fX + 10, fY - 23, fX - 5, fY - 50); triangle(fX + fishX, fY, fX + fishD, fY - 40, fX + fishD, fY + 25); //EYES fill(255); ellipse(fX + fishEx, fY - 15, 20, 20); fill(0); ellipse(fX + fishEx, fY - 15, 10, 10); fill(0); text("MR. TUNA", fX-50, fY+10); //Moving the fish like the sun } void movefish() { fX = fX + dX; fY = fY + dY; if (fX < 0) { dX = 1; fishD = -100; fishX = -80; fishEx = 40; } if (fX > width) { dX = -1; fishD = 100; fishX = 80; fishEx = -40; } if (fY < height/3) { dY = 1; } if (fY > height) { dY = -1; } if (keyPressed) { if (key == 'D' || key == 'd') { fX = fX +3; } if (keyPressed) { if (key == 'A' || key == 'a') { fX = fX -3; } } if(keyPressed) { if (key == 'W' || key == 'w') { fY = fY - 3; } } if (keyPressed) { if (key == 'S' || key == 's') { fY = fY +3; } } } } } //Creating the bottom dweller class Anenemy { float cX, cY; float dX, dY; float anenemyX, anenemyY; int score = 0; Anenemy() { cX = 600; cY = 700; dX = 1; dY = 2; anenemyX = -80; anenemyY = -100; } void display() { //Body fill(255, 127, 36); ellipse(cX, cY, 150, 50); //Eye sockets ellipse(cX-30, cY-20, 50, 50); ellipse(cX+30, cY-20, 50, 50); //Appendages rect(cX+40, cY, 20, 50); rect(cX-60, cY, 20, 50); //Eyeballs fill(255); ellipse(cX-30, cY-20, 30, 30); ellipse(cX+30, cY-20, 30, 30); fill(0); ellipse(cX-30, cY-20, 15, 15); ellipse(cX+30, cY-20, 15, 15); } void mousePressed() { if (mouseButton == LEFT) { cX = cX + dX; cY = cY + dY; if (cX < 0) { dX = 1; anenemyY = -100; anenemyX = -80; } if (cX > width) { dX = -1; anenemyY = 100; anenemyX = 80; } if (cY < height/3) { dY = 1; } if (cY > height) { dY = -1; } } } } //Class Boat class Boat { float bX, bY; color cR; float dX; float move; float rB, rY; int score = 0; float boatW, boatH; Boat(color cR_) { cR = 255; bX = 0; bY = 160; dX = 1; move = 30; rB = 90; rY = 300; boatW = 200; boatH = 80; } void display() { fill(255, 51, 51); rect(bX, bY, 90, 40); triangle(bX+move+rB, bY, bX+rB, bY, bX+rB, bY+40); rect(bX+40, bY-20, -20, 50); text(score, bX + 20, bY + 20); fill(255); text("S.S. COREY", bX+10, bY+10); text(score, bX + 20, bY + 20); /*fill(255); triangle(bX+rB, bY, bX+rB, bY+80, bX+(100+rB), bY); fill(cR-50, cR-255, cR-255); rect(bX, bY, 200, 80); rect(bX, bY-20, 200, 80-40); fill(cR-50, cR-255, cR-255); rect(bX, bY, 200, 80); rect(bX, bY-20, 200, 80-40); fill(255); text("S.S. COREY", bX+10, bY+10); text(score, bX + 20, bY + 20);*/ } void move() { bX= bX +dX; if (bX > width) { dX=-1; move= -1 * move; rB=0; } if (bX<0) { dX=1; bX= -1 * move; rB=90; } } } //Messages void messages() { fill(0); textSize(12); text( "CST112: TAKE HOME", 15, 15 ); text( "MARIA CAMPAGNA, CST 112", 15, 30 ); text("Move the Anenemy by pressing the left mouse button, press the right to stop him.", 15, 50); text("If you want to move the fish away, press A to move left, D to move right, W to move upward and S to move downward.", 15, 70 ); text("ANENEMY SCORE =", 800, 15); text(anenemyScore, 950, 15); text("MR. TUNA SCORE =", 800, 30); text(mrTunaScore, 950, 30); text("S.S. COREY SCORE =", 800, 45); text(sSCoreyScore, 950, 45); }