/// <summary> /// Creates map /// </summary> /// <param name="width">Width of the map</param> /// <param name="height">Height of the map</param> /// <returns>Array of tiles</returns> public static WorldTile[] GenerateMap(int width, int height) { bool[,] cells = new bool[width, height]; // Fill map with 1 or 0 randomly UH.Loops(width, height, (x, y) => cells[x, y] = x == 0 || y == 0 || x == width - 1 || y == height - 1 || RandomService.GetRandomBool(_generatorWallRoomRation)); // Simulation for (int i = 0; i < _generatorSteps; i++) { cells = SimulationStep(cells); } // Set map WorldTile[] map = new WorldTile[width * height]; UH.Loops(width, height, (x, y) => map[y * width + x] = new WorldTile(y * width + x, x, y, cells[x, y], new CollisionType[0])); // Set walls' collisions UH.Loops(width, height, (x, y) => { WorldTile tile = map[y * width + x]; if (!tile.IsWall) { return; } List <CollisionType> collision = new List <CollisionType>( ); if (x - 1 < 0 || !map[y * width + x - 1].IsWall) { collision.Add(CollisionType.Left); } if (x + 1 >= width || !map[y * width + x + 1].IsWall) { collision.Add(CollisionType.Right); } if (y - 1 < 0 || !map[(y - 1) * width + x].IsWall) { collision.Add(CollisionType.Top); } if (y + 1 >= height || !map[(y + 1) * width + x].IsWall) { collision.Add(CollisionType.Bottom); } tile.Collisions = collision.ToArray( ); }); return(map); }