/* ZJ Wood code for PCS 6th grade - pumpkin game - kids fill in bat drawn
at mouse */

int ty1, ty2, ty3;
boolean stopB1, stopB2, stopB3;
boolean win;

void setup() {
  size(800, 800);
  ty1 = ty2 = ty3 = 0;
  stopB1 = stopB2 = stopB3 = false;
  win = false;
  frameRate(15);
}

void draw() {
  if (win) {
    background(random(0, 255), random(0, 255), random(0, 255));
  } else {
    background(12, 34, 56);
  }
  drawPumpkins();

  //TODO - change this into a bat!
  fill(0);
  ellipse(mouseX, mouseY, 40, 40);

}

void mousePressed() {
  if (mouseX > 180 && mouseX < 220 &&  mouseY > ty1-20 && mouseY < ty1+20) {
    stopB1 = true;
  }
  if (mouseX > 380 && mouseX < 420 && mouseY > ty2-20 && mouseY < ty2+20) {
    stopB2 = true;
  }
  if (mouseX > 580 && mouseX < 620 && mouseY > ty3-20 && mouseY < ty3+20) {
    stopB3 = true;
  }
  if (stopB1 && stopB2 && stopB3) {
    win = true;
  }
}

void drawPumpkins() {
  //these are the obstacles
  fill(219, 146, 35);
  ellipse(200, ty1, 60, 50);
  fill(36, 118, 12);
  rect(195, ty1-40, 10, 20);

  fill(240, 149, 12);
  ellipse(400, ty2, 60, 50);
  fill(36, 118, 12);
  rect(395, ty2-40, 10, 20);

  fill(219, 146, 35);
  ellipse(600, ty3, 60, 50);
  fill(36, 118, 12);
  rect(595, ty3-40, 10, 20);
  // update the balls position if they have not been hit
  if (stopB1 == false) {
    ty1 = ty1 + 10;
  }
  if (stopB2 == false) {
    ty2 = ty2 + 8;
  }
  if (stopB3 == false) {
    ty3 = ty3 + 7;
  }

  //wrap around to top if the balls hit the bottom
  if (ty1 > height) {
    ty1 = 0;
  }
  if (ty2 > height) {
    ty2 = 0;
  }
  if (ty3 > height) {
    ty3 = 0;
  }
}