Exemple #1
0
    /// <summary>
    /// Tries to move the player in their current move direction.
    /// </summary>
    private void Move()
    {
        // Don't even try moving if we have no input direction (compares enums, saves performance)
        if (moveDir == QuadDirection2D.none)
        {
            return;
        }
        // Try to move the player
        if (gridMover.Move(moveDir, out bool isCurrentlyMoving))
        {
            return;
        }
        if (isCurrentlyMoving)
        {
            return;
        }

        // If player couldn't move then try moving them in x or y separately
        Vector2 moveDirVector = moveDir.Vector;

        // If they were moving only in the x or y, the player just can't move
        if (moveDirVector.x == 0 || moveDirVector.y == 0)
        {
            return;
        }

        QuadDirection2D horiMoveDir = new Vector2(moveDirVector.x, 0).ToDirection2D().ToQuadDirection2D();
        QuadDirection2D vertMoveDir = new Vector2(0, moveDirVector.y).ToDirection2D().ToQuadDirection2D();

        // Try vertical first if we tried horizontal first last time
        if (lastMovementPriority == eDirectionPriority.Horizontal)
        {
            // Vertical move try
            if (gridMover.Move(vertMoveDir))
            {
                lastMovementPriority = eDirectionPriority.Vertical;
                return;
            }
        }
        // Horizontal move try
        if (gridMover.Move(horiMoveDir))
        {
            lastMovementPriority = eDirectionPriority.Horizontal;
            return;
        }
        // Try vertical second if we tried vertical first last time
        if (lastMovementPriority == eDirectionPriority.Vertical)
        {
            // Vertical move try
            if (gridMover.Move(vertMoveDir))
            {
                lastMovementPriority = eDirectionPriority.Vertical;
                return;
            }
        }
    }
Exemple #2
0
 private void Update()
 {
     if (slideDirection != QuadDirection2D.none)
     {
         gridMover.Move(slideDirection);
     }
 }
Exemple #3
0
    public override bool Hit(GridHit hit)
    {
        Vector2 diff = hit.hitPosition - (Vector2)transform.position;
        // Scale the difference by the mover's size. The bigger magnitude of the result (x or y) is closer
        Vector2 distComparisonV = diff / transform.lossyScale;
        bool    isHori          = Mathf.Abs(distComparisonV.x) > Mathf.Abs(distComparisonV.y);

        gridMover.speed = hit.speed;
        QuadDirection2D dir = hit.direction.ToDirection2D(isHori).ToQuadDirection2D();

        return(gridMover.Move(dir));
    }
Exemple #4
0
    private IEnumerator MoveCoroutine()
    {
        kingOriginalPosition = kingTrans.position;

        float t = 0;

        while (t < moveTime)
        {
            kingTrans.Translate(Vector3.right * moveSpeed * Time.deltaTime);
            GridMover playerGridMover = PlayerMovement.Instance.GetComponent <GridMover>();
            playerGridMover.speed = moveSpeed;
            playerGridMover.Move(QuadDirection2D.right);

            t += Time.deltaTime;
            yield return(null);
        }

        CanvasSingleton.Instance.StartFadeOutAndIn(fadeOutSpeed, OnFadedOut, OnFadedIn);
    }
Exemple #5
0
    private void Update()
    {
        Direction2D horiDir = Direction2D.none;
        Direction2D vertDir = Direction2D.none;

        float horiInput = Input.GetAxisRaw("Horizontal");
        float vertInput = Input.GetAxisRaw("Vertical");

        if (Mathf.Abs(horiInput) == 1.0f)
        {
            horiDir = new Vector2(horiInput, 0).ToDirection2D();
        }
        if (Mathf.Abs(vertInput) == 1.0f)
        {
            vertDir = new Vector2(0, vertInput).ToDirection2D();
        }

        QuadDirection2D moveDir = horiDir.Add(vertDir);

        if (moveDir != QuadDirection2D.none)
        {
            gridMover.Move(moveDir);
        }
    }