Beispiel #1
0
        public CityBlock(CityBlockSettings settings)
        {
            this.settings = settings;

            size = new Coord(settings.width, settings.height);

            roads     = new RoadPiece[size.x, size.y];
            pavements = new PavementPiece[size.x, size.y];
            buildings = new BuildingPiece[size.x, size.y];
            misc      = new MiscPiece[size.x, size.y];
        }
Beispiel #2
0
        static CityBlock GenerateGridLayout(CityBlockSettings settings)
        {
            var cityBlock = new CityBlock(settings);

            // add horizontal roads
            for (int y = 1; y < cityBlock.size.y - 1; y += settings.gap)
            {
                for (int x = 1; x < cityBlock.size.x - 1; x++)
                {
                    cityBlock.SetRoadTile(x, y, RoadPiece.HORIZONTAL);
                }
            }

            // add vertical roads
            for (int x = 1; x < cityBlock.size.x - 1; x += settings.gap)
            {
                for (int y = 1; y < cityBlock.size.y - 1; y++)
                {
                    if (cityBlock.GetRoadTile(x, y) != RoadPiece.NONE)
                    {
                        cityBlock.SetRoadTile(x, y, RoadPiece.CROSS_CENTER);
                    }
                    else
                    {
                        cityBlock.SetRoadTile(x, y, RoadPiece.VERTICAL);
                    }
                }
            }

            // ground level
            SetCrossroadBorders(cityBlock);
            SetPavementWrappedWithRoad(cityBlock);

            // buildings
            SetBuildingsOnPavement(cityBlock);

            // world border
            SetBorder(cityBlock);

            // features
            SetCornerLamps(cityBlock);
            SetRoadsWithCrossingsAroundCrossroads(cityBlock);

            return(cityBlock);
        }
Beispiel #3
0
 public static CityBlock Generate(CityBlockSettings settings)
 {
     // return GenerateGridLayout(settings);
     return(GenerateManualLayout());
 }
Beispiel #4
0
        static CityBlock GenerateManualLayout()
        {
            int _ = 0;
            int H = 1;
            int V = 2;
            int C = 3;

            int[,] cityLayout =
            {
                { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, },
                { _, C, _, _, C, _, _, C, _, _, C, _, _, C, _, },
                { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, },
                { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, },
                { _, C, _, _, C, _, _, C, _, _, C, _, _, C, _, },
                { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, },
                { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, },
                { _, C, _, _, C, _, _, C, _, _, C, _, _, C, _, },
                { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, },
                { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, },
                { _, C, _, _, C, _, _, C, _, _, C, _, _, C, _, },
                { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, },
                { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, },
                { _, C, _, _, C, _, _, C, _, _, C, _, _, C, _, },
                { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, },
            };

            // create the city block
            var settings = new CityBlockSettings();

            settings.width  = cityLayout.GetLength(1);
            settings.height = cityLayout.GetLength(0);
            var cityBlock = new CityBlock(settings);

            // create road from layout
            for (int x = 0; x < settings.width; x++)
            {
                for (int y = 0; y < settings.height; y++)
                {
                    var tile = cityLayout[y, x];
                    if (tile == H)
                    {
                        cityBlock.SetRoadTile(x, y, RoadPiece.HORIZONTAL);
                    }
                    else if (tile == V)
                    {
                        cityBlock.SetRoadTile(x, y, RoadPiece.VERTICAL);
                    }
                    else if (tile == C)
                    {
                        cityBlock.SetRoadTile(x, y, RoadPiece.CROSS_CENTER);
                    }
                }
            }

            // ground level
            SetCrossroadBorders(cityBlock);
            SetPavementWrappedWithRoad(cityBlock);

            // buildings
            // SetBuildingsOnPavement(cityBlock);

            // world border
            SetBorder(cityBlock);

            // features
            // SetCornerLamps(cityBlock);
            // SetRoadsWithCrossingsAroundCrossroads(cityBlock);

            return(cityBlock);
        }