示例#1
0
 public virtual void PlayDeathEffects()
 {
     if (deathSound.Length > 0)
     {
         GetComponent <AudioSource>().PlayOneShot(UtilRandom.RandomFromArray(deathSound) as AudioClip);
     }
 }
示例#2
0
        public override object Generate(ColumnModel model)
        {
            if (model is not RandomPatternModel specModel)
            {
                throw new ApplicationException("Mismatch in model " + model.ColumnDefinitionType +
                                               " inside generator " + GetType().Name);
            }
            var result = specModel.Template;

            while (true)
            {
                var regex = new Regex(UtilDataGeneration.SourceNameExpression);
                var match = regex.Match(result);
                if (!match.Success)
                {
                    break;
                }

                var patternName    = match.Groups[1].Value;
                var currentPattern = specModel.Patterns.ContainsKey(patternName) ? specModel.Patterns[patternName] :
                                     _defaultPatterns.ContainsKey(patternName) ? _defaultPatterns[patternName] : "ABC";
                var c = UtilRandom.GetCharFromString(currentPattern, _rnd);
                result = regex.Replace(result, c.ToString(), 1);
            }

            return(result);
        }
示例#3
0
    public virtual void PlayGroundLandEffects()
    {
        float time = GameTime.time;

        if (time < nextGroundHitEffect)
        {
            return;
        }
        nextGroundHitEffect = time + 0.333f;

        if (footLandHardSound.Length > 0)
        {
            GetComponent <AudioSource>().PlayOneShot(UtilRandom.RandomFromArray(footLandHardSound) as AudioClip);
        }
        if (landGroundHardParticles)
        {
            landGroundHardParticles.Play();
        }

        // Send the camera info about the footstep for rolling effect.
        PlayerCamera pc = Camera.main.GetComponent <PlayerCamera>();

        if (pc)
        {
            pc.HitGround();
        }
    }
示例#4
0
        public void RandomStringTest()
        {
            int length = 999;
            var str    = UtilRandom.GetRandomString(length);

            str.Length.Should().Be(length);
        }
示例#5
0
    void HitGround(Collision collision)
    {
        // Don't play this effect too often or while dead.
        if (Time.time < nextGroundHitEffect || isDead)
        {
            return;
        }

        nextGroundHitEffect = Time.time + 0.25f;

        // Only play this effect if we hit the ground hard enough on the local Y axis.
        if ((warp * collision.relativeVelocity).y >= 5.0f)
        {
            // Play a different impact sound depending on hard / soft ground.
            AudioClip[] audioclips = isOnSoftGround ? footLandSoftSound : footLandHardSound;
            if (audioclips.Length > 0)
            {
                GetComponent <AudioSource>().PlayOneShot(UtilRandom.RandomFromArray(audioclips) as AudioClip);
            }

            ParticleSystem system = isOnSoftGround ? landGroundSoftParticles : landGroundHardParticles;
            system.Play();

            // Send camera message we hit the ground so it can play a view punch effect.
            if (playerCamera)
            {
                playerCamera.HitGround();
            }
        }
    }
 private void Start()
 {
     if (UtilRandom.Bool(chance))
     {
         OnFired();
     }
 }
示例#7
0
        // Callback function invoked when the cooldown timer is finished.
        private void CooldownFinished(float secondsOverflow)
        {
            // Choose a random attack.
            AttackHandler attack = UtilRandom.GetRandomElement(attacks);

            // Execute the attack.
            attack(boss);
        }
示例#8
0
 public override object Generate(InlineSourceModel model)
 {
     if (model.Content == null || model.Content.Count == 0)
     {
         return("--ND--");
     }
     return(UtilRandom.GetValueFromList(model.Content, Rnd));
 }
 private void Start()
 {
     ac    = ServiceLocator.GetAudioController();
     timer = new Timer(UtilRandom.RangeWithCenter(
                           secondsBetweenSounds, secondsBetweenSoundsVariance),
                       TimerFinished, true);
     timer.Run();
 }
示例#10
0
 public void GetUnrepeatIntsTest()
 {
     for (int i = 0; i < 10000; i++)
     {
         var input = UtilRandom.GetString(100, UtilRandom.RandomCharType.Number);
         Regex.IsMatch(input, @"^\d{100}$").Should().BeTrue(input);
     }
 }
    protected override void Instantiated(GameObject obj, float secondsOverflow)
    {
        float   magnitude = UtilRandom.RangeWithCenter(valueCenter, valueRadius);
        float   direction = UtilRandom.RangeWithCenter(directionCenter, directionRadius);
        Vector2 velocity  = Angle.FromDegrees(direction).GetHeadingVector() * magnitude;

        obj.GetComponent <Velocity2D>().SetVelocity(velocity);
    }
