Esempio n. 1
0
    void Start()
    {
        transform.rotation = Quaternion.Euler
                             (
            Random.Range(0f, 360f),
            Random.Range(0f, 360f),
            Random.Range(0f, 360f)
                             );

        transform.localScale = Vector3.one * RandomExtra.Range(ScaleBounds);

        rotClamp = RotateClampNormal;

        // set up A, B, and C so that they add up to 1
        A = Random.Range(0f, 1f);
        B = Random.Range(0f, 1 - A);
        C = 1 - A - B;

        a = RandomExtra.Range(SinPhaseRange);
        b = RandomExtra.Range(SinPhaseRange);
        c = RandomExtra.Range(SinPhaseRange);

        startPos = transform.position;

        rend = GetComponent <Renderer>();
    }
Esempio n. 2
0
    IEnumerator Start()
    {
        while (true)
        {
            if (SpawnAtStart)
            {
                StartCoroutine(objectSpawnLoop());
            }

            TimeUntilNextSpawn = RandomExtra.Range(TimePerSpawnRange);

            while (TimeUntilNextSpawn > 0)
            {
                TimeUntilNextSpawn -= Time.deltaTime;
                yield return(null);
            }

            TimeUntilNextSpawn = 0;

            if (!SpawnAtStart)
            {
                StartCoroutine(objectSpawnLoop());
            }
        }
    }
Esempio n. 3
0
    IEnumerator throwAtTarget(Transform target)
    {
        transform.position = target.transform.position + InitialRelativePosition;
        transform.rotation = Quaternion.Euler(0, 0, RandomExtra.Range(AngleRange));

        var landTarget  = target.transform.position + (Vector3)(Random.insideUnitCircle * MaxDistanceFromTarget);
        var throwDir    = (Vector2)landTarget - (Vector2)transform.position;
        var throwTarget = landTarget - (Vector3)throwDir.normalized * Random.Range(0, LandTravel);

        ThrowTransition.FlashFromTo(transform.position, throwTarget);

        while (ThrowTransition.Transitioning)
        {
            transform.position = ThrowTransition.Value;
            yield return(null);
        }

        transform.position = throwTarget;

        LandTransition.FlashFromTo(transform.position, landTarget);

        while (LandTransition.Transitioning)
        {
            transform.position = LandTransition.Value;
            yield return(null);
        }

        transform.position = landTarget;
    }
Esempio n. 4
0
 IEnumerator wander()
 {
     while (true)
     {
         wanderLocalPosition = Random.insideUnitCircle * WanderRadius;
         yield return(new WaitForSeconds(RandomExtra.Range(TimeBetweenWanderingsRange)));
     }
 }
Esempio n. 5
0
    IEnumerator Start()
    {
        while (true)
        {
            yield return(new WaitForSeconds(RandomExtra.Range(TimeBetweenTwitchesRange)));

            moveTiles();
        }
    }
Esempio n. 6
0
    IEnumerator fartRoutine()
    {
        while (true)
        {
            yield return(new WaitForSeconds(RandomExtra.Range(FartTimeRange)));

            Instantiate(FartPrefab, transform.position, Quaternion.identity).Initialize(Gem.ColorPart.Color);
        }
    }
Esempio n. 7
0
    void Start()
    {
        MoveLagTransition.AttachMonoBehaviour(this);
        MoveLagTransition.Value = 1;

        startingVisualLocalPosition = Visual.transform.localPosition;

        wanderWaitTimer = RandomExtra.Range(TimeUntilWanderRange);
    }
Esempio n. 8
0
    List <AstronomicalBody> getPrefabsToSpawn()
    {
        List <AstronomicalBody> prefabs = new List <AstronomicalBody>(GuaranteedBodyPrefabs.Items);

        for (int i = 0; i < RandomExtra.Range(ExtraBodiesToSpawnRange); i++)
        {
            prefabs.Add(ExtraBodyPrefabs.GetNext());
        }

        prefabs.ShuffleInPlace();

        return(prefabs);
    }
    IEnumerator messageRoutine(string message)
    {
        text.text = message;
        transform.localPosition = Vector2.zero;

        var direction = Quaternion.AngleAxis(RandomExtra.Range(ArcAngleRange), Vector3.forward) * Vector3.down;

        rb.velocity = RandomExtra.Range(InitialSpeedRange) * direction;

        yield return(new WaitForSeconds(MessageTime));

        rb.velocity = Vector2.zero;
        text.text   = "";
    }
Esempio n. 10
0
    IEnumerator behaviorRoutine()
    {
        while (true)
        {
            if (shouldSwitchTarget())
            {
                switchTarget();
            }

            patienceTicker--;

            yield return(new WaitForSeconds(RandomExtra.Range(ChaseFrameTimeRange)));
        }
    }
Esempio n. 11
0
    IEnumerator Start()
    {
        var text = GetComponent <TextMeshProUGUI>();

        while (true)
        {
            var next = Fonts.GetNext();

            text.font     = next.Font;
            text.fontSize = next.Size;

            yield return(new WaitForSeconds(RandomExtra.Range(FontSwapTimeRange)));
        }
    }
