Esempio n. 1
0
    public bool CanAttack(Vector2 attack)
    {
        Vector2 moveInFacingDirection = Vector2Position + facingDirection;
        Vector2 distanceFromMove      = attack - moveInFacingDirection;

        return(distanceFromMove.Equals(Vector2.zero) || GameManager.AbsVector2(GameManager.FlipVector2(distanceFromMove)).Equals(GameManager.AbsVector2(facingDirection)));
    }
Esempio n. 2
0
    public bool CanMoveTo(Vector2 moveToPos)
    {
        if (GameManager.instance.IsEntityAtPosition(moveToPos) || !GameManager.instance.IsWalkableAtPosition(moveToPos))
        {
            return(false);
        }

        else
        {
            if (!GameManager.instance.IsPathValid(Vector2Position, moveToPos))
            {
                return(false);
            }

            if ((moveToPos - Vector2Position).normalized.Equals(facingDirection))
            {
                return(Vector2.Distance(moveToPos, Vector2Position) <= init);
            }
            else
            {
                Vector2 moveInFacingDirection = Vector2Position + facingDirection;
                Vector2 distanceFromMove      = moveToPos - moveInFacingDirection;

                return(GameManager.AbsVector2(GameManager.FlipVector2(distanceFromMove)).Equals(GameManager.AbsVector2(facingDirection)));
            }
        }
    }
Esempio n. 3
0
    public bool CanRotateTo(Vector2 rotateTo)
    {
        Vector2 absRotateTo = GameManager.AbsVector2(rotateTo);

        if (rotateTo.Equals(facingDirection))
        {
            return(false);
        }
        else if (canRotate180)
        {
            return(absRotateTo.x != absRotateTo.y && (absRotateTo.x == 1f || absRotateTo.y == 1f));
        }
        else
        {
            return(absRotateTo.x != Mathf.Abs(facingDirection.x) && absRotateTo.y != Mathf.Abs(facingDirection.y) && (absRotateTo.x == 1f || absRotateTo.y == 1f));
        }
    }
Esempio n. 4
0
    private void MovementAi(Vector2 currentTargetPositionAim)
    {
        if (Vector2Position.Equals(currentTargetPositionAim))
        {
            RotateTo((currentTarget.Vector2Position - Vector2Position).normalized);
        }
        else if ((currentTargetPositionAim - Vector2Position).normalized.Equals(facingDirection))
        {
            if (Vector2.Distance(Vector2Position, currentTargetPositionAim) >= 1.42f && CanMoveTo(Vector2Position + facingDirection * init))
            {
                Move(facingDirection * init);
            }
            else if (Vector2.Distance(Vector2Position, currentTargetPositionAim) >= 1f && CanMoveTo(Vector2Position + facingDirection))
            {
                Move(facingDirection);
            }
            else
            {
                GameManager.instance.NextTurn();
            }
        }
        else
        {
            Vector2 normalizedDistance      = (currentTargetPositionAim - Vector2Position).normalized;
            Vector2 absNormalizedDistance   = GameManager.AbsVector2(normalizedDistance);
            Vector2 roundNormalizedDistance = GameManager.RoundVector2(normalizedDistance);

            if (absNormalizedDistance.Equals(Vector2.right) || absNormalizedDistance.Equals(Vector2.up))
            {
                RotateTo(roundNormalizedDistance);
            }
            else
            {
                if (facingDirection.Equals(roundNormalizedDistance))
                {
                    Move(GameManager.ExtremeCeilVector2(normalizedDistance));
                }
                else
                {
                    RotateTo(roundNormalizedDistance);
                }
            }
        }
    }