Exemple #1
0
    private void moveTo(SquareIndex index)
    {
        if (nodeList.Count == 0)
        {
            lastIndex    = startIndex;
            currentIndex = index;

            nodeList.Add(instantiateMoveNode(moveNodeFinalPrefab, currentIndex, 10));
        }
        else if (!index.Equals(nodeList[0].index))
        {
            int listIndex = calculateListIndex(index);

            if (listIndex > 0)
            {
                removeIndex(listIndex, index);
            }
            else
            {
                addIndex(index);
            }

            lastIndex    = currentIndex;
            currentIndex = index;
        }

        createNodeLinks();
        calculateNumMoves();
    }
Exemple #2
0
    //Returns a list with all the possible squares a player can move to
    public List <SquareIndex> getMoveToSquareList(SquareIndex index, int radius, bool squareWithPlayerIn)
    {
        List <SquareIndex> indexList       = new List <SquareIndex>();
        List <SquareIndex> indexListInArea = getSquareListInArea(index, radius);

        for (int i = 0; i < indexListInArea.Count; i++)
        {
            SquareIndex currentIndex = indexListInArea[i];

            bool sameIndex = index.Equals(currentIndex);
            bool onBounds  = isOnBounds(currentIndex);
            bool isPlayer  = isPlayerOnSquare(currentIndex);

            if (!sameIndex && onBounds && (!isPlayer || squareWithPlayerIn))
            {
                indexList.Add(currentIndex);
            }
        }

        return(indexList);
    }
Exemple #3
0
    private void updateMouse()
    {
        if (isTracking)
        {
            if (Input.GetMouseButton(0))
            {
                RaycastHit rayHit = new RaycastHit();
                Ray        ray    = GameCamera.camera.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out rayHit, GameConfig.RAY_DISTANCE, GameConfig.boardLayerMask))
                {
                    SquareIndex index     = rayHit.collider.GetComponent <BoardSquare>().index;
                    SquareIndex headIndex = nodeList[0].index;

                    //HACK: Have to think about this at some point
                    if (!index.Equals(headIndex) && !index.Equals(startIndex))
                    {
                        //Check if we have enough moves left
                        if (nodeList.Count < numMoves)
                        {
                            hasMoved = true;

                            //Check if we have changed direction
                            if (canChangeDirection || (!canChangeDirection && !isDirectionChange(index)))
                            {
                                moveTo(index);
                            }
                        }
                    }
                }
            }
            else if (Input.GetMouseButtonUp(0))
            {
                //If the user didn't move the arrow, perform a click
                if (!hasMoved)
                {
                    click();
                }

                isTracking = false;
                hasMoved   = false;
            }
        }
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit rayHit = new RaycastHit();
                Ray        ray    = GameCamera.camera.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out rayHit, GameConfig.RAY_DISTANCE, GameConfig.boardLayerMask))
                {
                    SquareIndex headIndex = nodeList[0].index;
                    SquareIndex index     = rayHit.collider.GetComponent <BoardSquare>().index;

                    if (index == headIndex)
                    {
                        isTracking = true;
                    }
                    //If we click the index the player is on, we cancel the move
                    else if (player.index == index)
                    {
                        cancel();
                    }
                    else
                    {
                        removeList();
                        List <SquareIndex> path = PathFinder.findPath(startIndex, index, board, canUseEmptySquares, canChangeDirection, numDiagonals);
                        for (int i = 0; i < path.Count; i++)
                        {
                            //Check if we have enough moves left
                            if (nodeList.Count < numMoves)
                            {
                                moveTo(path[i]);
                            }
                        }
                    }
                }
            }
        }
    }