public static List <BackgroundObject> CreateBackgroundObjects(int amountToCreate, Transform transform, Vector2 generationBounds, Vector2 spacing, StyleManager.LevelStyle style, int depth) { List <BackgroundObject> result = new List <BackgroundObject>(); int maxAmountOfObjectsHorizontal = (int)(generationBounds.X / spacing.X); if (spacing.X == 0) { maxAmountOfObjectsHorizontal = 1; } int maxAmountOfObjectsVertical = (int)(generationBounds.Y / spacing.Y); if (spacing.Y == 0) { maxAmountOfObjectsVertical = 1; } int maxAmountOfObjects = maxAmountOfObjectsHorizontal * maxAmountOfObjectsVertical; List <int> indexes = new List <int>(); for (int i = 0; i < maxAmountOfObjects; ++i) { indexes.Add(i); } for (int i = 0; i < amountToCreate; ++i) { int selectionIndex = Globals.Random.Next(0, indexes.Count); int placementX = indexes[selectionIndex] % maxAmountOfObjectsHorizontal; int placementY = indexes[selectionIndex] / maxAmountOfObjectsVertical; indexes.RemoveAt(selectionIndex); BackgroundObject objectToGenerateFrom = Globals.Backgrounds.GetObject(style, depth); BackgroundObject newObject = new BackgroundObject(objectToGenerateFrom); if (transform != null) { newObject.Transform.ParentTransform = transform; } newObject.Transform.PosX = spacing.X * placementX; newObject.Transform.PosY = spacing.Y * placementY; newObject.ApplyJitter(); result.Add(newObject); } return(result); }
public BackgroundObject GetObject(StyleManager.LevelStyle style, int depth) { return(_backgroundObjects[style][depth][Globals.Random.Next(0, _backgroundObjects[style][depth].Length)]); }