Ejemplo n.º 1
0
 public bool CollidesWith(Chamber other, int minDist)
 {
     return(!(right <= other.left - minDist ||
              left >= other.right + minDist ||
              top <= other.bottom - minDist ||
              bottom >= other.top + minDist));
 }
Ejemplo n.º 2
0
        public static Layout Generate(System.Random rng,
                                      int width,
                                      int height)
        {
            ChamberGeneratorConfig chamberCfg = new ChamberGeneratorConfig()
            {
                mapSize        = new Point2i(width, height),
                minChamberSize = 10,
                maxChamberSize = 20,
                numChambers    = width * height / 500,
                maxIterations  = 10000
            };

            IList <Chamber>  chambers     = GenerateChambers(rng, chamberCfg);
            IList <Corridor> corridors    = GenerateCorridors(rng, chambers, chambers.Count, 2 * chamberCfg.maxChamberSize);
            Chamber          startChamber = ChooseStartChamber(chambers);

            return(new Layout()
            {
                MapSize = new Point2i(width, height),
                Chambers = chambers,
                Corridors = corridors,
                StartChamber = startChamber,
                ExitChamber = ChooseExitChamber(rng, chambers, startChamber),
                Tiles = GenerateTiles(width, height, chambers, corridors)
            });
        }
Ejemplo n.º 3
0
 static Chamber ChooseExitChamber(System.Random rng,
                                  IList <Chamber> chambers,
                                  Chamber startChamber)
 {
     while (true)
     {
         Chamber c = chambers.Random(rng);
         if (c != startChamber)
         {
             return(c);
         }
     }
 }
Ejemplo n.º 4
0
        private static IList <Chamber> GenerateChambers(System.Random rng,
                                                        ChamberGeneratorConfig cfg)
        {
            IList <Chamber> chambers = new List <Chamber>();

            for (int i = 0; i < cfg.maxIterations && chambers.Count < cfg.numChambers; ++i)
            {
                Chamber newChamber = Chamber.Random(rng, cfg.mapSize.x, cfg.mapSize.y, cfg.minChamberSize, cfg.maxChamberSize);

                if (!chambers.Any(c => c.CollidesWith(newChamber, 5)) && newChamber.IsNotBorder(cfg.mapSize))
                {
                    chambers.Add(newChamber);
                }
            }
            return(chambers);
        }
Ejemplo n.º 5
0
        public static Corridor JoiningChambers(System.Random rng, Chamber src, Chamber dst)
        {
            IList <Point2i> intermediatePoints = new List <Point2i>();

            intermediatePoints.Add(src.center);

            Point2i delta = dst.center - src.center;

            if (rng.Next(2) == 0)
            {
                delta.x = 0;
            }
            else
            {
                delta.y = 0;
            }

            intermediatePoints.Add(src.center + delta);
            intermediatePoints.Add(dst.center);

            return(new Corridor(intermediatePoints));
        }
Ejemplo n.º 6
0
        private IList <Point2i> GenerateFiresPositions(Chamber chamber)
        {
            switch (((FiresLayout[])Enum.GetValues(typeof(FiresLayout))).Random(rng))
            {
            case FiresLayout.None:
                return(new List <Point2i>());

            case FiresLayout.Center:
                return(new List <Point2i> {
                    chamber.center
                });

            case FiresLayout.Corners:
                int offset = rng.Next(1, 5);
                return(new List <Point2i> {
                    new Point2i(chamber.left + offset, chamber.bottom + offset),
                    new Point2i(chamber.left + offset, chamber.top - offset - 1),
                    new Point2i(chamber.right - offset - 1, chamber.bottom + offset),
                    new Point2i(chamber.right - offset - 1, chamber.top - offset - 1),
                });

            case FiresLayout.Exits:
                IList <Point2i> fires = new List <Point2i>();
                for (int x = chamber.left; x < chamber.right; ++x)
                {
                    for (int y = chamber.bottom; y < chamber.top; ++y)
                    {
                        if (CountAdjacentTilesOfType(layout.Tiles, new Point2i(x, y), Tile.Type.Corridor) == 1)
                        {
                            fires.Add(new Point2i(x, y));
                        }
                    }
                }
                return(fires);
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 7
0
 public bool Equals(Chamber chamber)
 {
     return(left == chamber.left && right == chamber.right && bottom == chamber.bottom && top == chamber.top);
 }
Ejemplo n.º 8
0
 private static bool lessThanMaxRange(Chamber ch1, Chamber ch2, int maxRange)
 {
     return(Math.Abs(ch1.center.x - ch2.center.x) < maxRange && Math.Abs(ch1.center.y - ch2.center.y) < maxRange);
 }