Skip to content

Commit

Permalink
finish adding sound effects and music
Browse files Browse the repository at this point in the history
  • Loading branch information
ar1a committed Oct 5, 2024
1 parent 6ffa725 commit 16ad540
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 10 deletions.
6 changes: 3 additions & 3 deletions assets/audio/Dancing at the Inn.mp3.import
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ dest_files=["res://.godot/imported/Dancing at the Inn.mp3-8c36b0374b80eb24c62f38

[params]

loop=false
loop_offset=0
bpm=0
loop=true
loop_offset=0.0
bpm=0.0
beat_count=0
bar_beats=4
Binary file added assets/audio/victory.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/audio/victory.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://cunxa4hmk4kk"
path="res://.godot/imported/victory.wav-d893d32ad919f27e15cf04d35e288b78.sample"

[deps]

source_file="res://assets/audio/victory.wav"
dest_files=["res://.godot/imported/victory.wav-d893d32ad919f27e15cf04d35e288b78.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2
3 changes: 2 additions & 1 deletion default_bus_layout.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[gd_resource type="AudioBusLayout" format=3 uid="uid://c1l5kcfkfpw77"]

[resource]
bus/0/volume_db = -11.9576
bus/1/name = &"Music"
bus/1/solo = false
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = 0.0
bus/1/volume_db = -5.625
bus/1/send = &"Master"
bus/2/name = &"SFX"
bus/2/solo = false
Expand Down
18 changes: 18 additions & 0 deletions scenes/autoload/AudioHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using Godot;

namespace Game.Autoload;
Expand All @@ -6,6 +7,8 @@ public partial class AudioHelpers : Node
{
private static AudioHelpers instance;
private AudioStreamPlayer explosionAudioStreamPlayer;
private AudioStreamPlayer clickAudioStreamPlayer;
private AudioStreamPlayer victoryAudioStreamPlayer;

public override void _Notification(int what)
{
Expand All @@ -18,10 +21,25 @@ public override void _Notification(int what)
public override void _Ready()
{
explosionAudioStreamPlayer = GetNode<AudioStreamPlayer>("ExplosionAudioStreamPlayer");
clickAudioStreamPlayer = GetNode<AudioStreamPlayer>("ClickAudioStreamPlayer");
victoryAudioStreamPlayer = GetNode<AudioStreamPlayer>("VictoryAudioStreamPlayer");
}

public static void PlayBuildingDestruction()
{
instance.explosionAudioStreamPlayer.Play();
}

public static void PlayVictory()
{
instance.victoryAudioStreamPlayer.Play();
}

public static void RegisterButtons(IEnumerable<Button> buttons)
{
foreach (var button in buttons)
{
button.Pressed += static () => instance.clickAudioStreamPlayer.Play();
}
}
}
19 changes: 18 additions & 1 deletion scenes/autoload/AudioHelpers.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[gd_scene load_steps=6 format=3 uid="uid://dcqg65t5mgi8q"]
[gd_scene load_steps=9 format=3 uid="uid://dcqg65t5mgi8q"]

[ext_resource type="Script" path="res://scenes/autoload/AudioHelpers.cs" id="1_05jao"]
[ext_resource type="AudioStream" uid="uid://b3cp2yrvnui03" path="res://assets/audio/explosion_01.wav" id="1_nngmb"]
[ext_resource type="AudioStream" uid="uid://bhinlvsm8b88h" path="res://assets/audio/Dancing at the Inn.mp3" id="2_ba6vs"]
[ext_resource type="AudioStream" uid="uid://67hpeisx8123" path="res://assets/audio/explosion_02.wav" id="2_tlw1b"]
[ext_resource type="AudioStream" uid="uid://clclehcxlxqih" path="res://assets/audio/explosion_03.wav" id="3_w66he"]
[ext_resource type="AudioStream" uid="uid://b3pjgvco20g2h" path="res://assets/audio/click.wav" id="5_0muqb"]
[ext_resource type="AudioStream" uid="uid://cunxa4hmk4kk" path="res://assets/audio/victory.wav" id="6_6ho6q"]

[sub_resource type="AudioStreamRandomizer" id="AudioStreamRandomizer_fe72c"]
streams_count = 3
Expand All @@ -14,7 +17,21 @@ stream_2/stream = ExtResource("3_w66he")
[node name="AudioHelpers" type="Node"]
script = ExtResource("1_05jao")

[node name="MusicAudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("2_ba6vs")
volume_db = -5.0
autoplay = true
bus = &"Music"

[node name="ExplosionAudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = SubResource("AudioStreamRandomizer_fe72c")
max_polyphony = 3
bus = &"SFX"

[node name="ClickAudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("5_0muqb")
bus = &"SFX"

[node name="VictoryAudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("6_6ho6q")
bus = &"SFX"
2 changes: 2 additions & 0 deletions scenes/ui/BuildingSection.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Game.Autoload;
using Game.Resources.Building;
using Godot;

Expand All @@ -21,6 +22,7 @@ public override void _Ready()
button = GetNode<Button>("%Button");

button.Pressed += () => EmitSignal(SignalName.Pressed);
AudioHelpers.RegisterButtons(new Button[] { button });
}

public void SetBuildingResource(BuildingResource buildingResource)
Expand Down
1 change: 1 addition & 0 deletions scenes/ui/GameUI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Game.Autoload;
using Game.Manager;
using Game.Resources.Building;
using Godot;
Expand Down
1 change: 1 addition & 0 deletions scenes/ui/LevelCompleteScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public override void _Ready()
{
nextLevelButton = GetNode<Button>("%NextLevelButton");
nextLevelButton.Pressed += OnNextLevelButtonPressed;
AudioHelpers.PlayVictory();
}

private void OnNextLevelButtonPressed()
Expand Down
7 changes: 3 additions & 4 deletions scenes/ui/LevelSelectScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public partial class LevelSelectScreen : MarginContainer
private int maxPageIndex;
private LevelDefinitionResource[] levelDefinitions;

//TODO: delete me?
private int startIndex => PAGE_SIZE * pageIndex;
private int endIndex => Mathf.Min(startIndex + PAGE_SIZE, levelDefinitions.Length);

public override void _Ready()
{
gridContainer = GetNode<GridContainer>("%GridContainer");
Expand All @@ -41,6 +37,9 @@ public override void _Ready()
backButton.Pressed += () => EmitSignal(SignalName.BackPressed);
previousPageButton.Pressed += () => OnPageChanged(-1);
nextPageButton.Pressed += () => OnPageChanged(1);
AudioHelpers.RegisterButtons(
new Button[] { backButton, previousPageButton, nextPageButton }
);

ShowPage();
}
Expand Down
2 changes: 1 addition & 1 deletion scenes/ui/LevelSelectSection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Game.Autoload;
using Game.Resources.Level;
using Godot;
Expand All @@ -24,6 +23,7 @@ public override void _Ready()
completedIndicator = GetNode<TextureRect>("%CompletedIndicator");

button.Pressed += OnButtonPressed;
AudioHelpers.RegisterButtons(new Button[] { button });
}

private void OnButtonPressed()
Expand Down
2 changes: 2 additions & 0 deletions scenes/ui/MainMenu.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Game.Autoload;
using Godot;

namespace Game.UI;
Expand All @@ -15,6 +16,7 @@ public override void _Ready()
levelSelectScreen = GetNode<LevelSelectScreen>("%LevelSelectScreen");
playButton = GetNode<Button>("%PlayButton");
quitButton = GetNode<Button>("%QuitButton");
AudioHelpers.RegisterButtons(new Button[] { playButton, quitButton });

mainMenuContainer.Visible = true;
levelSelectScreen.Visible = false;
Expand Down

0 comments on commit 16ad540

Please sign in to comment.