Exemple #1
0
    IEnumerator RunOrange()
    {
        foreach (var i in Times(10))
        {
            AnimateRect(Direction.Down, 1, Vector2.one * 0.5f, orange, CameraHelper.RandomXOffset(0.9f), level: 0);
            yield return(Rest(1));
        }

        int   ornamentation = 1;
        float boundFactor   = 0.1f;

        foreach (var i in Times(20))
        {
            var progress = i / 20f;

            // Gradually add ornamentation
            var offset = CameraHelper.RandomXOffset(0.6f);
            var scale  = Vector2.one * Random.Range(0.2f, 0.5f); // the big one
            var speed  = 1;

            var boundingRect = CameraHelper.BoundingRectOnPerimeter(
                Location.Top, CameraHelper.Width * boundFactor, CameraHelper.Height * boundFactor, offset);
            var foundationRect = RectHelper.RectFromCenterAndSize(boundingRect.center, scale);
            var formation      = GenerateFormation(foundationRect, boundingRect, Random.Range(1, 3));
            foreach (var rect in formation)
            {
                var lineSpeed = speed * Random.Range(1f - 0.3f * progress, 1f + 0.3f * progress);
                var level     = 0;
                if (rect == formation[0])
                {
                    lineSpeed = speed;
                    level     = -1;
                }
                AnimateRect(
                    Direction.Down,
                    lineSpeed,
                    rect.size,
                    new Color[] { orange, blue, red }[Random.Range(0, Mathf.CeilToInt(3 * progress))],
                    rect.center,
                    0);
            }
            yield return(Rest(2));

            ornamentation++;
            boundFactor += 0.05f;
        }
    }
Exemple #2
0
    List <Rect> GenerateFormation(Rect foundation, Rect boundary, int count, bool nonOverlapping = true)
    {
        var rects = new List <Rect>();

        rects.Add(foundation);
        int retries = 0;

        while (rects.Count <= count && retries < 1000)
        {
            var enclosed = new Vector2(
                foundation.width.RandomFraction(0.05f, 0.5f),
                foundation.height.RandomFraction(0.05f, 0.8f));
            var candidate = RectHelper.RectFromCenterAndSize(boundary.RandomPosition(), enclosed);
            if (nonOverlapping && rects.Any(r => r.Overlaps(candidate)))
            {
                retries++;
                continue;
            }
            rects.Add(candidate);
        }
        return(rects);
    }