Exemplo n.º 1
0
    // Update is called once per frame
    private void Update()
    {
        if (m_PlayerState == State.Intro)
        {
            return;
        }

        //Pressed down left/right/up arrows:
        //1) Change orientation
        //2) Move left/right/up
        //3) Change state to flight
        //4) If going left/right offset scrolling background

        //float pivotXStep = 0f;
        //float pivotYStep = 0f;
        //float pivotYSpeed = 6f;
        //float pivotXSpeed = 10f;

        State nextState = State.None;

        //if (Input.GetKey(KeyCode.LeftArrow))
        //{
        //    m_DisplayLookXScale = -1f;
        //    nextState = State.Flight;
        //    pivotXStep = -pivotXSpeed * Time.deltaTime;
        //    pivotYStep = -pivotYSpeed * Time.deltaTime * .25f;
        //    m_BackgroundScroller.SetXMoveStep(-pivotXStep * .8f);
        //}
        //if (Input.GetKey(KeyCode.RightArrow))
        //{
        //    m_DisplayLookXScale = 1f;
        //    nextState = State.Flight;
        //    pivotXStep = pivotXSpeed * Time.deltaTime;
        //    pivotYStep = -pivotYSpeed * Time.deltaTime * .25f;
        //    //m_BackgroundScroller.SetXMoveStep(-pivotXStep * .8f);
        //}
        //if(Input.GetKeyDown(KeyCode.LeftShift))
        //{
        //    m_InFlightBurst = !m_InFlightBurst;
        //}
        //if(m_InFlightBurst)
        //{
        //    nextState = State.Flight;
        //    pivotYStep = pivotYSpeed * Time.deltaTime;
        //}
        //if(nextState == State.None)
        //{
        //    nextState = State.Idle;
        //    pivotYStep = -pivotYSpeed * Time.deltaTime * .25f;
        //}

        if (m_GridMoveSequence == null)
        {
            int gridCol = m_CurrentGridCol;
            int gridRow = m_CurrentGridRow;
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                gridCol = Mathf.Max(gridCol - 1, 0);
            }
            else if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                gridCol = Mathf.Min(gridCol + 1, m_WorldGrid.GridColCount - 1);
            }
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                gridRow = Mathf.Min(gridRow + 1, m_WorldGrid.GridRowCount - 1);
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                gridRow = Mathf.Max(gridRow - 1, 0);
            }

            if (gridCol != m_CurrentGridCol || gridRow != m_CurrentGridRow)
            {
                m_CurrentGridRow = gridRow;
                m_CurrentGridCol = gridCol;
                HandleGridUpdate(m_CurrentGridRow, m_CurrentGridCol);

                float lookAngle = 0f;
                if ((m_CurrentGridRow == 0 && m_CurrentGridCol == 0) ||
                    m_CurrentGridRow == 1 && m_CurrentGridCol == m_WorldGrid.GridColCount - 1)
                {
                    lookAngle = -45f;
                }
                if ((m_CurrentGridRow == 0 && m_CurrentGridCol == m_WorldGrid.GridColCount - 1) ||
                    (m_CurrentGridRow == 1 && m_CurrentGridCol == 0))
                {
                    lookAngle = 45f;
                }

                transform.DORotate(new Vector3(0f, 0f, lookAngle), .5f);
            }
        }

        m_DisplayLookYScale = m_CurrentGridRow == 0 ? 1 : -1;

        //m_BackgroundScroller.SetScrollSpeed(m_IdleScrollSpeed + GetPivotYPercentFromIdle() * m_FlyForwardScrollSpeed);
        m_BackgroundScroller.SetScrollSpeed(m_IdleScrollSpeed);

        //HandlePivotXStep(pivotXStep);
        //HandlePivotYStep(pivotYStep);

        m_DisplayRoot.localScale = new Vector3(m_DisplayLookXScale, m_DisplayLookYScale, 1f);

        if (nextState == m_PlayerState)
        {
            return;
        }

        //An actual state change is needed
        m_PlayerState = nextState;

        //After state switching, check to see what kind of animation state change is needed
        switch (m_PlayerState)
        {
        case State.Idle:
            m_Animations.Play("Idle");
            break;

        case State.Flight:
            m_Animations.Play("Flight");
            break;
        }
    }