示例#1
0
 // function to add neighbor tile at given tile coordinates
 private void addNeighbor(int x, int y)
 {
     tempTile = tileBoard.GetTile(x, y);
     //Debug.Log("Examining Tile at : (" + x + "," + y + ")");
     // if the tile is in bounds...
     if (tempTile != null)
     {
         // calculate total move cost
         tempInt = currentNode.totalMoveCost + tempTile.getMoveCost();
         //Debug.Log("Total Move Cost is: " + tempInt);
         // and if we have enough move allowance to navigate here...
         if (moves >= tempInt)
         {
             // and if the coordinates are not in the closed list...
             //Debug.Log("Tile corresponds to closedlist: " + (x - transX -6) + ", " + (y - transY -6));
             if (!closedList[(x - transX), (y - transY)])
             {
                 // and if the tile is unoccupied...
                 if (!tempTile.isOccupied())
                 {
                     // make a NavNode for this tile
                     tempNode = new NavNode(tempTile);
                     // update it's move cost
                     tempNode.totalMoveCost = tempInt;
                     // add it to the heap
                     heap.push(tempNode);
                 }
             }
         }
     }
 }
示例#2
0
    // function to add neighbor tile at given tile coordinates
    private void addNeighbor(int x, int y)
    {
        tempTile = tileBoard.GetTile(x, y);
        // if the tile is in bounds...
        if (tempTile != null)
        {
            // calculate total move cost
            tempInt = currentNode.totalMoveCost + tempTile.getMoveCost();
            // and if we have enough move allowance to navigate here...
            if (moves >= tempInt)
            {
                // and if the coordinates are not in the closed list...
                if (!closedList[(x - transX), (y - transY)])
                {
                    // and if the tile is unoccupied...
                    if (!tempTile.isOccupied())
                    {
                        // make a NavNode for this tile
                        tempNode = new NavNode(tempTile);
                        // update it's move cost
                        tempNode.totalMoveCost = tempInt;

                        // calculate it's f
                        f          = agressive * agressive - getMinDistance(x, y);
                        f         += defensive * tempTile.getDefenseMod();
                        f         += runner * tempInt;
                        tempNode.f = f;

                        // add it to the heap
                        movesHeap.push(tempNode);
                    }
                }
            }
        }
    }