Ejemplo n.º 1
0
    void OnMouseDown()
    {
        screenPoint = Camera.main.WorldToScreenPoint(transform.position);
        offset      = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));

        if (PlayerPrefController.GetDragHold() == 1)
        {
            oldPos = transform.position;
        }
    }
Ejemplo n.º 2
0
    private void SetNewPosVectors()
    {
        if (PlayerPrefController.GetDragHold() == 0)
        {
            oldPos = transform.position;
        }

        enemyPos = enemy.gameObject.transform.position;

        curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);

        currentPos   = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
        currentPos.x = Mathf.Round(Mathf.Clamp(currentPos.x, 1, 16));
        currentPos.y = Mathf.Round(Mathf.Clamp(currentPos.y, 1, 16));
    }
Ejemplo n.º 3
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.tag == "PositiveTile" || collider.tag == "NegativeTile")
        {
            ChangeDigitAmount(collider.GetComponent <TileController> ().value, false);

            Vector3 tilePos = collider.gameObject.transform.position;

            gameController.MakeTileInactiveInList(tilePos);

            if (PlayerPrefController.GetDragHold() == 0 || tag != "Player")
            {
                Destroy(collider.gameObject);
            }
            else
            {
                collider.gameObject.SetActive(false);
                GetComponent <PlayerController>().tilesTakenThisTurn.Add(collider.gameObject);
            }
        }
    }
Ejemplo n.º 4
0
    void OnMouseDrag()
    {
        switch (PlayerPrefController.GetDragHold())
        {
        case 0:

            if (!moveLocked && !enemy.turnInProgress)
            {
                SetNewPosVectors();

                // Block any movement beyond single N/E/S/W movement
                if (currentPos.x == transform.position.x || currentPos.y == transform.position.y)
                {
                    currentPos = new Vector3(Mathf.Clamp(currentPos.x, oldPos.x - 1, oldPos.x + 1),
                                             Mathf.Clamp(currentPos.y, oldPos.y - 1, oldPos.y + 1), currentPos.z);

                    if (enemyPos == currentPos)
                    {
                        hitEnemy = true;
                    }
                    else
                    {
                        hitEnemy           = false;
                        transform.position = currentPos;

                        if (transform.position != oldPos)
                        {
                            moveLocked = true;
                        }
                    }
                }
            }

            break;

        case 1:
            if (!moveLocked && !enemy.turnInProgress)
            {
                SetNewPosVectors();

                // Block any movement beyond single N/E/S/W movement
                if (currentPos.x == transform.position.x || currentPos.y == transform.position.y)
                {
                    currentPos = new Vector3(Mathf.Clamp(currentPos.x, currentPos.x - 1, currentPos.x + 1),
                                             Mathf.Clamp(currentPos.y, currentPos.y - 1, currentPos.y + 1), currentPos.z);

                    if (enemyPos == currentPos)
                    {
                        hitEnemy = true;
                    }
                    else
                    {
                        hitEnemy = false;

                        if (transform.position != currentPos)
                        {
                            posBeforeMove      = transform.position;
                            transform.position = currentPos;
                            CheckDistanceToOriginalPos();
                        }

                        if (moveCount <= 0)
                        {
                            moveLocked = true;
                        }
                    }
                }
            }

            break;
        }
    }
Ejemplo n.º 5
0
    void OnMouseDrag()
    {
        switch (PlayerPrefController.GetDragHold())
        {
        case 0:
            if (!moveLocked && !enemy.turnInProgress)
            {
                oldPos = transform.position;
                Vector3 enemyPos = enemy.gameObject.transform.position;

                Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);

                Vector3 currentPos = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
                currentPos.x = Mathf.Round(Mathf.Clamp(currentPos.x, 1, 16));
                currentPos.y = Mathf.Round(Mathf.Clamp(currentPos.y, 1, 16));

                // Block any movement beyond single N/E/S/W movement
                if (currentPos.x == transform.position.x || currentPos.y == transform.position.y)
                {
                    currentPos = new Vector3(Mathf.Clamp(currentPos.x, oldPos.x - 1, oldPos.x + 1),
                                             Mathf.Clamp(currentPos.y, oldPos.y - 1, oldPos.y + 1),
                                             currentPos.z);

                    if (enemyPos == currentPos)
                    {
                        hitEnemy = true;
                    }
                    else
                    {
                        hitEnemy           = false;
                        transform.position = currentPos;

                        if (transform.position != oldPos)
                        {
                            moveLocked = true;
                        }
                    }
                }
            }

            break;

        case 1:
            if (!moveLocked && !enemy.turnInProgress)
            {
                Vector3 enemyPos = enemy.gameObject.transform.position;

                Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);

                Vector3 currentPos = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
                currentPos.x = Mathf.Round(Mathf.Clamp(currentPos.x, 1, 16));
                currentPos.y = Mathf.Round(Mathf.Clamp(currentPos.y, 1, 16));

                // Block any movement beyond single N/E/S/W movement
                if (currentPos.x == transform.position.x || currentPos.y == transform.position.y)
                {
                    currentPos = new Vector3(Mathf.Clamp(currentPos.x, oldPos.x - 5, oldPos.x + 5),
                                             Mathf.Clamp(currentPos.y, oldPos.y - 5, oldPos.y + 5),
                                             currentPos.z);

                    if (enemyPos == currentPos)
                    {
                        hitEnemy = true;
                    }
                    else
                    {
                        hitEnemy           = false;
                        transform.position = currentPos;

                        if (transform.position != oldPos)
                        {
                            int xDistance = (int)Mathf.Abs(transform.position.x - oldPos.x);
                            int yDistance = (int)Mathf.Abs(transform.position.y - oldPos.y);

                            moveCount = 5 - (xDistance + yDistance);
                            UIController.instance.SetMoveCounter(moveCount);

                            if (moveCount <= 0)
                            {
                                moveLocked = true;
                            }
                        }
                    }
                }
            }

            break;
        }
    }