import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class Only_One extends PApplet {

int tam;
int nbol = 0;
int fase = 1;
int time = 0;
int ltc = 150;
int [] bkg = {240, 240, 240};
String tecla = "none";
int[][] col = {{231, 76, 60}, {142, 68, 173}, {52, 152, 219}, {46, 204, 113}, {241, 196, 15}};
Bola b1;
Bola b2;
Bola b3;
Bola b4;
Bola b5;

public void setup() {
  
  //size(1240, 720);

  b1 = new Bola();
  b2 = new Bola();
  b3 = new Bola();
  b4 = new Bola();
  b5 = new Bola();
}
int a=0;
public void draw() {
  background(bkg[0], bkg[1], bkg[2]);   
  if (width < height) {
    tam = width/10;
  } else {
    tam = height/10;
  }
  fill(ltc);
  noStroke();
  rect(width-tam, tam*0.5f, tam*0.5f, tam*0.5f);


  if (fase == 1) {
    textAlign(CENTER);
    textSize(tam*0.5f);
    text("This game has no sound, just take off your headphones...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>1000 && mousePressed) {
      time = millis();
      fase = 2;
    }
  }

  if (fase == 2) {
    textSize(tam*0.5f);
    text("...open your room's window...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 3;
    }
  }

  if (fase == 3) {
    textSize(tam*0.5f);
    text("...and enjoy the sound of the birds, the wind, the rain...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 4;
    }
  }

  if (fase == 4) {
    textSize(tam*0.5f);
    text("...or even the cars.", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 5;
    }
  }

  if (fase == 5) {
    textSize(tam*0.5f);
    text("And think...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 6;
    }
  }

  if (fase == 6) {
    textSize(tam*0.5f);
    text("...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 7;
    }
  }

  if (fase == 7) {
    textSize(tam*0.5f);
    text(" ", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 8;
    }
  }

  if (fase == 8) {
    textSize(tam*0.5f);
    text("What if you had to choose just one color...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+1000 && mousePressed) {
      time = millis();
      fase = 9;
    }
  }

  if (fase == 9) {

    if (millis()>time+2000 && millis()<time+5000) {
      textAlign(CENTER);
      textSize(tam*0.5f);
      text("There is no need to hurry.", width*0.5f, height*0.3f);
    }
    if (millis()>time+6000 && millis()<time+10000) {
      text("You can play with them first if you want.", width*0.5f, height*0.3f);
    }   
    if (millis()>time+11000 && millis()<time+15000) {
      textSize(tam*0.3f);
      textAlign(RIGHT);
      text("Clic and hold to make happy moves.", width-width*0.1f, height-height*0.1f);
    }
    if (millis()>time+16000 && millis()<time+20000) {     
      text("Press the square to reset the positions.", width-width*0.1f, height-height*0.1f);
    }    
    if (millis()>time+22000 && millis()<time+26000) {
      textAlign(CENTER);
      textSize(tam*0.5f);
      text("This is an important decision.", width*0.5f, height*0.3f);
    }      
    if (millis()>time+27000 && millis()<time+29000) {     
      text("Choose wisely.", width*0.5f, height*0.3f);
    }      
    if (millis()>time+32000) {  
      textSize(tam*0.3f);
      text("Place the cursor on the one you want and press the SPACE BAR when you are ready.", width*0.5f, height*0.3f);
    }  


    b1.display(width*0.3f, height*0.45f, col[0], 1);
    b2.display(width*0.4f, height*0.45f, col[1], 2);
    b3.display(width*0.5f, height*0.45f, col[2], 3);
    b4.display(width*0.6f, height*0.45f, col[3], 4);
    b5.display(width*0.7f, height*0.45f, col[4], 5);
  }

  if (fase == 10) {
    fill(ltc);

    textAlign(CENTER);
    textSize(tam*0.5f);
    text("Are you sure?", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 11;
    }
  }

  if (fase == 11) {
    textSize(tam*0.5f);
    text("...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 12;
    }
  }

  if (fase == 12) {
    textSize(tam*0.5f);
    text("Hahahaha", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 13;
    }
  }

  if (fase == 13) {
    textSize(tam*0.7f);
    text("I DON´T CARE.", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 14;
    }
  }

  if (fase == 14) {
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 15;
    }
  }

  if (fase == 15) {
    textSize(tam*0.5f);
    text("Just one more one thing.", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 16;
    }
  }

  if (fase == 16) {
    textSize(tam*0.5f);
    text("Next time you go to sleep...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 17;
    }
  }

  if (fase == 17) {
    textSize(tam*0.5f);
    text("...think on those poor little colors...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 18;
    }
  }

  if (fase == 18) {
    textSize(tam*0.5f);
    text("...which have been excluded.", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 19;
    }
  }

  if (fase == 19) {
    textSize(tam*0.5f);
    text("What if they were not just colors...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 20;
    }
  }

  if (fase == 20) {
    textSize(tam*0.5f);
    text("...but books, movies, or games.", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 21;
    }
  }

  if (fase == 21) {
    textSize(tam*0.5f);
    text("Or worse.", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 22;
    }
  }

  if (fase == 22) {
    textSize(tam*0.5f);
    text("What if they had been religions, sexualities, idiologies...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 23;
    }
  }

  if (fase == 23) {
    textSize(tam*0.5f);
    text("...or people, family, friends.", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 24;
    }
  }

  if (fase == 24) {
    textSize(tam*0.5f);
    text(" ", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 25;
    }
  }
  if (fase == 25) {
    textSize(tam*0.5f);
    text("Take your time to think...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 26;
    }
  }
  if (fase == 26) {
    textSize(tam*0.5f);
    text("That's always good.", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 27;
    }
  }


  if (fase == 27) {
    textSize(tam*0.4f);
    text("Thanks for playing.", width*0.5f, height*1.15f-a);

    textSize(tam*0.5f);
    text("A jammy game made by:", width*0.5f, height*1.35f-a);
    text("Gonzalo Ortega", width*0.5f, height*1.45f-a);

    textSize(tam*0.2f);
    text("Don't hesitate to replay and experiment with the game to find the happy ending.", width*0.5f, height*1.55f-a);
    if (height*1.55f-a < -100) {
      exit();
    }
    a++;
  }

  if (tecla == "space" && (mouseX>width-tam) && (mouseX<width-tam+tam*0.5f) &&
    (mouseY>tam*0.5f) && (mouseY<tam*0.5f+tam*0.5f)) {
    time = millis();
    fase = 91;
  }

  if (fase == 91) {
    textSize(tam*0.5f);
    ltc = 150;
    bkg[0] = 240;
    bkg[1] = 240;
    bkg[2] = 240;
    text("What have you DONEEEE!!!", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 92;
    }
  }

  if (fase == 92) {
    ltc = 50;
    bkg[0] = 231;
    bkg[1] = 76;
    bkg[2] = 60;
    textSize(tam*0.5f);
    text("...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 93;
    }
  }

  if (fase == 93) {
    bkg[0] = 142;
    bkg[1] = 68;
    bkg[2] = 173;
    textSize(tam*0.5f);
    text("...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 94;
    }
  }

  if (fase == 94) {
    bkg[0] = 52;
    bkg[1] = 152;
    bkg[2] = 219;
    textSize(tam*0.5f);
    text("...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 95;
    }
  }

  if (fase == 95) {
    bkg[0] = 46;
    bkg[1] = 204;
    bkg[2] = 113;
    textSize(tam*0.5f);
    text("...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 96;
    }
  }

  if (fase == 96) {
    bkg[0] = 241;
    bkg[1] = 196;
    bkg[2] = 15;
    textSize(tam*0.5f);
    text("...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 97;
    }
  }

  if (fase == 97) {
    ltc = 150;
    bkg[0] = 240;
    bkg[1] = 240;
    bkg[2] = 240;
    textSize(tam*0.5f);
    text("I see...", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 98;
    }
  }

  if (fase == 98) {
    fill(231, 76, 60);
    rect(0, 0, width*0.2f, height);
    fill(142, 68, 173);
    rect(width*0.2f, 0, width*0.2f, height);
    fill(52, 152, 219);
    rect(width*0.4f, 0, width*0.2f, height);
    fill(46, 204, 113);
    rect(width*0.6f, 0, width*0.2f, height);
    fill(241, 196, 15);
    rect(width*0.8f, 0, width*0.2f, height);

    fill(50);
    textSize(tam*0.5f);
    text("You don't want to exclude anyone.", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 99;
    }
  }

  if (fase == 99) {
    fill(231, 76, 60);
    rect(0, 0, width*0.2f, height);
    fill(142, 68, 173);
    rect(width*0.2f, 0, width*0.2f, height);
    fill(52, 152, 219);
    rect(width*0.4f, 0, width*0.2f, height);
    fill(46, 204, 113);
    rect(width*0.6f, 0, width*0.2f, height);
    fill(241, 196, 15);
    rect(width*0.8f, 0, width*0.2f, height);

    fill(50);
    textSize(tam*0.5f);
    text("It's a nice choice.", width*0.5f, height*0.3f);
    textSize(tam*0.2f);
    text("clic", width*0.5f, height*0.4f);
    if (millis()>time+500 && mousePressed) {
      time = millis();
      fase = 100;
    }
  }

  if (fase == 100) {
    fill(231, 76, 60);
    rect(0, 0, width*0.2f, height);
    fill(142, 68, 173);
    rect(width*0.2f, 0, width*0.2f, height);
    fill(52, 152, 219);
    rect(width*0.4f, 0, width*0.2f, height);
    fill(46, 204, 113);
    rect(width*0.6f, 0, width*0.2f, height);
    fill(241, 196, 15);
    rect(width*0.8f, 0, width*0.2f, height);

    fill(50);
    textSize(tam*0.4f);
    text("Thanks for playing.", width*0.5f, height*1.15f-a);

    textSize(tam*0.5f);
    text("A jammy game made by:", width*0.5f, height*1.35f-a);
    text("Gonzalo Ortega", width*0.5f, height*1.45f-a);

    if (height*1.45f-a < -100) {
      exit();
    }
    a++;
  }
}

