예제 #1
0
    public void SetBoardObject(int i, BoardCell elementCell)
    {
        if (i >= boardElements.Length)
        {
            return;
        }

        BoardObject element = elementCell.GetPlacedObject();

        if (element == null)
        {
            return;
        }

        BoardObjectState objectState = new BoardObjectState();

        objectState.id = element.GetObjectID();
        Vector2Int pos = elementCell.GetPosition();

        objectState.x           = pos.x;
        objectState.y           = pos.y;
        objectState.args        = element.GetArgs();
        objectState.orientation = (int)element.GetDirection();

        boardElements[i] = objectState;
    }
예제 #2
0
    public void RotateObject(Vector2Int origin, int direction, float time, out Coroutine coroutine)
    {
        // Check direction
        coroutine = null;
        if (direction == 0)
        {
            return;
        }
        direction = direction < 0 ? -1 : 1;

        // Check if origin object exists
        if (!IsInBoardBounds(origin))
        {
            return;
        }

        BoardObject bObject = board[origin.x, origin.y].GetPlacedObject();

        if (bObject == null)
        {
            return;                  // No to rotate
        }
        // You cannot rotate an object that is already rotating
        if (bObject.GetDirection() == BoardObject.Direction.PARTIAL)
        {
            return;
        }

        coroutine = StartCoroutine(InternalRotateObject(bObject, direction, time));
    }
예제 #3
0
    private IEnumerator InternalRotateObject(BoardObject bObject, int direction, float time)
    {
        // Get direction
        BoardObject.Direction currentDirection = bObject.GetDirection();
        BoardObject.Direction targetDirection  = (BoardObject.Direction)((((int)currentDirection + direction) + 8) % 8);

        // Froze direction
        bObject.SetDirection(BoardObject.Direction.PARTIAL, false);

        Vector3 fromAngles = bObject.transform.localEulerAngles;

        fromAngles.y = (int)currentDirection * 45.0f;
        Vector3 toAngles = bObject.transform.localEulerAngles;

        toAngles.y = ((int)currentDirection + direction) * 45.0f;

        // Interpolate movement
        float auxTimer = 0.0f;

        while (auxTimer < time)
        {
            Vector3 lerpAngles = Vector3.Lerp(fromAngles, toAngles, auxTimer / time);
            bObject.transform.localEulerAngles = lerpAngles;
            auxTimer += Time.deltaTime;
            yield return(null);
        }

        // Set final rotation (defensive code)
        bObject.SetDirection(targetDirection);
    }
예제 #4
0
    private void OnLeftDown()
    {
        if (!modifiable)
        {
            return;
        }
        if (orbitCamera != null && !orbitCamera.IsReset())
        {
            return;
        }
        if (boardObject == null)
        {
            boardObject = GetComponent <BoardObject>();
        }
        if (argumentLoader != null)
        {
            argumentLoader.SetBoardObject(boardObject);
        }
        if (cameraInput != null)
        {
            cameraInput.SetDragging(true);
        }

        zCoord      = Camera.main.WorldToScreenPoint(transform.position).z;
        mouseOffset = transform.position - GetMouseWorldPos();
        dragging    = true;

        string name = boardObject.GetName();

        TrackerAsset.Instance.setVar("element_type", name.ToLower());
        TrackerAsset.Instance.setVar("element_name", boardObject.GetNameWithIndex().ToLower());
        TrackerAsset.Instance.setVar("position", lastPos.ToString());
        TrackerAsset.Instance.setVar("rotation", boardObject.GetDirection().ToString().ToLower());
        TrackerAsset.Instance.setVar("action", "pick");
        TrackerAsset.Instance.GameObject.Interacted(boardObject.GetID());
    }
예제 #5
0
    // Smooth interpolation, this code must be called by blocks
    public bool MoveObject(Vector2Int origin, Vector2Int direction, float time, out Coroutine coroutine)
    {
        coroutine = null;
        // Check valid direction
        if (!(direction.magnitude == 1.0f && (Mathf.Abs(direction.x) == 1 || Mathf.Abs(direction.y) == 1)))
        {
            return(false);
        }

        // Check if origin object exists
        if (!IsInBoardBounds(origin))
        {
            return(false);
        }

        BoardObject bObject = board[origin.x, origin.y].GetPlacedObject();

        if (bObject == null)
        {
            return(false);                 // No object to move
        }
        // Check if direction in valid
        if (IsInBoardBounds(origin + direction))
        {
            // A valid direction
            BoardCell fromCell = board[origin.x, origin.y];
            BoardCell toCell   = board[origin.x + direction.x, origin.y + direction.y];

            if (toCell.GetPlacedObject() != null)
            {
                if (bObject.GetAnimator() != null)
                {
                    if (bObject.GetDirection() == BoardObject.Direction.LEFT ||
                        bObject.GetDirection() == BoardObject.Direction.RIGHT ||
                        bObject.GetDirection() == BoardObject.Direction.DOWN_RIGHT ||
                        bObject.GetDirection() == BoardObject.Direction.UP_LEFT)
                    {
                        if (direction.y != 0)
                        {
                            bObject.GetAnimator().Play("Collision");
                        }
                        else
                        {
                            bObject.GetAnimator().Play("Collision2");
                        }
                    }
                    else
                    {
                        if (direction.y != 0)
                        {
                            bObject.GetAnimator().Play("Collision2");
                        }
                        else
                        {
                            bObject.GetAnimator().Play("Collision");
                        }
                    }
                }
                return(false);
            }

            coroutine = StartCoroutine(InternalMoveObject(fromCell, toCell, time));
            return(true);
        }
        else
        {
            // Not a valid direction
            return(false);
        }
    }