Esempio n. 12
0
    void spawnCloud()
    {
        var velocity = Random.insideUnitCircle.normalized * RandomExtra.Range(CloudSpeedRange);

        var angles = new List <Quaternion>()
        {
            Quaternion.Euler(0, 0, 0),
            Quaternion.Euler(0, 0, 90),
            Quaternion.Euler(0, 0, 180),
            Quaternion.Euler(0, 0, 270),
        };

        Instantiate(FartCloudPrefab, transform.position, angles.PickRandom(), transform).Initialize(this, velocity, color);
    }
Esempio n. 13
0
    void Start()
    {
        List <AstronomicalBody> prefabs = getPrefabsToSpawn();
        List <AstronomicalBody> spawned = new List <AstronomicalBody>();

        int attemptedSpawnConfigurations = 0;

        while (spawned.Count < prefabs.Count && attemptedSpawnConfigurations < 1000)
        {
            List <Vector3> unitSphereDistribution = fibonacciSphere(prefabs.Count, true);

            for (int i = 0; i < prefabs.Count; i++)
            {
                Vector3 point;
                int     tryCount = 0;

                do
                {
                    point = transform.position + unitSphereDistribution[i] * RandomExtra.Range(DistanceFromSpawnRange);
                    tryCount++;
                } while (Physics.CheckSphere(point, prefabs[i].MinDistanceFromOtherColliders) && tryCount < SPAWN_TRIES_PER_PLANET);

                if (tryCount >= SPAWN_TRIES_PER_PLANET)
                {
                    foreach (AstronomicalBody spawn in spawned)
                    {
                        DestroyImmediate(spawn.gameObject);
                    }

                    spawned = new List <AstronomicalBody>();
                    attemptedSpawnConfigurations++;
                    break;
                }

                spawned.Add(Instantiate(prefabs[i], point, UnityEngine.Random.rotation));
            }
        }

        Debug.Log(attemptedSpawnConfigurations);

        if (attemptedSpawnConfigurations >= 1000)
        {
            throw new Exception("couldn't find a working configuration in a reasonable amount of time");
        }

        Goals = getGoals(prefabs);
    }
Esempio n. 14
0
    void explode()
    {
        int amount = RandomExtra.Range(PartsReleasedRange);

        for (int i = 0; i < amount; i++)
        {
            var fragment          = Object.Instantiate(PartsList.PickRandom(), transform.position, Quaternion.identity);
            var explosiveVelocity = Quaternion.AngleAxis(Random.Range(-ArcRange, ArcRange), Vector3.forward) * lastCollisionNormal;

            if (explosiveVelocity.magnitude > fragment.MaxBurstSpeed)
            {
                explosiveVelocity = explosiveVelocity.normalized * fragment.MaxBurstSpeed;
            }

            fragment.Rigidbody.velocity = explosiveVelocity;
        }
    }
Esempio n. 15
0
    void die()
    {
        Destroy(gameObject);

        foreach (ResourceType type in EnumUtil.AllValues <ResourceType>())
        {
            for (int i = 0; i < ResourceProfile[type]; i++)
            {
                Vector3 explosion = Random.onUnitSphere * RandomExtra.Range(ParticleExplosiveForceRange);
                var     particle  = Instantiate(ParticlePrefab, transform.position, Quaternion.LookRotation(explosion));
                particle.Initialize(Player.Instance.transform, type);
                particle.Rigidbody.AddForce(explosion, ForceMode.VelocityChange);
            }
        }

        PlanetExplosionEffect.Instance.Play(transform.position);
    }
Esempio n. 16
0
    public void Initialize(HamsterFart parent, Vector2 velocity, MagicColor color)
    {
        this.parent = parent;

        ColorPart.ChangeColor(color);

        bool use1 = RandomExtra.Chance(.5f);

        Outline.sprite = use1 ? Outline1 : Outline2;
        Cloud.sprite   = use1 ? Cloud1 : Cloud2;

        Outline.SetAlpha(Alpha);
        Cloud.SetAlpha(Alpha);

        GetComponent <Collider2D>().isTrigger = true; // just in case
        GetComponent <Rigidbody2D>().velocity = velocity;

        Destroy(gameObject, RandomExtra.Range(LifeTimeRange));
    }
    IEnumerator animateSpriteRendererInternal(float showDelay, SpriteRenderer spriteRenderer, bool loading)
    {
        Sprite finalSprite = loading ? spriteRenderer.sprite : null;

        if (loading)
        {
            spriteRenderer.sprite = null;
        }
        yield return(new WaitForSeconds(showDelay));

        var frames = loading ? LevelLoadAnimation : LevelUnloadAnimation;

        foreach (var frame in frames)
        {
            spriteRenderer.sprite = frame.Sprite;
            yield return(new WaitForSeconds(RandomExtra.Range(FrameTimeRange)));
        }

        spriteRenderer.sprite = finalSprite;
    }
