Esempio n. 1
0
    public void Start()
    {
        MagicColor color = (MagicColor)Random.Range(0, 3);

        Gem.ColorPart.ChangeColor(color);
        Health.Color = color;

        transform.position = EnemySpawner.Instance.HamsterSpawnLocations.GetNext().position;

        rb       = GetComponent <Rigidbody2D>();
        animator = GetComponent <Animator>();

        StartCoroutine(startRoutine());

        Health.Death.AddListener(() => {
            Gem.Launch();

            currentSpeed = DeathSpeed;
            if (RandomExtra.Chance(.5f))
            {
                currentSpeed *= -1;
            }

            StopAllCoroutines();

            GetComponent <Collider2D>().enabled = false;
            GetComponent <DestroyWhenChildrenInvisible>().ShouldDestroy = true;
        });
    }
Esempio n. 2
0
    IEnumerator moveRoutine()
    {
        moving  = true;
        moveDir = RandomExtra.Chance(.5f) ? Vector2.right : Vector2.left;

        float mainTimer      = Random.Range(MoveTimeRange.x, MoveTimeRange.y);
        float directionTimer = Random.Range(DirectionSwitchTimeRange.x, DirectionSwitchTimeRange.y);

        while (mainTimer > 0)
        {
            if (Mathf.Abs(transform.position.x - PlayerRef.transform.position.x) <= AttackDistance && RandomExtra.ChancePerSecond(AttackChancePerSecond))
            {
                moving = false;
                yield break; // do a grab, as long as the parent immediately calls grab
            }

            mainTimer      -= Time.deltaTime;
            directionTimer -= Time.deltaTime;

            if (directionTimer <= 0)
            {
                directionTimer = Random.Range(DirectionSwitchTimeRange.x, DirectionSwitchTimeRange.y);
                moveDir       *= -1;
            }

            transform.position += (Vector3)moveDir * MoveSpeed * Time.deltaTime;

            yield return(null);
        }

        moving = false;
    }
Esempio n. 3
0
    void moveTiles()
    {
        foreach (var cellPosition in Tilemap.cellBounds.allPositionsWithin)
        {
            if (Tilemap.GetTile(cellPosition) == null)
            {
                continue;
            }
            if (!RandomExtra.Chance(ChanceToTwitchPerTile))
            {
                continue;
            }

            var matrix   = Tilemap.GetTransformMatrix(cellPosition);
            var position = Random.insideUnitCircle * TileDisplacementRadius;

            if (RountTilesToNearestPixel)
            {
                position = new Vector2
                           (
                    Mathf.Round(position.x * 8) / 8,
                    Mathf.Round(position.y * 8) / 8
                           );
            }

            matrix[0, 3] = position.x;
            matrix[1, 3] = position.y;
            Tilemap.SetTransformMatrix(cellPosition, matrix);
        }
    }
    void spawnGoose()
    {
        Mage target;

        var nonActiveValidTargets = new List <Mage>
        {
            MageSquad.Instance.RedMage,
            MageSquad.Instance.GreenMage,
            MageSquad.Instance.BlueMage
        }
        .Where(m => !m.Active && !currentGooseTargets.Contains(m))
        .ToList();

        if ((nonActiveValidTargets.Count == 0 || RandomExtra.Chance(GooseTargetsActiveChance)) && !currentGooseTargets.Contains(MageSquad.Instance.ActiveMage))
        {
            target = MageSquad.Instance.ActiveMage;
        }
        else if (nonActiveValidTargets.Count > 0)
        {
            target = nonActiveValidTargets.PickRandom();
        }
        else
        {
            return;
        }

        currentGooseTargets.Add(target);

        var goose = Instantiate(GoosePrefab);

        goose.Initialize(target.transform);
        goose.Health.Death.AddListener(() => currentGooseTargets.Remove(target));
    }
Esempio n. 5
0
    void Start()
    {
        switch (Movement)
        {
        case MovementType.Cardinal:
            bool x = RandomExtra.Chance(.5f), p = RandomExtra.Chance(.5f);
            desiredVelocity = new Vector2(x ? p ? 1 : -1 : 0, !x ? p ? 1 : -1 : 0) * Speed;
            break;

        case MovementType.Diagonal:
            List <Vector2> directions = new List <Vector2>
            {
                new Vector2(1, 1),
                new Vector2(1, -1),
                new Vector2(-1, 1),
                new Vector2(-1, -1)
            };
            desiredVelocity = directions.PickRandom() * Speed;
            break;

        case MovementType.Follow:
            // do nothing
            break;

        default:
            throw new System.InvalidOperationException($"unexpected MovementType {Movement}");
        }

        Rigidbody.velocity = desiredVelocity;
    }
