Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (theBall == null)
        {
            //hint: if your game UI never displays, you might want to check this condition somehow...
            return;
        }

        switch (theGameState)
        {
        case GameStates.GS_INITIALIZATION:
            //calculate information about the hill
            HILL_HALF_WIDTH = HILL_UNSCALED_HALF_WIDTH * theHill.transform.localScale.x;

            Restart();                          //needed to avoid a race condition with the ball's Start() function
            break;

        case GameStates.GS_USER_INPUT:

            //increase or decreate the cannon's elevation by a rate of 10 degrees per second
            if (Input.GetKey(KeyCode.UpArrow))
            {
                theCannon.localElevationAngle = Mathf.Min(90.0f, theCannon.localElevationAngle + 10.0f * Time.deltaTime);
            }
            if (Input.GetKey(KeyCode.DownArrow))
            {
                theCannon.localElevationAngle = Mathf.Max(0.0f, theCannon.localElevationAngle - 10.0f * Time.deltaTime);
            }

            //increase or decreate the cannon's angle by a rate of 10 degrees per second
            if (Input.GetKey(KeyCode.RightArrow))
            {
                theCannon.localRotationAngle = Mathf.Min(60.0f, theCannon.localRotationAngle + 10.0f * Time.deltaTime);
            }
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                theCannon.localRotationAngle = Mathf.Max(-60.0f, theCannon.localRotationAngle - 10.0f * Time.deltaTime);
            }

            theBall.SimulateFlight(theCannon);

            //check for game start
            if (Input.GetKeyDown(KeyCode.Space))
            {
                Vector3 spawnPos = new Vector3(0, 0, 0);
                theCannon.GetSpawnBallPosition(out spawnPos);
                theBall.ApplyMovement(spawnPos);
                theBall.LaunchBall(theCannon.localElevationAngle, theCannon.localRotationAngle);
                theGameState = GameStates.GS_GAME_IN_PROGRESS;
            }
            break;

        case GameStates.GS_GAME_IN_PROGRESS:
            break;

        case GameStates.GS_ENDGAME_VICTORY:

            //check for new game
            if (Input.GetKeyDown(KeyCode.Space))
            {
                Restart();
            }
            break;

        case GameStates.GS_ENDGAME_DEFEAT:

            //check for new game
            if (Input.GetKeyDown(KeyCode.Space))
            {
                Restart();
            }
            break;
        }
    }