Esempio n. 18
0
    void manageWandering()
    {
        if (Mover.Velocity != 0)
        {
            wanderWaitTimer = RandomExtra.Range(TimeUntilWanderRange);

            if (wandering)
            {
                wandering = false;
                StopAllCoroutines();
            }
        }
        else
        {
            wanderWaitTimer -= Time.deltaTime;

            if (wanderWaitTimer <= 0 && !wandering)
            {
                wandering = true;
                StartCoroutine(wander());
                returnToNormalColorTimer = RandomExtra.Range(TimeToReturnToNormalColorRange);
            }
        }

        if (wandering)
        {
            Visual.transform.localPosition = wanderLocalPosition;

            Visual.transform.position = new Vector3
                                        (
                Mathf.Round(Visual.transform.position.x * 8) / 8,
                Mathf.Round(Visual.transform.position.y * 8) / 8,
                Mathf.Round(Visual.transform.position.z * 8) / 8
                                        );
        }
        else
        {
            returnToNormalColorTimer -= Time.deltaTime;
        }
    }
Esempio n. 19
0
        // for spooky effects
        protected string randomAscii(int length, bool includeSpace = true)
        {
            Vector2Int printableCharacterRange = new Vector2Int
                                                 (
                32 + (includeSpace ? 0 : 1),
                127 // don't include delete (random is exclusive)
                                                 );

            StringBuilder sb = new StringBuilder();

            bool colorAdded = false;

            for (int i = 0; i < length; i++)
            {
                if (!colorAdded && RandomExtra.Chance(.02f))
                {
                    var color = MagicColorRamp.GetValue(Random.value);

                    sb.Append($"<#{ColorUtility.ToHtmlStringRGB(color)}>");
                    colorAdded = true;
                }

                sb.Append((char)RandomExtra.Range(printableCharacterRange));

                if (colorAdded && RandomExtra.Chance(.07f))
                {
                    sb.Append("</color>");
                    colorAdded = false;
                }
            }

            if (colorAdded)
            {
                sb.Append("</color>");
                colorAdded = false;
            }

            return(sb.ToString());
        }
Esempio n. 20
0
    IEnumerator ambleRoutine()
    {
        while (true)
        {
            currentSpeed = 0;
            animator.SetBool("Walking", false);

            yield return(new WaitForSeconds(RandomExtra.Range(AmblePauseTimeRange)));

            float mult = walkingDirection;
            if (isFrozen)
            {
                mult *= BaseMageBullet.IceSlowPercent;
            }

            walkingDirection *= -1;

            currentSpeed = AmbleSpeed * mult;
            animator.SetBool("Walking", true);

            yield return(new WaitForSeconds(AmbleTime * (isFrozen ? BaseMageBullet.IceSlowPercent : 1)));
        }
    }
Esempio n. 21
0
 public void SpawnEnemy(Vector3 position)
 {
     spawnFlock(position, EnemyLeaderPrefab, RandomExtra.Range(EnemyFlockSizeRange));
 }
Esempio n. 22
0
    IEnumerator playAnimation(bool loading)
    {
        if (TilemapCollider != null)
        {
            TilemapCollider.enabled = false;
        }

        List <IndividualTileAnimationTracker> animationData = new List <IndividualTileAnimationTracker>();

        foreach (var cellPosition in Tilemap.cellBounds.allPositionsWithin)
        {
            var tile = Tilemap.GetTile(cellPosition);
            if (tile == null)
            {
                continue;
            }

            animationData.Add(new IndividualTileAnimationTracker
            {
                Position     = cellPosition,
                FinalTile    = loading ? tile : null,
                CurrentFrame = -1,
                Frames       = loading ? Animation.LevelLoadAnimation : Animation.LevelUnloadAnimation
            });

            if (loading)
            {
                Tilemap.SetTile(cellPosition, null);
            }
        }

        yield return(new WaitForSeconds(ShowDelay));

        Vector3Int[] positionArray = new Vector3Int[animationData.Count];
        TileBase[]   tileArray     = new TileBase[animationData.Count];
        int          cursor        = 0;

        while (animationData.Count > 0)
        {
            foreach (var data in animationData)
            {
                data.Timer -= Time.deltaTime;
                if (data.Timer > 0)
                {
                    continue;
                }

                data.Timer = RandomExtra.Range(Animation.FrameTimeRange);
                data.CurrentFrame++;

                positionArray[cursor] = data.Position;
                tileArray[cursor]     = data.CurrentTile;
                cursor++;
            }

            Tilemap.SetTiles(positionArray, tileArray);
            animationData.RemoveAll(anim => anim.IsFinished);

            yield return(null);

            Array.Clear(positionArray, 0, cursor);
            Array.Clear(tileArray, 0, cursor);
            cursor = 0;
        }

        if (TilemapCollider != null && loading)
        {
            TilemapCollider.enabled = true;
        }
    }