示例#12
0
    private void Fire()
    {
        AudioClip clip = sounds.GetRandomElement();

        ac.PlaySFX(clip);
        timer.SetSecondsTarget(clip.length + UtilRandom.RangeWithCenter(
                                   secondsBetweenSounds, secondsBetweenSoundsVariance));
    }
示例#13
0
 public override object Generate(FileSourceModel model)
 {
     if (_content == null || _content.Count == 0)
     {
         LoadSource(model);
     }
     return(UtilRandom.GetValueFromList(_content, Rnd));
 }
示例#14
0
        public override object Generate(ColumnModel model)
        {
            if (model is not IntegerRangeModel specModel)
            {
                throw new ApplicationException("Mismatch in model " + model.ColumnDefinitionType +
                                               " inside generator " + GetType().Name);
            }
            var result = UtilRandom.NextInteger(specModel.Min, specModel.Max, _rnd);

            return(result);
        }
示例#15
0
    private void Start()
    {
        oscillator.enabled = false;
        lerper.enabled     = true;
        lerper.Completed  += LerpFinish;

        damage.Add(data.damage);

        timerIdle = new Timer(UtilRandom.RangeWithCenter(data.secondsToIdle,
                                                         data.secondsToIdleVariance), TimerIdleFinish, false);
        timerIdle.Run();
    }
示例#16
0
    private void Start()
    {
        timerWarning = new Timer(data.secondsOfWarning, WarningFinish, false);
        timerIdle    = new Timer(data.secondsOfIdling, IdleFinish, false);
        timerWarning.Run();
        GameObject warning = Instantiate(data.prefabWarning, transform);

        warning.transform.position = transform.position + Vector3.up * warningHeight;
        // Set the destroy time for the floor spike warning.
        warning.GetComponent <MonoTimer>().SetSecondsTarget(data.secondsOfWarning);
        damage.Add(data.damage);
        heightToRise = UtilRandom.RangeWithCenter(data.heightToRise, data.heightToRiseVariance);
    }
示例#17
0
    public virtual void PlayJumpEffects()
    {
        float time = GameTime.time;

        if (time < nextJumpEffect)
        {
            return;
        }
        nextJumpEffect = time + 0.333f;

        if (jumpSound.Length > 0)
        {
            GetComponent <AudioSource>().PlayOneShot(UtilRandom.RandomFromArray(jumpSound) as AudioClip);
        }
    }
示例#18
0
        public override object Generate(ColumnModel model)
        {
            if (model is not TemplateModel specModel)
            {
                throw new ApplicationException("Mismatch in model " + model.ColumnDefinitionType +
                                               " inside generator " + GetType().Name);
            }
            if (string.IsNullOrEmpty(specModel.Template))
            {
                specModel.Template = $"{{{GenerationInfo.Sources[0].Name}}}";
            }

            var result = specModel.Template;

            if (_itemGenerators == null)
            {
                _itemGenerators = new Dictionary <string, GeneratorItemBase>();
            }

            while (true)
            {
                var regex = new Regex(@"\{([\w\-|]+)\}");
                var match = regex.Match(result);
                if (!match.Success)
                {
                    break;
                }

                var patternName = match.Groups[1].Value;
                if (patternName.Contains("|"))
                {
                    var sourceArray = patternName.Split('|');
                    patternName = UtilRandom.GetValueFromList(sourceArray, _rnd);
                    _logger.LogInformation($"patternName: {patternName}");
                }

                var sourceModel = GetSource(patternName);
                if (sourceModel == null)
                {
                    return("--ND--");
                }
                var itemGenerator = GetItemGenerator(_itemGenerators, sourceModel);
                var value         = itemGenerator.Generate(sourceModel);
                result = regex.Replace(result, value.ToString(), 1);
            }

            return(result);
        }
示例#19
0
    void DoPlayerDeath(DeathType deathtype)
    {
        if (isDead)
        {
            return;
        }

        if (deathtype == DeathType.Pierce)
        {
            SetState(PlayerState.DeadImpaled);
        }
        else
        {
            SetState(PlayerState.Dead);
        }

        // Send HUD info so it can dim and red the screen.
        if (gameHUD)
        {
            gameHUD.DoPlayerDeath(deathtype);
        }

        // Used for allowing the camera to free rotate if we're falling forever.
        m_diedFromFall = deathtype == DeathType.Fall;

        /*if (deathtype != DeathType.Fall)
         *      resetGravity(true);*/

        // All sorts of different sounds depending on how we died!
        AudioClip[] sounds;
        if (deathtype == DeathType.Pierce)
        {
            sounds = deathSoundImpaled;
        }
        else if (deathtype == DeathType.Fall)
        {
            sounds = deathSoundFall;
        }
        else
        {
            sounds = deathSound;
        }

        if (sounds.Length > 0)
        {
            GetComponent <AudioSource>().PlayOneShot(UtilRandom.RandomFromArray(sounds) as AudioClip, 1.0f);
        }
    }
