Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F1))
        {
            debug = !debug;
        }

        if (debug)
        {
            //Test Power Ups
            if (Input.GetKeyDown(KeyCode.S))
            {
                ActivePowerUp(PoweUpType.STAR, 5.0f);
            }
            else if (Input.GetKeyDown(KeyCode.M))
            {
                ActivePowerUp(PoweUpType.METAL, 5.0f);
            }
            else if (Input.GetKeyDown(KeyCode.L))
            {
                ActivePowerUp(PoweUpType.SLOW, 5.0f, 2.0f);
                save_slow_reduced = 2.0f;
            }
            else if (Input.GetKeyDown(KeyCode.J))
            {
                ActivePowerUp(PoweUpType.SLOW, 5.0f, 2.0f);
                save_slow_reduced = 2.0f;
            }
        }

        switch (state)
        {
        case StatePlayer.IN_NODE:
        {
            if (startGame && !tutorial_active && evo_provider.show == false)
            {
                //Differentiate between SPACEBAR (PC Control) and SCREEN TOUCH (Mobile Control)
                if (Input.GetKeyDown(KeyCode.Space) || (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began))
                {
                    GetComponent <TrailRenderer>().enabled = true;
                    direction = next_position - initial_position;
                    GetComponent <Rigidbody>().AddForce(direction.normalized * (velocity + evo_controller.ExtraSpeed()) * Time.deltaTime, ForceMode.Impulse);

                    //Set animation to MOVING
                    GetComponent <Animator>().SetFloat("Speed", 1.0f);

                    state = StatePlayer.MOVING;
                }
            }
            break;
        }

        case StatePlayer.ARRIVE:
        {
            // Calcul next_position
            float distance = Vector3.Distance(transform.position, next_position);
            time_arrive += Time.deltaTime;
            bool force_arrive = false;
            if (time_arrive >= 1.0f)
            {
                force_arrive = true;
            }
            if (distance_arrive >= distance && force_arrive == false)
            {
                distance_arrive = distance;
            }
            else
            {
                time_arrive        = 0.0f;
                transform.position = next_position;
                state = StatePlayer.IN_NODE;
                GetComponent <Rigidbody>().velocity = Vector3.zero;
                camera_go.GetComponent <CameraController>().MoveCamera(transform);
                source.PlayOneShot(NodeSound);
                //Call ReserchNextNode
                if (isReturn == false)
                {
                    nodeManager.UpdateSectableNodes();

                    //Restart Color Charges
                    evo_controller.RestartColorCharges();

                    score.AddScore(ScoreType.ARRIVE_NODE);
                }

                isReturn         = false;
                initial_node     = nodeManager.GetCurrentNode();
                next_node        = nodeManager.GetNextNode();
                initial_position = initial_node.transform.position;
                next_position    = next_node.transform.position;

                //Update Arrow direction
                target_controller.SetTarget(next_node.transform);

                //Set animation to Idle
                GetComponent <Animator>().SetFloat("Speed", 0.0f);
            }
            break;
        }

        case StatePlayer.MOVING:
        {
            break;
        }

        case StatePlayer.RETURN:
        {
            GetComponent <Rigidbody>().AddForce((initial_node.transform.position - transform.position).normalized * velocity * 2 * Time.deltaTime, ForceMode.Force);
            break;
        }

        case StatePlayer.DYING:
        {
            //......
            if (transform.position.y <= -5)
            {
                initial_node     = nodeManager.GetCurrentNode();
                next_node        = nodeManager.GetNextNode();
                initial_position = initial_node.transform.position;
                next_position    = next_node.transform.position;
                GetComponent <Rigidbody>().useGravity = false;
                GetComponent <Rigidbody>().velocity   = Vector3.zero;
                transform.position = initial_position;
                //Update Arrow direction
                target_controller.SetTarget(next_node.transform);

                //Set animation to Idle
                GetComponent <Animator>().SetBool("Hit", false);
                UI_Menu.GetComponent <UI_Game>().Score_window(score.GetScore());
                state = StatePlayer.IN_NODE;
                gameObject.SetActive(false);
            }
            break;
        }
        }

        // METALLIC BALL POWER UP -------------------
        if (armor_active)
        {
            if (evo_provider.show == false && tutorial_active == false)
            {
                current_time_armor += Time.deltaTime;

                //Update HUD
                powerup_bar.fillAmount = 1 - (current_time_armor / duration_armor);
            }

            if (current_time_armor >= duration_armor)
            {
                current_time_armor = 0.0f;
                armor_active       = false;

                script_star.GetComponent <Renderer>().material           = normal_mat;
                script_star.GetComponent <ScrollingUVs_Layers>().enabled = false;
                //Disable HUD
                DisablePowerUpHUD(PoweUpType.METAL);
            }
        }
        // -------------------------------------------

        // STAR POWER UP -----------------------------
        if (star_active)
        {
            if (evo_provider.show == false && tutorial_active == false)
            {
                current_time_star += Time.deltaTime;

                //Update HUD
                powerup_bar.fillAmount = 1 - (current_time_star / duration_star);
            }

            if (current_time_star >= duration_star)
            {
                current_time_star = 0.0f;
                star_active       = false;

                script_star.GetComponent <Renderer>().material           = normal_mat;
                script_star.GetComponent <ScrollingUVs_Layers>().enabled = false;
                //Disable HUD
                DisablePowerUpHUD(PoweUpType.STAR);
            }
        }
        // --------------------------------------------

        // STAR POWER UP -----------------------------
        if (slow_active)
        {
            if (evo_provider.show == false && tutorial_active == false)
            {
                current_time_slow += Time.deltaTime;

                //Update HUD
                powerup_bar.fillAmount = 1 - (current_time_slow / duration_slow);
            }

            if (current_time_slow >= duration_slow)
            {
                source.PlayOneShot(Accelerate);
                camerasource.pitch = 1.0f;
                slow_active        = false;
                current_time_slow  = 0.0f;
                script_star.GetComponent <Renderer>().material           = normal_mat;
                script_star.GetComponent <ScrollingUVs_Layers>().enabled = false;
                //Disable HUD
                nodeManager.GetComponent <NodeManager>().ResetObstaclesSpeed();
                DisablePowerUpHUD(PoweUpType.SLOW);
            }
        }
        // --------------------------------------------
    }