void Update() { //get number of blocks that are turned off int currentNumberOfOffBlocks = _blocks.Count(x => !x.On); //If all blocks are on if (currentNumberOfOffBlocks == 0 && _lastNumberOfUnactivatedBlocks > 0) { //Play "tada" sound _multiSoundPlayer.PlaySound(1); _prize.SetActive(true); _blocks.ForEach(x => x.Lock()); } //positive: The number of on-blocks have gone up else if (currentNumberOfOffBlocks < _lastNumberOfUnactivatedBlocks) { //play spound with increased pitch _multiSoundPlayer.PlaySound(0, 1 + ((_blocks.Count - currentNumberOfOffBlocks) / (float)_blocks.Count)); } //Negative: The number of on- blocks have gone down else if (currentNumberOfOffBlocks > _lastNumberOfUnactivatedBlocks) { //play sound with decreased pitch _multiSoundPlayer.PlaySound(0, 1 + ((_blocks.Count - currentNumberOfOffBlocks) / (float)_blocks.Count)); } //update last state _lastNumberOfUnactivatedBlocks = currentNumberOfOffBlocks; }
private void OnTriggerStay2D(Collider2D collision) { if (collision.attachedRigidbody && !IsSubmerged(collision.attachedRigidbody)) { collision.attachedRigidbody.gravityScale *= GravityMultiplier; _bodiesInWater.Add(collision.attachedRigidbody); if (collision.gameObject.IsPlayer()) { _multiSoundPlayer.PlaySound(volume: 0.5f); } } }
/// <summary> /// Sets the button to be pressed if it isn't already /// </summary> public void Press() { if (Pressed) { return; } Pressed = true; _buttonUp.SetActive(false); _buttonDown.SetActive(true); //Make pressed sound _multiSoundPlayer.PlaySound(volume: 1.3f); }
private void Update() { //The player cannot wall jump at a repelling wall or whilst underwater if (RepellingWall.PlayerIsInRepellingArea || Water.IsSubmerged(_rigid)) { return; } ///Gets the normal of the adjacent wall (if there is one) Vector2?wallNormal = GetWallNormal(); //If there is an adjacent wall NextToWall = wallNormal != null && Mathf.Sign(wallNormal.Value.x) == -_flippable.DirectionSign; if (NextToWall) { //If the player attempts to jump while next to a wall, create a wall jump if (Input.GetButtonDown("Jump") && !this.OnGround2D()) { _rigid.SetVelocityY(0f); _rigid.velocity = (wallNormal.Value + Vector2.up * 0.75f).normalized * WallJumpForce; //Plays jump sound _multiSoundPlayer.PlaySound(index: 0, volume: 0.25f); } //Restrict maximum falling speed _rigid.velocity = _rigid.velocity.SetY(Mathf.Max(_rigid.velocity.y, -MaxFallSpeedOnWall)); } }
/// <summary> /// Coroutine: Causes the player to jump dynamically /// </summary> /// <returns></returns> private IEnumerator CoJump() { //The amount of real-time seconds that have passed since the start of the jump float seconds = 0f; //Gets the jump force to apply float jumpForce = JumpForce; float jumpReleaseForce = JumpReleaseForce; if (Commons.PowerUpManager.HasPowerUp(PowerUp.Invincibility)) { jumpForce *= Commons.PowerUpManager.InvincibilityJumpMultiplier; jumpReleaseForce *= Commons.PowerUpManager.InvincibilityJumpMultiplier; } //Set the initial jump velocity _rigid.SetVelocityY(jumpForce); //Plays jump sound _multiSoundPlayer.PlaySound(index: 0, volume: 0.25f); //Switches solidity of JumpSwitchBlocks foreach (var i in FindObjectsOfType <JumpSwitchBase>()) { i.OnJump(); } //As long as the player can still hold the button while (seconds < 0.15f || Cheats.MoonJump) { //The player is still holding the jump button, keep adding force if (Input.GetButton("Jump")) { //The player has hit a ceiling. Stop if (_rigid.velocity.y < jumpForce / 2f && !Cheats.MoonJump) { yield break; } //Keep the players jump _rigid.SetVelocityY(jumpForce); } //The player has let go of the jump button else { if (_rigid.velocity.y > jumpReleaseForce) { _rigid.SetVelocityY(jumpReleaseForce); } yield break; } seconds += Time.fixedDeltaTime; yield return(new WaitForFixedUpdate()); } }
private IEnumerator MakeTickNoise() { while (CurrentSeconds > 0 && CurrentSeconds > BlinkingTime) { _multiSoundPlayer.PlaySound(0); yield return(new WaitForSeconds(0.5f)); _multiSoundPlayer.PlaySound(1); yield return(new WaitForSeconds(0.5f)); } while (CurrentSeconds > 0 && CurrentSeconds > BlinkingTime / 2) { _multiSoundPlayer.PlaySound(0); yield return(new WaitForSeconds(0.25f)); _multiSoundPlayer.PlaySound(1); yield return(new WaitForSeconds(0.25f)); } while (CurrentSeconds > 0) { _multiSoundPlayer.PlaySound(0); yield return(new WaitForSeconds(0.15f)); _multiSoundPlayer.PlaySound(1); yield return(new WaitForSeconds(0.15f)); } }
/// <summary> /// Counts up or down the currency counter /// </summary> /// <param name="startValue"></param> /// <returns></returns> private IEnumerator CoCount(int startValue) { int count = startValue; bool lastTickPlayedSound = false; while (count != _lastKnownCurrencyValue) { if (count > _lastKnownCurrencyValue) { count--; if (lastTickPlayedSound = !lastTickPlayedSound) { _multiSoundPlayer.PlaySound(0); } } else { count++; if (lastTickPlayedSound = !lastTickPlayedSound) { _multiSoundPlayer.PlaySound(1); } } SetLabel(count.ToString()); if (_smack != null) { _smack.Smack(); } yield return(new WaitForSecondsRealtime(0.05f)); } _counterRunning = false; }
private void Update() { if (_playerInRange && Input.GetButtonDown("Interact")) { if (Commons.Inventory.GeneralKeys > 0) { Commons.Inventory.GeneralKeys--; Commons.RoomGenerator.RoomParameterBuilderOverrides.Push(Instantiate(GeneratorOverride)); Commons.RoomGenerator.GenerateNext(); } else { _multiSoundPlayer.PlaySound(); } } }
private void Update() { bool isSubmerged = Water.IsSubmerged(_rigidbody); //Let the player jump out of the water properly if (!isSubmerged && _lastSubmergeState && Input.GetButton("Jump")) { _rigidbody.SetVelocityY(JumpOutForce); } _lastSubmergeState = Water.IsSubmerged(_rigidbody); //If not in water, don't run the rest of the script if (!isSubmerged) { return; } //Swim up if (Input.GetButtonDown("Jump")) { /* * If the player is sinking at a high speed they are decelerated so that the sinking effect isn't so strong * that the swimming isn't doing anything * In other words... game feel */ float clampedSinkSpeedBeforeSwim = MaxSinkSpeed / 4; _rigidbody.SetVelocityY(currentY => Math.Max(-clampedSinkSpeedBeforeSwim, currentY)); _rigidbody.velocity += Vector2.up * SwimForce; //Restart the swim stroke _animator.RestartAnimation(); //Play sound _multiSoundPlayer.PlaySound(index: 1, volume: 0.25f); } //Clamp speeds _rigidbody.SetVelocityY(currentY => Mathf.Clamp(currentY, -MaxSinkSpeed, MaxAscensionSpeed)); _rigidbody.SetVelocityX(currentX => Mathf.Clamp(currentX, -MaxHorizontalSpeed, MaxHorizontalSpeed)); }
/// <summary> /// <inheritdoc /> /// </summary> /// <param name="hurtbox"></param> protected override void OnReceiveDamage(Hurtbox hurtbox) { //Dead men don't scream if (Commons.PlayerHealth.IsDead) { return; } //Play sound _multiSoundPlayer.PlaySound(); //Hitboxes are not active when noclip is enabled if (Cheats.Noclip) { return; } GrantInvincibilityFrames(); Commons.PlayerHealth.DealDamage(hurtbox.GetDamage(this)); if (Commons.PlayerHealth.IsDead) { //Player is dead. Explode if (_exploder) { _exploder.ExplodeBig(); } } else { //Player was hurt. Splinter if (_exploder && !hurtbox.IgnoresInvincibilityFrames) { _exploder.ExplodeSmall(); } } }
public override void OnPickup() { _multiSoundPlayer.PlaySound(ClipIndex); }
private void OnCollisionEnter2D(Collision2D collision) { /* * Sound */ //If block is visible if (Commons.IsVectorOnScreen(collision.contacts.First().point, _mainCamera)) { //Play sound at normal volume if collision is player if (collision.gameObject.IsPlayer()) { _multiSoundPlayer.PlaySound(); } //Play sound at 40% volume else if (!collision.gameObject.GetComponent <Projectile>()) { _multiSoundPlayer.PlaySound(volume: 0.4f); } } /* * Collision logic */ ContactPoint2D contact = collision.GetContact(0); Vector2 relativeVelocity = collision.relativeVelocity; //If the collision is from the side if (contact.normal.x != 0) { //if the collision is with a player: disable the speed cap for a little while if (collision.gameObject == this.GetPlayer()) { _noSpeedCapTimeLeft = NoSpeedCapTime; } int direction = Math.Sign(relativeVelocity.x); float pushBack = Mathf.Max(Math.Abs(relativeVelocity.x), MinimumPushBackVelocity); //Invert and add velocity collision.rigidbody.SetVelocityX(pushBack * -direction); } //if the collision is from top or bottom else { int direction = Math.Sign(relativeVelocity.y); float pushBack = Mathf.Max(Math.Abs(relativeVelocity.y), MinimumPushBackVelocity); //if the collision is with a player: check if the player is holding jump if (collision.gameObject == this.GetPlayer()) { //If the player is holding jump: multiply the vertical speed if (Input.GetButton("Jump")) { pushBack *= HoldingJumpScale; } //Tell jump controller not to allow double jumps _playerJumpController.Value.CaptureSuccessfulJumpSnapshot(); } //Invert and add velocity collision.rigidbody.SetVelocityY(pushBack * -direction); } }
private void PlayErrorSound() { _multiSoundPlayer.PlaySound(2); }
/// <summary> /// <inheritdoc /> /// </summary> /// <param name="hurtbox"></param> protected override void OnReceiveDamage(Hurtbox hurtbox) { //Play damage sound if (_multiSoundPlayer && !(hurtbox is PlayerInvincibilityHurtbox && !Commons.PowerUpManager.HasPowerUp(PowerUp.Invincibility))) { _multiSoundPlayer.PlaySound(-1, 1, 0.5f); } if (!(hurtbox is PlayerInvincibilityHurtbox)) { MakeEnemyBlindChase(); } if (TriggersAdrenalineMusic && !(hurtbox is GlobalHurtbox) && hurtbox.GetDamage(this) != 0) { Commons.SoundtrackPlayer.AddAdrenalineTrigger(this, 5f); } //Dead men don't scream if (_health.IsDead) { return; } //Give I-frames GrantInvincibilityFrames(); //Deal damage int damage = hurtbox.GetDamage(this); _health.DealDamage(damage); //Create damage pop-up CreateDamagePopNumber(damage); if (_health.IsDead) { //Explode foreach (var i in GetComponentsInChildren <ParticleExplosion>()) { i.ExplodeBig(); } //Drop items foreach (var i in GetComponentsInChildren <DropLootTableOnDeath>()) { i.DropItem(); } //Destroy the object Destroy(transform.parent.gameObject); } else { if (hurtbox.IgnoresInvincibilityFrames) { return; } //Drop some scraps foreach (var i in GetComponentsInChildren <ParticleExplosion>()) { i.ExplodeSmall(); } } }