Пример #1
0
    public void CheckSwipe()
    {
        //Aqui checa-se se existe exatamente um dedo ativo na tela
        if (Touch.activeFingers.Count == 1)
        {
            Touch activeTouch = Touch.activeFingers[0].currentTouch;

            //O código so continua caso o toque esteja em sua fase final ("Ended")
            if (activeTouch.phase != TouchPhase.Ended)
            {
                return;
            }

            //As diferenças entre os valores inicial e final de X e Y são calculadas
            float difX = activeTouch.screenPosition.x - activeTouch.startScreenPosition.x;
            float difY = activeTouch.screenPosition.y - activeTouch.startScreenPosition.y;

            //Aqui é checado qual deslocamento no eixo foi maior
            //Caso o maior seja X, o código detecta esquerda ou direita
            //Caso o maior seja Y, o código detecta baixo ou cima
            if (Mathf.Abs(difX) > Mathf.Abs(difY))
            {
                //Aqui checa-se se difX é positivo ou negativo
                if (difX < -swipeOffset)
                {
                    //CHAMAR AQUI COMANDOS PARA SWIPE ESQUERDO
                    //Debug.LogWarning("ESQUERDA");
                    StartCoroutine(fightManagerScript.PerformMove(Move.ESQUERDA));
                }
                else if (difX > swipeOffset)
                {
                    //CHAMAR AQUI COMANDOS PARA SWIPE DIREITO
                    //Debug.LogWarning("DIREITA");
                    StartCoroutine(fightManagerScript.PerformMove(Move.DIREITA));
                }
            }
            else
            {
                //Aqui checa-se se difY é positivo ou negativo
                if (difY < -swipeOffset)
                {
                    //CHAMAR AQUI COMANDOS PARA SWIPE PARA BAIXO
                    //Debug.LogWarning("BAIXO");
                    StartCoroutine(fightManagerScript.PerformMove(Move.BAIXO));
                }
                else if (difY > swipeOffset)
                {
                    //CHAMAR AQUI COMANDOS PARA SWIPE PARA CIMA
                    //Debug.LogWarning("CIMA");
                    StartCoroutine(fightManagerScript.PerformMove(Move.CIMA));
                }
            }
        }
    }
Пример #2
0
    //Este método aplica a chance de acerto para acerto ou erro do golpe
    public void CalculateMove()
    {
        Move toPerform = new Move();
        Move nextValid = new Move();

        //Checa-se os tamanhos das listas de golpes
        if (fightManagerScript.tempMoves.Count < fightManagerScript.fightMoves.Count)
        {
            //O golpe na lista verdadeira no índice equivalente ao tamanho da lista temporária é atribuído à variável local
            nextValid = fightManagerScript.fightMoves[fightManagerScript.tempMoves.Count];

            //O valor aleatório é sorteado
            float prob = Random.Range(0f, 100f);

            //Caso ele seja menor ou igual à chance de acerto, o lutador acertará o golpe
            if (prob <= hitChance)
            {
                //E a variável "toPerform" recebe o próximo golpe corretamente
                toPerform = nextValid;
            }
            else
            {
                //Caso contrário, o golpe será errado e "toPerform" recebe outro golpe aleatório
                while (toPerform == nextValid)
                {
                    toPerform = (Move)Random.Range(0, 4);
                }
            }
        }
        else
        {
            //Caso as listas tenham o mesmo tamanho, "toPerform" recebe um valor aleatório
            toPerform = (Move)Random.Range(0, 4);
        }

        //O golpe é executado e a chance de acertar o próximo diminui de acordo com "decreaseChanceByMove"
        StartCoroutine(fightManagerScript.PerformMove(toPerform));
        hitChance -= decreaseChanceByMove;

        if (fightManagerScript.fightMoves.Count == 0)
        {
            hitChance = inicialHitChance;
        }
    }