Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
//		Debug.Log (gameOver);
        if (gameOver || gameWin)
        {
            return;
        }

        //if (Input.GetKeyDown(pauseKey)) {
        if (Input.GetButtonDown(pauseKey))
        {
            if (!gamePaused)
            {
                oldTimeScale = Time.timeScale;

                Time.timeScale = 0f;

                gameOverScreen.pause();

                gamePaused = true;
            }
            else
            {
                //Time.timeScale = oldTimeScale;

                // it will call Resume() indirectly
                gameOverScreen.resume();
            }
        }

        if (gamePaused)
        {
            return;
        }

        if (isLerping)
        {
            lerpTo(destination);
        }

        if (gameOver || rigidbody2D.isKinematic)
        {
            return;
        }
//		if(rigidbody2D.IsAwake())
//		{
//			rigidbody2D.Sleep();
//		}

        /*
         * if (Input.GetKey (jump)) {
         *      transform.rigidbody2D.AddForce (new Vector2 (50,jumpForce));
         * }
         */
        /*
         *      if (Input.GetKeyDown(jump)) {
         * if (energy > enUsage * Time.deltaTime) {
         * transform.rigidbody2D.AddForce(
         *              //new Vector2(50 * Time.deltaTime, jumpForce * Time.deltaTime));
         *              new Vector2(25, jumpForce));
         *
         * energy -= enUsage * Time.deltaTime;
         * if (energy <= 0f)
         *      energy = 0f;
         * }
         *      } else {
         * energy += enUsage * 0.375f * Time.deltaTime;
         * if (energy > maxEN) {
         * energy = maxEN;
         * }
         *      }
         *
         *      float percent = energy/maxEN;
         *      percent = Mathf.Sqrt(percent);
         *      renderer.material.SetColor("_Color",
         * new Color(0f, percent, percent));
         */
        //if (Input.GetKeyDown (jump)) {
        hasJumped = false;
        if (Input.GetButtonDown(jump))
        {
            if (jumpsLeft > 0)
            {
                hasJumped = true;
                Instantiate(shadow, transform.position, Quaternion.identity);
                //transform.rigidbody2D.velocity =  new Vector2(transform.rigidbody2D.velocity.x,(0.5f+((0.5f/noOfJumps)*jumpsLeft)*jumpSpeed));
                transform.rigidbody2D.velocity = new Vector2(transform.rigidbody2D.velocity.x, jumpSpeed);
                jumpsLeft--;
                foreach (Transform child in transform)
                {
                    if (child.gameObject.activeSelf)
                    {
                        child.gameObject.SetActive(false);
                        break;
                    }
                }
            }
        }


        if (transform.position.y < -10f || transform.position.y > 15f ||
            transform.position.x < -18f || transform.position.x > 18f)
        {
            //Application.LoadLevel (Application.loadedLevel);

            int       songIdx   = GameObject.Find("Control").GetComponent <ConfigLoader>().songIdx;
            float     highScore = PlayerPrefs.GetFloat("HighScore_" + songIdx.ToString());
            LevelText levelText = GameObject.Find("LevelGroup").GetComponent <LevelText>();

            if (score + levelText.percent / 100f > highScore)
            {
                highScore = score + levelText.percent / 100f;

                PlayerPrefs.SetFloat("HighScore_" + songIdx.ToString(),
                                     score + levelText.percent / 100f);
            }

            gameOver = true;
            rigidbody2D.isKinematic = true;
            rigidbody2D.Sleep();

            gameOverScreen.setScores(score + levelText.percent / 100f, highScore);
            gameOverScreen.flyIn(false);

            /*
             * int highScore = PlayerPrefs.GetInt ("HighScore");
             * if (score > highScore) {
             *      highScore = score;
             *      PlayerPrefs.SetInt ("HighScore", score);
             * }
             * gameOver = true;
             * //Deactivating rigidBody
             * rigidbody2D.isKinematic = true;
             * rigidbody2D.Sleep();
             * gameOverScreen.setScores (score, highScore);
             * gameOverScreen.flyIn (false);
             */
        }
    }