public void keyPressed() {
  if (key==' ') {
    tecla = "space";
  } else {
    tecla = "none";
  }
}
public void keyReleased() {
  tecla = "none";
}
class Bola {
  float x2 = 0;
  float y2 = 0;
  int select = 0;

  Bola() {
  }

  public void display(float x0, float y0, int[] c, int num) {
    noStroke();
    //println(num + " - " + nbol + " " + select);
    if (mousePressed && (mouseX>width-tam) && (mouseX<width-tam+tam*0.5f) &&
      (mouseY>tam*0.5f) && (mouseY<tam*0.5f+tam*0.5f)) {
      select = 0;
      ltc = 150;
      bkg[0] = 240;
      bkg[1] = 240;
      bkg[2] = 240;
      nbol = 0;
    }

    if (select == 0) {
      fill(ltc, 50);
      ellipse(x0, y0, tam*1.10f, tam*1.10f);
      fill(c[0], c[1], c[2]);
      ellipse(x0, y0, tam, tam);
      if (mousePressed && nbol == 0 && (mouseX>x0-tam*0.5f) && (mouseX<x0+tam*0.5f) &&
        (mouseY>y0-tam*0.5f) && (mouseY<y0+tam*0.5f)) {
        select = 1;
      }
    }

    if (select == 1) {
      nbol = num;
      x2 = mouseX;
      y2 = mouseY;
      fill(ltc, 50);
      ellipse(x2, y2, tam*1.10f, tam*1.10f);
      fill(c[0], c[1], c[2]);
      ellipse(x2, y2, tam, tam);
      if (mousePressed == false) {
        select = 2;
        nbol = 0;
      }
    }

    if (select == 2) {
      fill(ltc, 50);
      ellipse(x2, y2, tam*1.10f, tam*1.10f);
      fill(c[0], c[1], c[2]);
      ellipse(x2, y2, tam, tam);
      if (mousePressed && nbol == 0 && (mouseX>x2-tam*0.5f) && (mouseX<x2+tam*0.5f) &&
        (mouseY>y2-tam*0.5f) && (mouseY<y2+tam*0.5f)) {
        select = 1;
      }
    }

    if (tecla == "space" && (mouseX>x2-tam*0.5f) && (mouseX<x2+tam*0.5f) &&
      (mouseY>y2-tam*0.5f) && (mouseY<y2+tam*0.5f)) {
      select = 3;
      bkg = c;
      ltc = 50;
      nbol = 0;
    }   
    if (tecla == "space" && (mouseX>x0-tam*0.5f) && (mouseX<x0+tam*0.5f) &&
      (mouseY>y0-tam*0.5f) && (mouseY<y0+tam*0.5f)) {
      select = 3;
      bkg = c;
      ltc = 50;
      nbol = 0;
    }   
    
    if (select == 3) {
      fill(ltc, 50);
      ellipse(x2, y2, tam*1.10f, tam*1.10f);
      fill(c[0], c[1], c[2]);
      ellipse(x2, y2, tam, tam);
      nbol = num;
      time = millis();
      fase = 10;
    }
  }
}
  public void settings() {  fullScreen(); }
  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "--present", "--window-color=#666666", "--hide-stop", "Only_One" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}
