class Fade {
  float value;
  color c;
  float increment;

  boolean fading;
  boolean out;
  
  String effect;
  
  Fade(){
    value = 0;
    fading = false;
  }
  void start(float time, color c, String effect){
    increment = 1 / time;
    this.c = c;
    this.effect = effect;
    fading = true;
    out = true;
    
    value = 0;
  }
  void render(){
    fill(c, 255 * value);
    noStroke();
    rect(0,0,width,height);
  }
  void update(){
    if (fading){
      if (out){
        value += increment;
        if (value >=1){
          value = 1;
          checkEffect(effect);
          out = false;
        }
      }
      else{
        value -= increment;
        if (value <=0){
          value = 0;
          fading = false;
        }
      }
    }
  }
}

void checkEffect(String e){
  switch (e){
    case "intro":
      gameState = "intro";
      setBGM("mus_menu");
      break;
    case "startGame":
      startGame();
      break;
    case "nextRoom":
      level.nextRoom();
      break;
    case "gameOver":
      gameState = "gameOver";
      setBGM("mus_menu");
      break;
    case "endGame":
      gameState = "endGame";
      setBGM("mus_menu");
      break;
  }
}