// Update is called once per frame
    void Update()
    {
        switch (estado)
        {
        case EstadoDaqui.caindoBoss:
            TempoDecorrido += Time.deltaTime;
            if (TempoDecorrido < TEMPO_QUEDA_BOSS)
            {
                boss.transform.position = Vector3.Lerp(
                    posInicial,
                    posDeDeslinicialDoBoss.position,
                    ZeroOneInterpolation.PolinomialInterpolation(TempoDecorrido / TEMPO_QUEDA_BOSS, 8));
            }
            else
            {
                EventAgregator.Publish(new StandardSendGameEvent(EventKey.requestShakeCam, ShakeAxis.z, 10, 2f));
                EventAgregator.Publish(new StandardSendGameEvent(EventKey.disparaSom, SoundEffectID.pedrasQuebrando));
                boss.transform.position = posDeDeslinicialDoBoss.position;
                boss._Animator.SetTrigger("tocouChao");
                estado         = EstadoDaqui.animaIntimidacao;
                TempoDecorrido = 0;
            }
            break;

        case EstadoDaqui.particulaDaIntimidacao:
            TempoDecorrido += Time.deltaTime;
            if (TempoDecorrido > 0.25f)
            {
                InstanciaLigando.Instantiate(particulaEnfaseDoBoss, boss.transform.position, 5);
                EventAgregator.Publish(new StandardSendGameEvent(EventKey.disparaSom, somEnfaseDoBoss));
                EventAgregator.Publish(new StandardSendGameEvent(EventKey.requestLocalnameExibition, "O Grande Círculo Imperfeito", false, 2f));

                new MyInvokeMethod().InvokeNoTempoDeJogo(
                    () => {
                    EventAgregator.Publish(new StandardSendGameEvent(EventKey.startMusic, new NameMusicaComVolumeConfig()
                    {
                        Musica = NameMusic.XPboss3,
                        Volume = 1
                    }
                                                                     ));
                }, 1
                    );
                estado         = EstadoDaqui.gritando;
                TempoDecorrido = 0;
            }
            break;

        case EstadoDaqui.animaIntimidacao:
            TempoDecorrido += Time.deltaTime;
            if (TempoDecorrido > TEMPO_ATE_INTIMIDACAO)
            {
                TempoDecorrido = 0;
                boss._Animator.SetTrigger("preparaPulo");

                estado = EstadoDaqui.particulaDaIntimidacao;
            }
            break;

        case EstadoDaqui.gritando:
            TempoDecorrido += Time.deltaTime;
            if (TempoDecorrido > TEMPO_GRITANDO)
            {
                boss._Animator.SetTrigger("retornaAoPadrao");
                boss.IniciarBoss();
                EventAgregator.Publish(EventKey.finalizaDisparaTexto, null);
                estado = EstadoDaqui.iniciaLuta;
            }
            break;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (estado != EstadoDaqui.emEspera)
        {
            tempoDecorrido += Time.deltaTime;
            BaseMoveRigidbody.PositionWithAndador(andador, transform);
        }

        switch (estado)
        {
        case EstadoDaqui.pulinhosPreparatorios:
            #region pulinhosPreparatorios
            if (VerifiqueContFurias())
            {
                _Animator.SetTrigger("queda");
                InstanciaLigando.Instantiate(particulaEnfaseDoBoss, transform.position, 5);
                EventAgregator.Publish(new StandardSendGameEvent(EventKey.disparaSom, gritoDaFuria));
                EventAgregator.Publish(EventKey.abriuPainelSuspenso, null);
                estado = EstadoDaqui.prepararGiroDeFuria;
            }
            else
            if (tempoDecorrido > TEMPO_ENTRE_PULINHO && contDePulinhos < PULINHOS_ATE_ATAQUE)
            {
                int qual = Random.Range(0, uhuhah.Length);

                EventAgregator.Publish(new StandardSendGameEvent(EventKey.disparaSom, uhuhah[qual]));
                _Animator.SetTrigger("preparaPulo");
                estado         = EstadoDaqui.preparaPulinho;
                tempoDecorrido = 0;
            }
            else if (tempoDecorrido > TEMPO_ENTRE_PULINHO && contDePulinhos >= PULINHOS_ATE_ATAQUE)
            {
                int qual = Random.Range(0, 2);

                if (qual == 0)
                {
                    InstanciaLigando.Instantiate(
                        particulaDoAtaqueAlto,
                        particulaDoAtaqueAlto.transform.position, 5,
                        Quaternion.identity);

                    estado = EstadoDaqui.giroAlto;
                    PreparaParabolaLocal();
                }
                else if (qual == 1)
                {
                    EscolheDestino();
                    InstanciaLigando.Instantiate(particulaDoAtaqueReto, particulaDoAtaqueReto.transform.position, 5);
                    estado = EstadoDaqui.giroReto;
                }
                else
                {
                    Debug.Log("numero não esperado: " + qual);
                }

                EventAgregator.Publish(new StandardSendGameEvent(EventKey.disparaSom, urroDeAtaque));
                tempoDecorrido = 0;
            }
            #endregion
            break;

        case EstadoDaqui.prepararGiroDeFuria:
            #region preparandoGiroFuria
            if (tempoDecorrido > TEMPO_PREPARANDO_FURIA)
            {
                _Animator.SetTrigger("tocouChao");
                EventAgregator.Publish(EventKey.fechouPainelSuspenso);
                EscolheMelhorCantoAlto();
                estado         = EstadoDaqui.giroDeFuria;
                tempoDecorrido = 0;
                contDePulinhos = 0;
                indice         = 0;
                mov.ChangeGravityScale(0);
            }
            #endregion
            break;

        case EstadoDaqui.giroDeFuria:
            #region giroFuria
            andador.position = Vector3.Lerp(posInicial, targets[indice], velocidadeGiroFuria * tempoDecorrido / distancia);
            transform.Rotate(new Vector3(0, 0, 20));

            if (tempoDecorrido * velocidadeGiroFuria > distancia)
            {
                EventAgregator.Publish(new StandardSendGameEvent(EventKey.disparaSom, SoundEffectID.pedrasQuebrando));
                EventAgregator.Publish(new StandardSendGameEvent(EventKey.requestShakeCam, ShakeAxis.z, 5, 2f));
                tempoDecorrido = 0;
                posInicial     = targets[indice];
                indice         = ContadorCiclico.AlteraContador(1, indice, 4);
                contDePulinhos++;
            }

            if (contDePulinhos >= 19)
            {
                _Animator.SetTrigger("retornaAoPadrao");
                FinalizaGiro();
            }
            #endregion
            break;

        case EstadoDaqui.giroReto:
            #region giroReto
            if (tempoDecorrido > TEMPO_TELEGRAFANDO_GIRO + TEMPO_GIRO_ALTO)
            {
                FinalizaGiro();
                //mov.AplicadorDeMovimentos(Vector3.zero);
            }
            else if (tempoDecorrido > TEMPO_TELEGRAFANDO_GIRO)
            {
                float time = (tempoDecorrido - TEMPO_TELEGRAFANDO_GIRO) / TEMPO_GIRO_ALTO;

                transform.Rotate(new Vector3(0, 0, 20));

                andador.position = Vector3.Lerp(posInicial, target, ZeroOneInterpolation.PolinomialInterpolation(time, 2));
            }
            #endregion
            break;

        case EstadoDaqui.giroAlto:
            #region giroAlto
            if (tempoDecorrido > TEMPO_TELEGRAFANDO_GIRO + TEMPO_GIRO_ALTO)
            {
                FinalizaGiro();
                //mov.AplicadorDeMovimentos(Vector3.zero);
            }
            else if (tempoDecorrido > TEMPO_TELEGRAFANDO_GIRO)
            {
                float time = (tempoDecorrido - TEMPO_TELEGRAFANDO_GIRO) / TEMPO_GIRO_ALTO;

                transform.Rotate(new Vector3(0, 0, 20));
                andador.position = ZeroOneInterpolation.ParabolaDeDeslocamento(
                    new Vector2(posInicial.x, posInicial.y),
                    new Vector2(target.x, target.y),
                    new Vector2(vertice.position.x, vertice.position.y),
                    ZeroOneInterpolation.OddPolynomialInterpolation(time, 3));

                //Debug.Log(target.x+" : "+posInicial.x);
            }
            #endregion
            break;

        case EstadoDaqui.preparaPulinho:
            #region preparaPulinhos
            if (tempoDecorrido > TEMPO_PREPARANDO_PULINHO)
            {
                mov.JumpForce();
                _Animator.SetTrigger("disparaPulo");
                tempoDecorrido = 0;
                contDePulinhos++;
                estado = EstadoDaqui.atualizaPulinho;
            }
            #endregion
            break;

        case EstadoDaqui.atualizaPulinho:
            #region atualizaPulinhos
            if (tempoDecorrido > TEMPO_NO_PULINHO)
            {
                if (requisicaoDeEspinhos)
                {
                    lancados = new EspinhosDoCirculoImperfeito[conjuntoDeEspinhos.childCount];

                    for (int i = 0; i < conjuntoDeEspinhos.childCount; i++)
                    {
                        GameObject G = InstanciaLigando.Instantiate(conjuntoDeEspinhos.GetChild(i).gameObject,
                                                                    conjuntoDeEspinhos.GetChild(i).position, 10);

                        lancados[i] = G.GetComponent <EspinhosDoCirculoImperfeito>();
                    }

                    _Animator.SetTrigger("retornaAoPadrao");
                    _Animator.SetTrigger("queda");

                    EventAgregator.Publish(new StandardSendGameEvent(EventKey.disparaSom, preparaEspinhos));
                    estado = EstadoDaqui.preparaEspinhos;
                    requisicaoDeEspinhos = false;
                }
                else
                {
                    _Animator.SetTrigger("retornaAoPadrao");
                    estado = EstadoDaqui.pulinhosPreparatorios;
                }

                tempoDecorrido = 0;
            }
            #endregion
            break;

        case EstadoDaqui.preparaEspinhos:
            #region preparaEspinhos
            if (tempoDecorrido > TEMPO_PREPARANDO_ESPINHOS)
            {
                EventAgregator.Publish(new StandardSendGameEvent(EventKey.disparaSom, lancaEspinhos));
                _Animator.SetTrigger("tocouChao");
                mov.JumpForce();
                tempoDecorrido = 0;
                estado         = EstadoDaqui.lancaEspinhos;
            }
            #endregion
            break;

        case EstadoDaqui.lancaEspinhos:
            #region lancaEspinhos
            if (tempoDecorrido > TEMPO_PARA_LANCAR_ESPINHOS)
            {
                _Animator.SetTrigger("retornaAoPadrao");

                for (int i = 0; i < lancados.Length; i++)
                {
                    lancados[i].circulo.SetActive(false);
                    lancados[i].espinhos.SetActive(true);
                    lancados[i].particulaDosEspinhos.SetActive(true);
                }

                estado         = EstadoDaqui.pulinhosPreparatorios;
                tempoDecorrido = 0;
            }
            #endregion
            break;
        }
    }