Exemple #1
0
 public void checkCollisionToPaddle(Rectangle rectangle)
 {
     if (CurrentRectangle.Intersects(rectangle))
     {
         Vector2 normal       = new Vector2(0, -1);
         Vector2 secondVector = Vector2.Zero;
         if (CurrentRectangle.Center.X < rectangle.Center.X)
         {
             secondVector = new Vector2(-1, 0);
         }
         if (CurrentRectangle.Center.X > rectangle.Center.X)
         {
             secondVector = new Vector2(1, 0);
         }
         ratio            = (float)Math.Abs((CurrentRectangle.Center.X - rectangle.Center.X) * 0.011);
         locationVector.Y = rectangle.Top - CurrentRectangle.Height;
         direction        = Vector2.Lerp(normal, secondVector, ratio);
         direction.Normalize();
     }
 }
        public override MazeGenerationResults Generate()
        {
            if (CurrentIteration++ == 0)
            {
                var mapInitializationResults = InitializeMap();
                var pointFrom = Point.CreateSameAllDimensions(Map.Dimensions, 0);
                var mapRect   = new Rectangle(pointFrom + 1, Map.Size - 1);
                Rectangles.Add(mapRect);
                if (ShowMapInitializationStep)
                {
                    return(mapInitializationResults);
                }
            }

            if (CurrentRectangle == null)
            {
                if (Rectangles.Count != 0)
                {
                    BeginNewRectangle();
                }
                else
                {
                    return(new MazeGenerationResults(GenerationResultsType.GenerationCompleted));
                }
            }

            var results      = new MazeGenerationResults();
            var offset       = Vertical ? new Point(1, 0) : new Point(0, 1);
            var currentPoint = LastPoint + offset;

            if (!CurrentRectangle.Contains(currentPoint))
            {
                var rects = new List <Rectangle>
                {
                    new Rectangle(CurrentRectangle.From, currentPoint)
                };
                Point path;
                Point newRectFrom;
                if (Vertical)
                {
                    newRectFrom = new Point(CurrentRectangle.From[0], LastPoint[1] + 1);
                    var pathCoord = RNG.Next(InitialPoint[0] / 2, LastPoint[0] / 2) * 2 + 1;
                    path = new Point(pathCoord, InitialPoint[1]);
                }
                else
                {
                    newRectFrom = new Point(LastPoint[0] + 1, CurrentRectangle.From[1]);
                    var pathCoord = RNG.Next(InitialPoint[1] / 2, LastPoint[1] / 2) * 2 + 1;
                    path = new Point(InitialPoint[0], pathCoord);
                }

                ChangeCell(results, path, CellState.Empty, CellDisplayState.Path);

                var newRect = new Rectangle(newRectFrom, CurrentRectangle.To);
                rects.Add(newRect);

                var doReverseRecursionOrder = ReverseRecursionOrder > RNG.NextDouble();
                if (doReverseRecursionOrder)
                {
                    rects.Reverse();
                }

                foreach (var rect in rects)
                {
                    if (rect.Size[0] > 2 || rect.Size[1] > 2)
                    {
                        if (ProcessSingleCellBlocks || (rect.Size[0] > 1 && rect.Size[1] > 1))
                        {
                            Rectangles.Add(rect);
                        }
                    }
                }

                CurrentRectangle = null;
            }
            else
            {
                ChangeCell(results, currentPoint, CellState.Filled, CellDisplayState.Wall);
                LastPoint = currentPoint;
            }
            return(results);
        }