示例#20
0
        public override object Generate(ColumnModel model)
        {
            if (model is not RandomCharsModel specModel)
            {
                throw new ApplicationException("Mismatch in model " + model.ColumnDefinitionType +
                                               " inside generator " + GetType().Name);
            }
            var resultLength = UtilRandom.NextInteger(specModel.MinLength, specModel.MaxLength, _rnd);
            var sb           = new StringBuilder();

            for (var i = 0; i < resultLength; i++)
            {
                var c = UtilRandom.GetCharFromString(specModel.AllowedChars, _rnd);
                sb.Append(c);
            }

            return(sb.ToString());
        }
示例#21
0
    // Populates the grid of cubes.
    private void PopulateGrid()
    {
        // Clicking the wrong cube will take points away.
        Action <AppendixCube> cubeCallback = (x) => x.Clicked += WrongCubeClicked;

        // Instantiate the grid of cubes.
        cubes = UtilInstantiate.GridOfRectTransforms <AppendixCube>(
            Tuning.gridWidth, Tuning.gridHeight, prefabCube, true,
            gridContainer, 0.5f, cubeCallback);

        if (cubes.Count != 0)
        {
            // Choose a random cube and make it the Appendix.
            AppendixCube appendix = UtilRandom.GetRandomElement(cubes);
            appendix.MakeIntoAppendix();
            // Clicking the appendix won't take points away.
            appendix.Clicked -= WrongCubeClicked;
            // Clicking the appendix will win the game.
            appendix.Clicked += WinGame;
        }
    }
示例#22
0
    private void DoFootsteps()
    {
        // Play footstep effects based on how fast we're moving in our ground normalized plane.
        float speed = GetComponent <Rigidbody>().velocity.magnitude;

        if (speed < footStepMinSpeed)
        {
            return;
        }

        // Next time we play is based on our speed.
        float speedPerMaxSpeed = Mathf.Min(1.0f, speed / maxGroundSpeed);
        float nextFootStep     = lastFootStep + Mathf.Max(footStepMinTime, footStepMaxTime * (1 - speedPerMaxSpeed));

        if (Time.time >= nextFootStep)
        {
            lastFootStep = Time.time;
            swapfoot     = !swapfoot;

            AudioClip[] audioclips = isOnSoftGround ? footStepSoftSound : footStepHardSound;             // Hard or soft material sounds?
            AudioClip   clip       = UtilRandom.RandomFromArray(audioclips) as AudioClip;

            // Play softer/louder depending on current speed.
            float magnitude = 0.5f + speedPerMaxSpeed * 0.5f;

            if (clip != null)
            {
                GetComponent <AudioSource>().PlayOneShot(clip, magnitude);
            }

            ParticleSystem system = isOnSoftGround ? swapfoot ? hitGroundSoftRightParticles : hitGroundSoftLeftParticles : swapfoot ? hitGroundHardRightParticles : hitGroundHardLeftParticles;
            system.Play();

            // Send the camera info about the footstep for rolling effect.
            if (playerCamera)
            {
                playerCamera.DoFootstep(magnitude, swapfoot);
            }
        }
    }
 protected override void Instantiated(GameObject obj, float secondsOverflow)
 {
     obj.GetComponent <RootDamage>().Add(UtilRandom.RangeWithCenter(valueCenter, valueRadius));
 }
示例#24
0
 public Sprite GetRandomElement()
 {
     return(UtilRandom.GetRandomElement(array));
 }
示例#25
0
 public AudioClip GetRandomElement()
 {
     return(UtilRandom.GetRandomElement(array));
 }
示例#26
0
 public Vector3 GetRandomFloorPosition()
 {
     return
         (UtilRandom.PositionBetweenTwoPoints(bottomLeft.position, bottomRight.position));
 }
示例#27
0
 // Returns a random collection of items from the unclaimed list without removing them.
 // The index of each item returned will be different.
 public List <T> GetRandomElementsUniqueUnclaimed(int count)
 {
     return(UtilRandom.GetRandomElementsUnique(unclaimed, count));
 }
示例#28
0
 // Returns a random element from the unclaimed list without removing it.
 public T GetRandomElementUnclaimed()
 {
     return(UtilRandom.GetRandomElement(unclaimed));
 }
示例#29
0
 public Boss.Data GetRandomBoss()
 {
     return(UtilRandom.GetRandomElement(pool));
 }
示例#30
0
 protected override void Instantiated(GameObject obj, float secondsOverflow)
 {
     obj.GetComponent <AngularVelocity2D>().SetAngularVelocity(UtilRandom.RangeWithCenter(valueCenter, valueRadius));
 }