Esempio n. 6
0
    bool trySpawnObject(T spawn)
    {
        var w = CameraCache.Main.pixelWidth;
        var h = CameraCache.Main.pixelHeight;

        bool xIsStuck     = RandomExtra.Chance(.5f);
        bool stuckOnUpper = RandomExtra.Chance(.5f);

        Vector2 edgeLocScreen = new Vector2
                                (
            xIsStuck ? (stuckOnUpper ? w : 0) : Random.Range(0, w),
            !xIsStuck ? (stuckOnUpper ? h : 0) : Random.Range(0, h)
                                );

        Vector2 edgeLocWorld = CameraCache.Main.ScreenToWorldPoint(edgeLocScreen);

        Vector2 cardinal = new Vector2
                           (
            xIsStuck ? (stuckOnUpper ? 1 : -1) : 0,
            !xIsStuck ? (stuckOnUpper ? 1 : -1) : 0
                           );

        var     rad       = spawn.GetComponent <CircleCollider2D>().radius;
        Vector2 meteorPos = edgeLocWorld + cardinal * rad * 2;

        if (Physics2D.CircleCast(meteorPos, rad, Vector2.zero))
        {
            return(false);
        }

        Instantiate(spawn, meteorPos, Quaternion.identity);
        return(true);
    }
Esempio n. 7
0
    void Start()
    {
        SpawnScaleTransition.AttachMonoBehaviour(this);
        SpawnScaleTransition.FlashFromTo(0, 1);
        DeathScaleTransition.AttachMonoBehaviour(this);

        spriteIsOn = RandomExtra.Chance(.5f);
        flipSprite();

        initialPosition = transform.position;
    }
Esempio n. 8
0
    protected virtual void Awake()
    {
        TotalEnemies++;

        Health.Death.AddListener(() => {
            TotalEnemies--;

            if (RandomExtra.Chance(EnemySpawner.Instance.ItemDropRate))
            {
                Instantiate(EnemySpawner.Instance.ItemDropDistribution.GetNext(), transform.position, Quaternion.identity);
            }
        });
    }
    MagicColor getColor()
    {
        colorStreak++;

        var chance = ChanceToSwitchColorsByColorStreak.Evaluate(colorStreak);

        if (RandomExtra.Chance(chance))
        {
            currentColor = colors.GetNext();
            colorStreak  = 0;
        }

        return(currentColor);
    }
Esempio n. 10
0
    public void Launch()
    {
        transform.parent = null;

        launched     = true;
        rb.simulated = true;
        rb.velocity  = LaunchSpeed;
        // half the time, flip x:
        if (RandomExtra.Chance(.5f))
        {
            rb.velocity *= Vector2.left;
        }

        GetComponent <DestroyWhenChildrenInvisible>().ShouldDestroy = true;
    }
Esempio n. 11
0
    void setScale(float dt)
    {
        scaleDelta += (RandomExtra.Chance(.5f) ? -ScaleAccelMax : ScaleAccelMax) * dt;
        scaleDelta  = Mathf.Clamp(scaleDelta, ScaleDeltaBounds.x, ScaleDeltaBounds.y);

        var next = transform.localScale * scaleDelta;

        transform.localScale += (next - transform.localScale) * dt;
        transform.localScale  = new Vector3
                                (
            Mathf.Clamp(transform.localScale.x, ScaleBounds.x, ScaleBounds.y),
            Mathf.Clamp(transform.localScale.y, ScaleBounds.x, ScaleBounds.y),
            Mathf.Clamp(transform.localScale.z, ScaleBounds.x, ScaleBounds.y)
                                );
    }
Esempio n. 12
0
    void redistributeSpinWith(Top otherTop)
    {
        collisionLock          = true;
        otherTop.collisionLock = true;

        bool thisSpunFaster = CurrentSpin == otherTop.CurrentSpin
            ? RandomExtra.Chance(.5f) // ties are broken randomly
            : CurrentSpin > otherTop.CurrentSpin;

        Top fasterSpinningTop = thisSpunFaster ? this : otherTop;
        Top slowerSpinningTop = thisSpunFaster ? otherTop : this;

        Spin differential = Mathf.Min(fasterSpinningTop.CurrentSpin, Spin.MAX - slowerSpinningTop.CurrentSpin);

        fasterSpinningTop.CurrentSpin -= differential;
        slowerSpinningTop.CurrentSpin += differential;
    }
