
import controlP5.*;
import ddf.minim.*;
//-----------------------CurrentState-----------------------

State currentState;
//-----------------------CP5--------------------------------
ControlP5 cp5;
Button b;
int nButtons = 1;
String LoadMessages;
PFont font;
boolean[] firstInicialization;
PApplet app;
PImage sprite;
PlayState playState;

Minim minim;
AudioInput in;
void setup()
{
   //----------------------------------ControlP5---------------------------------
  cp5 = new ControlP5(this);
  reserveSpaceForButtons();
  // -------------------------------Screen*----------------------------
  size(1024, 768, P2D);
  smooth(3);
  surface.setResizable(true);
  background(0, 0, 0);
  noStroke();
  app = this;
  //----------------------------------Font-------------------------
  font = loadFont("SpaceFrigate-48.vlw");
    //--------------------------------Mic-------------------------------------
  minim = new Minim(this);
    in = minim.getLineIn();
  //-----------------------------------State--------------------
  currentState = new MainMenuState();
  currentState.setup();
 

}

void draw()
{
  currentState.draw();
}

void reserveSpaceForButtons()
{
  cp5 = new ControlP5(this);
  //b = new Button[nButtons];
  firstInicialization = new boolean[nButtons];  
  
  ControlFont buttonFont = new ControlFont(createFont("spacefr.ttf", 75));
  
  
  //----------------------------------ControlP5-----------------------------------
  firstInicialization[0] = true;
  b= cp5.addButton("Jugar", 0)
    .setColorActive(color(136,80,160)) // color for click
    .setColorBackground(color(160, 136, 216)) // default color
    .setColorForeground(color(136,80,160)) // color for mouse-over
    .setFont(buttonFont)
    .setValue(0)
    .setPosition(width/2-60*3, height*3/4)
    .setSize(width*3/9, height*1/9)
    ;
    
}

public void controlEvent(ControlEvent theEvent) 
{
  println(theEvent.getController().getName());
}
public void Jugar(int theValue) 
{
  if (!firstInicialization[theValue])
  {
    b.setVisible(false);
    //cp5.remove("Jugar");
    //currentState = new PlayState();
    playState = new PlayState();
    currentState = playState;
    
    currentState.setup();
  } else
  {
    firstInicialization[theValue] = false;
  }
}
void onTickEvent(CountdownTimer t, long timeLeftUntilFinish) 
{
  playState.onTickEvent(t, timeLeftUntilFinish);
}

void onFinishEvent(CountdownTimer t) 
{
  playState.onFinishEvent(t);
}