Пример #1
0
        private void TryAddNeighbor(TilePosition from, TilePosition position, int width, int height)
        {
            if (_obstacles.Contains(position))
            {
                return;
            }
            if (_visited.Contains(position))
            {
                return;
            }
            if (!IsInsideBounds(position, width, height))
            {
                return;
            }

            _from[position] = from;
            _pendingPositions.Enqueue(position);
        }
Пример #2
0
        private static void TryConnectVertically(LevelTile[,] tiles, TilePosition tile1, TilePosition tile2)
        {
            var dy = tile2.Y - tile1.Y;

            if (dy == 0)
            {
                return;
            }

            if (dy > 0)
            {
                tiles[tile1.X, tile1.Y].HasNorthDoor = true;
                tiles[tile2.X, tile2.Y].HasSouthDoor = true;
            }
            else
            {
                tiles[tile1.X, tile1.Y].HasSouthDoor = true;
                tiles[tile2.X, tile2.Y].HasNorthDoor = true;
            }
        }
Пример #3
0
        private static void TryConnectHorizontally(LevelTile[,] tiles, TilePosition tile1, TilePosition tile2)
        {
            var dx = tile2.X - tile1.X;

            if (dx == 0)
            {
                return;
            }

            if (dx > 0)
            {
                tiles[tile1.X, tile1.Y].HasEastDoor = true;
                tiles[tile2.X, tile2.Y].HasWestDoor = true;
            }
            else
            {
                tiles[tile1.X, tile1.Y].HasWestDoor = true;
                tiles[tile2.X, tile2.Y].HasEastDoor = true;
            }
        }
        private void GenerateCorridor(LevelTile[,] tiles, TilePosition origin)
        {
            for (var depth = 0; depth < _maxDepth; depth++)
            {
                var neighbor = GetRandomNeighbor(origin);
                var width    = tiles.GetWidth();
                var height   = tiles.GetHeight();
                if (!IsInsideBounds(neighbor, width, height))
                {
                    return;
                }
                if (tiles[neighbor.X, neighbor.Y].Type != LevelTileType.None)
                {
                    return;
                }

                tiles[neighbor.X, neighbor.Y] = LevelTile.Room();
                LevelTileConnector.Connect(tiles, origin, neighbor);
                origin = neighbor;
            }
        }
Пример #5
0
 public bool Contains(TilePosition position) =>
 Min.X <= position.X && position.X <= Max.X &&
 Min.Y <= position.Y && position.Y <= Max.Y;
Пример #6
0
 public TileRect(int minX, int minY, int maxX, int maxY)
 {
     Min = new TilePosition(minX, minY);
     Max = new TilePosition(maxX, maxY);
 }
Пример #7
0
 public TileRect(TilePosition min, TilePosition max)
 {
     Min = min;
     Max = max;
 }