Skip to content

Commit

Permalink
🔕 Respect mute button for hits
Browse files Browse the repository at this point in the history
  • Loading branch information
heytherewill committed Oct 2, 2023
1 parent 8b84ddc commit 576a3eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 6 additions & 0 deletions entities/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public abstract class Character : Node2D

[Export] public int CurrentHealth { get; protected set; }
[Export] protected int MaxHealth { get; set; } = 12;

public static bool ShouldPlaySound = true;

private CurrentAction? currentAction;
private Node2D? offset;
Expand Down Expand Up @@ -80,6 +82,7 @@ public void TakeDamage(int amountOfDamage)
var oldHealth = CurrentHealth;
CurrentHealth = Math.Max(CurrentHealth - amountOfDamage, 0);
redness = 1;

playHitSound();
EmitSignal(nameof(HealthChanged), CurrentHealth, MaxHealth, CurrentHealth - oldHealth);
if (CurrentHealth <= 0)
Expand All @@ -90,6 +93,9 @@ public void TakeDamage(int amountOfDamage)

private void playHitSound()
{
if (!ShouldPlaySound)
return;

if (GetNode<AudioStreamPlayer>("HitSound") is not { } sound)
{
return;
Expand Down
3 changes: 3 additions & 0 deletions scenes/main/AudioButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public bool Muted
{
if (muted == value) return;
muted = value;

Character.ShouldPlaySound = !muted;

if (muted)
{
audio?.Stop();
Expand Down
7 changes: 0 additions & 7 deletions scenes/main/TopHud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ public sealed class TopHud : Control
{
private const int maxWidth = 58;

public override void _Ready()
{

var audioButton = GetNode<TextureRect>("AudioButton");
// TODO: Handle clicks here????
}

public void UpdateHealth(int newHealth, int maxHealth)
{
var healthFill = GetNode<NinePatchRect>("HealthFill");
Expand Down

0 comments on commit 576a3eb

Please sign in to comment.