Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/* Bears love fish //////////////
 /////////////By Jennifer Stienstra////////////
 */

//variables for the first fish
float tail1y; 
float tail2y;
float tail3y;
float fish1y;
float eye1y;

//variables for the second fish
float tail4y;
float tail5y;
float tail6y;
float fish2y;
float eye2y;

//variables for the third fish
float tail7y;
float tail8y;
float tail9y;
float fish3y;
float eye3y;

/*boolean created for when the game is being played, 
 and turned off when the game is lost*/
boolean display;
//variable for rocks above fish
int rockAmount;






void setup() {
  size(400, 400);
  //values for first fish
  display = true;
  rockAmount = 10;


  tail1y = 0;
  tail2y = 40;
  tail3y = 0;
  fish1y = 40;
  eye1y = 70;
  //values for second fish     
  tail4y = -80;
  tail5y = -40;
  tail6y = -80;
  fish2y = -40;
  eye2y = -10;

  //values for third fish
  tail7y = -120;
  tail8y = -80;
  tail9y = -120;
  fish3y = -80;
  eye3y = -50;
}

void draw() {
  if (display == true) {
    background (84, 252, 223);

    goldfish1(tail1y, tail2y, tail3y, fish1y, eye1y); 
    goldfish2(tail4y, tail5y, tail6y, fish2y, eye2y); 
    goldfish3(tail7y, tail8y, tail9y, fish3y, eye3y); 
    movegoldfish();
    drawRocks();
    hungryBear();
    lostCondition();
  } else {
    background(0);
  }
}
//loop that draws the rocks
void drawRocks() {
  int displacement = 0;
  for (int i = 0; i < rockAmount; i ++) {
    for (int k = 0; k < rockAmount; k ++) {
      drawRock( i + displacement);
      displacement += 30;
    }
  }
}


//THE BEAR
void hungryBear() {
  rectMode(CORNERS);
  //bear head
  fill(67, 43, 7);
  stroke(0);
  rect(mouseX, 360, mouseX+100, 400);

  //bear ears
  fill(100, 80, 50);
  rect(mouseX +10, 380, mouseX+30, 390);
  rect(mouseX+ 70, 380, mouseX+90, 390);

  //bear snout
  fill(72, 54, 28);
  rect(mouseX+20, 320, mouseX+80, 360);

  //bear nose
  fill(0);
  ellipseMode(CORNERS);
  ellipse(mouseX+30, 305, mouseX+70, 325);
}

//the  first fish!
void goldfish1(float tail1y, float tail2y, float tail3y, float fish1y, float eye1y) {
  //tail of the fish
  stroke(0);
  fill(252, 139, 69);
  triangle(40, tail1y, 60, tail2y, 80, tail3y);
  //body of fish
  fill(250, 118, 35);
  rectMode(CORNERS);
  rect(40, fish1y, 80, fish1y+50);
  //fish eye
  fill(0);
  ellipseMode(CORNERS);
  ellipse(70, eye1y, 80, eye1y+10);
}

//the second fish
void goldfish2(float tail4y, float tail5y, float tail6y, float fish2y, float eye2y) {
  //tail of the fish
  fill(252, 139, 69);
  triangle(175, tail4y, 195, tail5y, 215, tail6y);
  //body of fish
  fill(250, 118, 35);
  rectMode(CORNERS);
  rect(175, fish2y, 215, fish2y+50);
  //fish eye
  fill(0);
  ellipseMode(CORNERS);
  ellipse(205, eye2y, 215, eye2y+10);
}

//the third fish
void goldfish3(float tail7y, float tail8y, float tail9y, float fish3y, float eye3y) {
  //tail of the fish
  fill(252, 139, 69);
  triangle(310, tail7y, 330, tail8y, 350, tail9y);
  //body of fish
  fill(250, 118, 35);
  rectMode(CORNERS);
  rect(310, fish3y, 350, fish3y+50);
  //fish eye
  fill(0);
  ellipseMode(CORNERS);
  ellipse(340, eye3y, 350, eye3y+10);
}

//moves the goldfish down the stream
void movegoldfish() {
  tail1y += 1;
  tail2y += 1;
  tail3y += 1;
  tail4y += 1;
  tail5y += 1;
  tail6y += 1;
  tail7y += 1;
  tail8y += 1;
  tail9y += 1;
  fish1y += 1;
  fish2y += 1;
  fish3y += 1;
  eye1y += 1;
  eye2y += 1;
  eye3y += 1;
}

//draw rocks above the water where the bear is standing
void drawRock(float x) {
  if (display == true) {
    ellipseMode(CENTER);
    fill(73, 77, 77);

    noStroke();
    ellipse(x, height, 50, 50);
    ellipseMode(CORNERS);
  }
}

/*pressing the mouse when the fish is 'in the bear's mouth' 
 will send fish back to original position*/
void mousePressed() {
  //if first fish is "eaten"
  if (fish1y > 300 && mouseX > 0 && mouseX < 60)
  {
    tail1y = 0;
    tail2y = 40;
    tail3y = 0;
    fish1y = 40;
    eye1y = 70;

    //if second fish is "eaten"
  } else if (fish2y > 300 && mouseX > 135 && mouseX < 195 ) {
    tail4y = -80;
    tail5y = -40;
    tail6y = -80;
    fish2y = -40;
    eye2y = -10;

    //if third fish is "eaten"
  } else if (fish3y > 300 && mouseX > 270 && mouseX <330)
  {
    tail7y = -120;
    tail8y = -80;
    tail9y = -120;
    fish3y = -80;
    eye3y = -50;
  }
}

//what happens when the player misses one of the fish
void lostCondition() {
  //if player misses first fish
  if (tail1y > 400) {
    print("You Starved. Press r to play again\n");
    display = false;
  }
  //if player misses second fish
  if (tail4y > 400) {
    //added \n at the end of text to start new paragraph
    print("You Starved. Press r to play again\n");
    display = false;
  }
  //if player misses third fish
  if (tail7y > 400) {
    print("You Starved. Press r to play again\n");
    display = false;
  }
}

//Activated to start the toy over again.
void keyPressed() {
  if (display == false) {
    if (key== 'r'|| key =='R') {
      setup();
    }
  }
}