Exemple #1
0
        private void DrawDoors(int tileSize, int hallwaySize)
        {
            // Create a path for drawing the hallways
            Path doorsPath = new Path();

            doorsPath.Stroke          = Brushes.Black;
            doorsPath.StrokeThickness = 1;
            SolidColorBrush mySolidColorBrush = new SolidColorBrush();

            mySolidColorBrush.Color = Colors.Black;
            doorsPath.Fill          = mySolidColorBrush;

            // Use a composite geometry for adding the doors to
            CombinedGeometry doorsGeometryGroup = new CombinedGeometry();

            doorsGeometryGroup.GeometryCombineMode = GeometryCombineMode.Union;
            doorsGeometryGroup.Geometry1           = null;
            doorsGeometryGroup.Geometry2           = null;

            for (int top = 0; top < fpHeight; top++)
            {
                for (int left = 0; left < fpWidth; left++)
                {
                    if (fp.floorGrid[top, left] != null)
                    {
                        FloorSegment thisSegment = fp.floorGrid[top, left];
                        double       doorX       = 0;
                        double       doorY       = 0;
                        double       doorWidth   = 0;
                        double       doorHeight  = 0;
                        // position the doors differently depending on weather or not there's a hallway.  Math, bitches.
                        foreach (enumDirection nextDoorDir in thisSegment.Doors)
                        {
                            switch (nextDoorDir)
                            {
                            case enumDirection.North:
                                FloorSegment northSegment = fp.IsInBounds(top - 1, left) ? fp.floorGrid[top - 1, left] : null;
                                doorX      = (left * tileSize) + (tileSize / 2) - (hallwaySize / 2);
                                doorY      = northSegment != null ? northSegment.GroupID != thisSegment.GroupID ? (top * tileSize) + (hallwaySize / 4) : (top * tileSize) - (hallwaySize / 4) : (top * tileSize) - (hallwaySize / 4);
                                doorWidth  = hallwaySize;
                                doorHeight = hallwaySize / 2;
                                break;

                            case enumDirection.South:
                                FloorSegment southSegment = fp.IsInBounds(top + 1, left) ? fp.floorGrid[top + 1, left] : null;
                                doorX      = (left * tileSize) + (tileSize / 2) - (hallwaySize / 2);
                                doorY      = southSegment != null ? southSegment.GroupID != thisSegment.GroupID ? ((top * tileSize) + tileSize) - ((hallwaySize / 4) * 3) : ((top * tileSize) + tileSize) - (hallwaySize / 4) : ((top * tileSize) + tileSize) - (hallwaySize / 4);
                                doorWidth  = hallwaySize;
                                doorHeight = hallwaySize / 2;
                                break;

                            case enumDirection.East:
                                FloorSegment eastSegment = fp.IsInBounds(top, left + 1) ? fp.floorGrid[top, left + 1] : null;
                                doorX      = eastSegment != null ? eastSegment.GroupID != thisSegment.GroupID ? ((left * tileSize) + tileSize) - ((hallwaySize / 4) * 3) : ((left * tileSize) + tileSize) - (hallwaySize / 4) : ((left * tileSize) + tileSize) - (hallwaySize / 4);
                                doorY      = (top * tileSize) + (tileSize / 2) - (hallwaySize / 2);
                                doorWidth  = hallwaySize / 2;
                                doorHeight = hallwaySize;
                                break;

                            case enumDirection.West:
                                FloorSegment westSegment = fp.IsInBounds(top, left - 1) ? fp.floorGrid[top, left - 1] : null;
                                doorX      = westSegment != null ? westSegment.GroupID != thisSegment.GroupID ? (left * tileSize) + (hallwaySize / 4) : (left * tileSize) - (hallwaySize / 4) : (left * tileSize) - (hallwaySize / 4);
                                doorY      = (top * tileSize) + (tileSize / 2) - (hallwaySize / 2);
                                doorWidth  = hallwaySize / 2;
                                doorHeight = hallwaySize;
                                break;
                            }
                            RectangleGeometry newDoorGeometry = new RectangleGeometry(new Rect(doorX, doorY, doorWidth, doorHeight));
                            doorsGeometryGroup = new CombinedGeometry()
                            {
                                Geometry1 = doorsGeometryGroup,
                                Geometry2 = newDoorGeometry
                            };
                        }
                    }
                }
            }

            doorsPath.Data = doorsGeometryGroup;
            RenderOptions.SetEdgeMode(doorsPath, EdgeMode.Aliased);
            MainCanvas.Children.Add(doorsPath);
        }