Ejemplo n.º 1
0
    public void MoveInDir(Vector2 dir)
    {
        PositionUtil.CalcPosition(currentTile, map.row, out tempX, out tempY);

        tempX += (int)dir.x;
        tempY += (int)dir.y;

        PositionUtil.CalcIndex(tempX, tempY, map.row, out tempIndex);

        //Debug.Log("Moving to: " + tempIndex);
        MoveTo(tempIndex, true);
    }
    void VisitTile(int index)
    {
        int column, newX, newY, row = 0;

        PositionUtil.CalcPosition(index, Map.col, out tempX, out tempY);
        var half = Mathf.FloorToInt(viewDistance / 2f);

        tempX -= half;
        tempY -= half;

        var total  = viewDistance * viewDistance;
        var maxCol = viewDistance - 1;

        for (int i = 0; i < total; i++)
        {
            column = i % viewDistance;

            newX = column + tempX;
            newY = row + tempY;

            PositionUtil.CalcIndex(newX, newY, Map.col, out index);
            if (index > -1 && index < Map.mapTiles.Length)
            {
                var tile = Map.mapTiles[index];
                tile.visited = true;
                DecorateTile(index);

                foreach (var neighbor in tile.Neighbors)
                {
                    if (neighbor != null)
                    {
                        if (!neighbor.visited)
                        {
                            neighbor.CalcFOWAutoTileID();
                            DecorateTile(neighbor.TileID);
                        }
                    }
                }
            }

            if (column == maxCol)
            {
                row++;
            }
        }
    }