Esempio n. 13
0
 // returns the piece that is hit from cover fire, if there is one, otherwise null
 public BoardPiece TryHit()
 {
     // check middle first since we like it more
     if (RandomExtra.Chance(middleChance))
     {
         return(MiddleCover);
     }
     if (RandomExtra.Chance(leftChance))
     {
         return(LeftCover);
     }
     if (RandomExtra.Chance(rightChance))
     {
         return(RightCover);
     }
     return(null);
 }
Esempio n. 14
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));
    }
Esempio n. 15
0
    public void UseOn(IHackable target)
    {
        MethodInfo hackMethod = target.GetType().GetMethod(HackMethodName);

        hackMethod.Invoke(target, PassParam ? new object[] { HackMethodParam } : null);

        bool caught  = RandomExtra.Chance(RevealChance);
        bool patched = RandomExtra.Chance(PatchChance);

        if (caught)
        {
            SecurityManager.Instance.Alert = true;
        }
        if (patched)
        {
            InventoryManager.Instance.HacksToBePatched.Add(this);
            Debug.Log("you got patched son");
        }
    }
Esempio n. 16
0
    void OnTriggerEnter2D(Collider2D other)
    {
        bool effect = false;

        if (!appliedExtraEffect && RandomExtra.Chance(ExtraEffectChance))
        {
            appliedExtraEffect = false;
            effect             = true;
        }

        if (other.gameObject.layer == LayerMask.NameToLayer("Player"))
        {
            if (effect && Color == MagicColor.Green)
            {
                other.GetComponent <Mage>().Health.Heal(HealAmount);
            }
            return;
        }

        BaseEnemy enemy = other.gameObject.GetComponent <BaseEnemy>();

        if (enemy != null)
        {
            enemy.Health.ColorDamage(Damage, Color);

            if (effect)
            {
                if (Color == MagicColor.Red)
                {
                    enemy.ApplyFire(Random.Range(FireTimeMin, FireTimMax));
                }

                if (Color == MagicColor.Blue)
                {
                    enemy.ApplyIce(Random.Range(IceTimeMin, IceTimeMax));
                }
            }
        }

        Destroy(gameObject);
    }
Esempio n. 17
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. 18
0
    IEnumerator Start()
    {
        yield return(new WaitForSeconds(Cooldown));

        bool order = false;

        while (true)
        {
            bool coinChance = RandomExtra.Chance(CoinGameProbability.Evaluate(ScoreManager.Instance.CoinCount));
            bool washChance = RandomExtra.Chance(WashGameProbability.Evaluate(ScoreManager.Instance.Dirtiness));

            // might be unnecessary, but we'll switch which game we check first every time so we don't favor one over the other
            if (order = !order)
            {
                if (coinChance)
                {
                    SceneManager.LoadScene("Coin");
                }
                else if (washChance)
                {
                    SceneManager.LoadScene("Bath");
                }
            }
            else
            {
                if (washChance)
                {
                    SceneManager.LoadScene("Bath");
                }
                else if (coinChance)
                {
                    SceneManager.LoadScene("Coin");
                }
            }

            yield return(new WaitForSeconds(SecondsPerRoll));
        }
    }
Esempio n. 19
0
    IEnumerator deathRoutine()
    {
        Collider.enabled = false;

        yield return(new WaitForSeconds(DeathAnimationWaitTimeBeforeShrinking));

        float explosionChance = ChanceForDeathToBeExplosionDeathByDeathsSinceLastExplosionDeath.Evaluate(deathsSinceLastExplosionDeath);
        bool  exploding       = RandomExtra.Chance(explosionChance);

        float targetScale = exploding
            ? ExplosionDeathScaleTarget
            : NormalDeathScaleTarget;

        DeathScaleTransition.StartTransitionTo(targetScale);
        yield return(new WaitWhile(() => DeathScaleTransition.Transitioning));

        deathsSinceLastExplosionDeath = exploding
            ? 0
            : deathsSinceLastExplosionDeath + 1;

        BallDied.Raise();
        Destroy(gameObject);
    }
Esempio n. 20
0
    void switchTarget()
    {
        if (RandomExtra.Chance(PlayerGuaranteedTargetChance))
        {
            target = FindObjectOfType(typeof(Player)) as FlockLeader;
            return;
        }

        var potentialTargets = (FindObjectsOfType(typeof(FlockLeader)) as FlockLeader[]).ToList();

        potentialTargets.Remove(this);

        Func <FlockLeader, bool> inRange = fl => Vector3.Distance(fl.transform.position, transform.position) <= DesiredMaximumDistance;

        if (!potentialTargets.Where(fl => fl != target).Any(inRange))
        {
            target = potentialTargets.PickRandom();
        }
        else
        {
            target = potentialTargets.Where(fl => fl != target).Where(inRange).ToList().PickRandom();
        }
    }