/// <summary> /// Constructor which takes the treeSize(radius) and the list of acceptable points in the X and Z space.These are the grid corrdinates /// which the trees can spawn into. /// </summary> /// <param name="rng"></param> /// <param name="size"></param> /// <param name="acceptablePoints"></param> /// <param name="isForest"></param> public NaturalObject(Random rng, objectSize size, ArrayList acceptablePoints, bool isForest) { this.size = size; if (isForest) { type = ForestTypePropability[rng.Next(0, ForestTypePropability.Count)]; } else { type = GrassTypePropability[rng.Next(0, GrassTypePropability.Count)]; } if (size == objectSize.LARGE || size == objectSize.MEDIUM) { // Large trees are 3x3 so the outer ring of the grid cannot be used. Point point = (Point)acceptablePoints[rng.Next(0, acceptablePoints.Count)]; x = point.X; y = point.Y; r = largeMediumTreeRadius; } else { // Small trees are 1x1 so the outer ring of the grid can be used. Point point = (Point)acceptablePoints[rng.Next(0, acceptablePoints.Count)]; x = point.X; y = point.Y; r = smallTreeRadius; } SetSizeType(); }
private void InitializeVariables() { spaceship = Spaceship.Instance; spaceshipRadius = spaceship.ColliderRadius; size = (objectSize)(Random.Range(2, 4) * 5f); objectRadius = GetComponent <CircleCollider2D>().radius *transform.localScale.x; colliderPosition *= (spaceshipRadius + objectRadius); destination = Objects.Instance.destinationObject; movementRate = Random.Range(7, 17); step = Vector3.Distance(transform.position, colliderPosition) / movementRate; frozenObjectsContainer = Containers.Instance.frozenObjectsContainer; objArray = FrozenObjectsArray.Instance; }
/// <summary> /// Method to generate a random Object. /// </summary> /// <param name="isForest"> true if the object is for the forest, otherwise false </param> /// <returns></returns> private NaturalObject GetRandomNaturalObject(bool isForest) { objectSize size = GetRandomObjectSize(); NaturalObject newObject; if (size == objectSize.SMALL) { newObject = new NaturalObject(random, size, smallObjectsAcceptablePoints, isForest); } else { newObject = new NaturalObject(random, size, largeMediumAcceptablePoints, isForest); } return(newObject); }
/// <summary> /// Helper function which takes a size and a color and will draw the correct amount of pixels to the image. /// </summary> /// <param name="x"> The center x coordinate </param> /// <param name="y"> The center y coordinate </param> /// <param name="color"> The color of the natural object </param> /// <param name="size"> The size of the natural object </param> public void DrawSizeSpecificPixel(int x, int y, Color color, objectSize size) { newMap.SetPixel(x, y, color); if (size == objectSize.LARGE || size == objectSize.MEDIUM) { newMap.SetPixel(x, y - 1, color); newMap.SetPixel(x, y + 1, color); newMap.SetPixel(x - 1, y, color); newMap.SetPixel(x + 1, y, color); if (size == objectSize.LARGE) { newMap.SetPixel(x - 1, y - 1, color); newMap.SetPixel(x - 1, y + 1, color); newMap.SetPixel(x + 1, y - 1, color); newMap.SetPixel(x + 1, y + 1, color); } } }
/// <summary> /// Creates a random number between 0 and 9 and uses it to get a values form the list of object Sizes /// </summary> /// <returns></returns> private objectSize GetRandomObjectSize() { objectSize treeType = SizesPropability[random.Next(0, 10)]; return(treeType); }