private void FillCenterArea(Point location, IMapInfo parentMap) { var rightEdge = levelDetail.SizeX - 8; var bottomEdge = levelDetail.SizeY - 8; for (var y = 8; y < bottomEdge; y += 8) { for (var x = 8; x < rightEdge; x += 8) { var px = location.X + x; var py = location.Y + y; // If this space is already filled, move on if (gameState.HasMap(px, py) > 0) { continue; } // Generate filler var random = new Random(gameState.Seed + location.X + location.Y + x + y); while (true) { var tileIdx = tileFillIds[random.Next(0, tileFillIds.Count())]; var info = gameState.GetSubMapInfo(tileIdx, 2, parentMap, new Point(location.X + x, location.Y + y)); // Make sure this tile actually fits here if (info.TileLocation.Right > (location.X + rightEdge) || info.TileLocation.Bottom > (location.Y + bottomEdge)) { continue; } if (info.TileLocation.Width == 16 && gameState.HasMap(px + 8, py) > 0) { continue; } if (info.TileLocation.Height == 16 && gameState.HasMap(px, py + 8) > 0) { continue; } // We found a tile that fits, so add it gameState.AddMap(info); break; } } } }