示例#1
0
        /**
         * Checks wether this tile belongs to a given face.
         */
        private static void ComputeFace(int x, int y, ref Graph.Graph graph)
        {
            // Check wether this tile is a wall, a vertex, or an empty cell.
            Vector2 position = new Vector2(x, y);

            Tile.Wall    cellWall = graph.GetWallAt(position);
            Graph.Vertex cellVtx  = graph.GetVertexAt(position);
            if (cellWall == null && cellVtx == null)
            {
                // Get the top and left cells.
                Vector2 left = position + new Vector2(-1, 0);
                Vector2 top  = position + new Vector2(0, -1);

                // Get the faces of the cells.
                Graph.Face leftFace = graph.GetFaceFromPoint(left);
                Graph.Face topFace  = graph.GetFaceFromPoint(top);

                Graph.Face pointFace;
                // If both faces are null.
                if (leftFace == null && topFace == null)
                {
                    // Create a new face.
                    pointFace = new Graph.Face();

                    // Add the face to the graph.
                    graph.AddFace(pointFace);

                    // If both faces are different.
                }
                else if (leftFace != topFace)
                {
                      {
                        // Merge both faces together.
                        pointFace = graph.MergeFaces(leftFace, topFace);

                        // If both faces are the same.
                    }
                }
                else
                {
                    // Select it as the point's face.
                    pointFace = leftFace;
                }

                // Add the point to the face.
                pointFace.AddPoint(position);
            }
        }