> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.BM9sPG1pqB7/rev.108
 * 
 * authors: 
 *   James Y.
 *   Nicole Agcaoili
 *   vanessa
 *   Brian C.

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



/*Prototype
 This is the code that makes things fall without things falling
 at the same time at the same speed
 */
boolean upPressed, downPressed, leftPressed, rightPressed,rPressed;
ball[] jellyfish;
PImage character, SC1, EndSC;
PFont chiller;
int screenNumber;
void setup()
{
  frameRate(60);
  smooth();
  size(700, 700); 
  imageMode(CENTER);
  chiller = loadFont("Chiller-Regular-50.vlw");
  textFont(chiller,50);
  SC1 = loadImage("SC1.gif");
  EndSC = loadImage("EndSC.gif");
  jellyfish = new ball[10];
  for(int i = 0; i<10; i++)
  {
    jellyfish[i] = new ball();
    jellyfish[i].a = (int)random(0,650);
    jellyfish[i].b = (int)random(-250,-50);
    jellyfish[i].speed = (int)random(0,5);
    jellyfish[i].x = width/2;
    jellyfish[i].y = width/2;
    jellyfish[i].score = 0;
    jellyfish[i].life = 5;
    jellyfish[i].speed2 = 10;
  }
  //  x = y = width/2;
  screenNumber = 1;
}

void draw()
{
  background(0);
  if (screenNumber == 1)
  {
    image(SC1,350,350);
    if (mousePressed) screenNumber = 2;
  }

  if (screenNumber == 2)
  {
    background(0); 
    checkLifeLost();
    for(int i = 0; i<jellyfish.length; i++)
    {
      jellyfish[i].show();
      jellyfish[i].checkCollisionJelly();
      jellyfish[i].charInside();
      text("Score:"+jellyfish[i].score,20,30);
      text("Lives:"+jellyfish[i].life,550,30);
    }
  }
  if (screenNumber == 3)
  {
    image(EndSC,350,350);
    if (rPressed) screenNumber = 2;
  }
}



void checkLifeLost()
{

  /*if (life == 0)
  {
    screenNumber = 3;
  }*/
}

class ball
{
  float a, b, x, y;
  int speed, speed2, life;
  int score;



  void show()
  {
    fill(252,175, 246);
    ellipse(a,b, 50,50);
    fill(255, 255,0);
    fill(0);
    ellipse(a+9, b-4, 8, 15);
    ellipse(a-9, b-4, 8,15);
    fill(255);
    ellipse(a-9, b-6, 5,9);
    ellipse(a+9, b-6, 5,9);
    fill(161,159,247);

    //main character
    fill(250, 250, 140);
    rect(x-27,y,54,35);
    fill(250,250,140);
    ellipse(x,y, 54,44);
    fill(0);
    ellipse(x-10,y, 3,3);
    ellipse(x+10,y, 3,3);
    fill(250,250, 140);
    noStroke();

    ellipse(x-22, y+31, 10, 27);
    ellipse(x+22, y+31, 10,27);
    ellipse(x-7, y+31, 10,27);
    ellipse(x+7, y+31, 10, 27);

    if (rightPressed) x += speed2;
    if (leftPressed)  x -= speed2;
    if (upPressed)    y -= speed2;
    if (downPressed)  y += speed2;


    if (b > 700)
    {
      b = (int)random(-250,-50);
      life = life - 1;
      a = random(700);
    }
    b += speed;
  }
  void checkCollisionJelly()
{  
    if(dist(x,y,a,b)<(50))
    {
     score = score +1;
    }
}
void charInside()
{
  if( x > width ) x = x-width;
  if( y > height ) y = y-height;
  if( x < 0 ) x = x+width;
  if( y < 0 ) y = y+height;
}
}

void keyPressed()
{
  if (keyCode == UP) upPressed = true;
  if (keyCode == DOWN ) downPressed = true;
  if (keyCode == LEFT ) leftPressed = true;
  if (keyCode == RIGHT ) rightPressed = true;
  if (key == 'r' ) rPressed = true;
}

void keyReleased()
{
  if (keyCode == UP) upPressed = false;
  if (keyCode == DOWN ) downPressed = false;
  if (keyCode == LEFT ) leftPressed = false;
  if (keyCode == RIGHT ) rightPressed = false;
  if (key == 'r' ) rPressed = false;
}