Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        timer -= 1;
        if (timer <= 0)
        {
            timer = 0;
        }

        handleArrows();

        //GAME
        if (game_state == State.Game)
        {
            if (timer == 0)
            {
                timer = TIME_QUESTIONS;
                NewQuestion();
            }


            if ((Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.RightArrow)) && question_list.Count >= 1)
            {
                bool answer = handleAnswer();
                //if answer is right
                if (answer)
                {
                    lame.Right();
                    audio_manager.success.Play();
                }
                //if answer is wrong
                else
                {
                    lame.Wrong();
                    audio_manager.failure.Play();
                }
            }

            lame.UpdateHeight(question_list.Count);
        }


        //LOSE
        else if (game_state == State.Lose)
        {
            //[100, 95] lame fall
            if (timer >= 95 && timer <= 100)
            {
                lame.Fall((timer - 95) / (float)5);
            }

            if (timer == 95)
            {
                tete_galilee.tej();
                audio_manager.death.Play();
                audio_manager.coupe.Play();
            }

            if (timer == 0)
            {
                game_state = State.Reload;
                timer      = 200;
            }
        }

        //INTRO1
        else if (game_state == State.Intro)
        {
            float sy = Screen.height / 100f;
            int   a  = 0;
            int   b  = 0;

            //FONDU
            a = 300;
            b = 200;
            if (timer <= a && timer >= b)
            {
                float lambda_fondu = (timer - b) / (float)(a - b);
                title.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 1 - lambda_fondu);
            }
            //SIGNATURES
            //from -7 to -3.5
            a = 200;
            b = 100;
            if (timer <= a && timer >= b)
            {
                float lambda_names = (timer - b) / (float)(a - b);
                float y_names      = lambda_names * (-7) + (1 - lambda_names) * (-3.5f);
                names.transform.localPosition = new Vector3(0, y_names, 0);
            }

            if (timer == 0)
            {
                game_state = State.BoxIntro;
                timer      = 50;
            }
        }
        //BOXINTRO
        else if (game_state == State.BoxIntro)
        {
            if (timer == 0 && question_list.Count == 0)
            {
                audio_manager.bouip.Play();
                Question q = Instantiate <Question>(question_prefab, new Vector3(0, -60, 0), Quaternion.identity);
                q.transform.SetParent(questions_pointer.transform, false);
                q.Initialiaze("Voulez-vous jouer ?", "Oui", "Non", 1);
                question_list.Add(q);
            }

            if ((Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.RightArrow)) && question_list.Count >= 1)
            {
                bool answer = handleAnswer();
                if (answer)
                {
                    audio_manager.fondreClavecin();
                    audio_manager.success.Play();
                    game_state = State.Intro2;
                    timer      = 200;
                }
                else
                {
                    timer = 50;
                    audio_manager.failure.Play();
                }
            }
        }

        //INTRO2
        else if (game_state == State.Intro2)
        {
            //[200-]
            float sy     = Screen.height / 100f;
            int   a      = 200;
            int   b      = 0;
            float lambda = timer / (float)(a - b);

            if (timer <= a && timer >= b)
            {
                float intro_h = (1 - lambda) * (3 * sy) + lambda * (0);
                intro_object.transform.position = new Vector3(0, intro_h, 0);
                float background_h = (1 - lambda) * 0 + lambda * (-2 * sy);
                background.transform.position = new Vector3(0, background_h, 0);
                float foreground_h = (1 - lambda) * 0 + lambda * 2 * (-2 * sy);
                foreground.transform.position = new Vector3(0, foreground_h, 0);
                float nuage_h = (1 - lambda) * 0 + lambda * 0.8f * (-2 * sy);
                nuage.transform.position = new Vector3(0, nuage_h, 0);
            }

            if (timer == 0)
            {
                game_state = State.Game;
                audio_manager.musique_stressante.Play();
            }
        }

        //RELOAD
        else if (game_state == State.Reload)
        {
            float sy = Screen.height / 100f;
            int   a  = 200;
            int   b  = 0;

            float lambda = (timer - b) / (float)(a - b);
            lambda = 1 - lambda;

            float intro_h = (1 - lambda) * (3 * sy) + lambda * (0);
            intro_object.transform.position = new Vector3(0, intro_h, 0);
            float background_h = (1 - lambda) * 0 + lambda * (-2 * sy);
            background.transform.position = new Vector3(0, background_h, 0);
            float foreground_h = (1 - lambda) * 0 + lambda * 2 * (-2 * sy);
            foreground.transform.position = new Vector3(0, foreground_h, 0);

            float nuage_h = (1 - lambda) * 0 + lambda * 0.8f * (-2 * sy);
            nuage.transform.position = new Vector3(0, nuage_h, 0);

            if (timer == 150)
            {
                audio_manager.musique_clavecin.Play();
            }

            if (timer == 0)
            {
                //reset all
                lame.Init();
                bourreau.setActive(false);
                game_state = State.BoxIntro;

                question_down = null;

                tete_galilee.Reinitialize();
                TIME_QUESTIONS = 400;
                audio_manager.boo.Stop();
            }
        }
    }