From e8f757fb3c3b13649454e0b12d966404a481e8af Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 8 Jan 2023 07:41:28 +0100 Subject: [PATCH] Add "pop" sound when a crop is ready --- assets/pop.wav | 3 +++ assets/pop.wav.import | 24 ++++++++++++++++++++++++ island/CropTile.gd | 6 +++++- island/CropTile.tscn | 12 ++++++++++-- island/Island.tscn | 10 ++++++++++ island/Pop.gd | 14 ++++++++++++++ player/Player.tscn | 1 + 7 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 assets/pop.wav create mode 100644 assets/pop.wav.import create mode 100644 island/Pop.gd diff --git a/assets/pop.wav b/assets/pop.wav new file mode 100644 index 0000000..e1be0a7 --- /dev/null +++ b/assets/pop.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea1ba7c8e6592f5ac9e37f9f754c3f8aabf3738cd98f8a229dfbd555c7972705 +size 68628 diff --git a/assets/pop.wav.import b/assets/pop.wav.import new file mode 100644 index 0000000..7692c0a --- /dev/null +++ b/assets/pop.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://lkftwgdun745" +path="res://.godot/imported/pop.wav-6c96098d372cbccab3a694ff4f0bb6a9.sample" + +[deps] + +source_file="res://assets/pop.wav" +dest_files=["res://.godot/imported/pop.wav-6c96098d372cbccab3a694ff4f0bb6a9.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=0 diff --git a/island/CropTile.gd b/island/CropTile.gd index 377af0b..eef1447 100644 --- a/island/CropTile.gd +++ b/island/CropTile.gd @@ -7,7 +7,9 @@ signal on_complete() @onready var growth_timer: Timer = $GrowthTimer @onready var sprout_mesh: MeshInstance3D = $Plant/Sprout +@onready var pop_sound: AudioStreamPlayer3D = $Pop @export var debug_growth: bool = false +@export var debug_growth_offset: float = 0.0; func plant(): @@ -19,6 +21,8 @@ func plant(): func complete(): if not growth_timer.is_stopped(): growth_timer.stop() + print("Playing completition sound...") + pop_sound.play_with_random_pitch() emit_signal("on_complete") if debug_growth: plant() @@ -31,4 +35,4 @@ func _process(_delta): func _ready(): if debug_growth: - plant() + growth_timer.start(growth_timer.wait_time - debug_growth_offset) diff --git a/island/CropTile.tscn b/island/CropTile.tscn index 67d6167..c66f9d3 100644 --- a/island/CropTile.tscn +++ b/island/CropTile.tscn @@ -1,7 +1,9 @@ -[gd_scene load_steps=5 format=3 uid="uid://cf35yl04qtru3"] +[gd_scene load_steps=7 format=3 uid="uid://cf35yl04qtru3"] [ext_resource type="Script" path="res://island/CropTile.gd" id="1_7lls2"] [ext_resource type="Material" uid="uid://w0ipvdnh4l8s" path="res://island/CropMaterial.tres" id="2_1oajr"] +[ext_resource type="AudioStream" uid="uid://lkftwgdun745" path="res://assets/pop.wav" id="3_gur2a"] +[ext_resource type="Script" path="res://island/Pop.gd" id="4_5e7wk"] [sub_resource type="BoxShape3D" id="BoxShape3D_6ja5h"] size = Vector3(1, 0.1, 1) @@ -36,6 +38,12 @@ mesh = SubResource("ArrayMesh_28cd1") skeleton = NodePath("../../..") [node name="GrowthTimer" type="Timer" parent="."] -wait_time = 5.0 +wait_time = 2.0 + +[node name="Pop" type="AudioStreamPlayer3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.1, 0.5) +stream = ExtResource("3_gur2a") +attenuation_filter_cutoff_hz = 20500.0 +script = ExtResource("4_5e7wk") [connection signal="timeout" from="GrowthTimer" to="." method="complete"] diff --git a/island/Island.tscn b/island/Island.tscn index 7f7c04d..da04812 100644 --- a/island/Island.tscn +++ b/island/Island.tscn @@ -83,5 +83,15 @@ transform = Transform3D(1, 0, 0, 0, -0.337161, 0.941447, 0, -0.941447, -0.337161 transform = Transform3D(-1, 3.48787e-16, -8.74228e-08, 3.48787e-16, 1, -3.48787e-16, 8.74228e-08, -3.48787e-16, -1, 0, 4.89631, 0) [node name="CropTile" parent="." instance=ExtResource("8_4ooup")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 2, 8) +debug_growth = true + +[node name="CropTile2" parent="." instance=ExtResource("8_4ooup")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 8) debug_growth = true +debug_growth_offset = 0.5 + +[node name="CropTile3" parent="." instance=ExtResource("8_4ooup")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 2, 8) +debug_growth = true +debug_growth_offset = 0.6 diff --git a/island/Pop.gd b/island/Pop.gd new file mode 100644 index 0000000..01123f9 --- /dev/null +++ b/island/Pop.gd @@ -0,0 +1,14 @@ +extends AudioStreamPlayer3D + + +var rng: RandomNumberGenerator + + +func _ready(): + rng = RandomNumberGenerator.new() + rng.randomize() + + +func play_with_random_pitch(): + pitch_scale = rng.randf_range(0.3, 1.0) + play() \ No newline at end of file diff --git a/player/Player.tscn b/player/Player.tscn index dd04c02..ace7f11 100644 --- a/player/Player.tscn +++ b/player/Player.tscn @@ -147,6 +147,7 @@ stretch = true [node name="GameViewport" type="SubViewport" parent="Head/Viewport/CameraViewportContainer"] handle_input_locally = false +audio_listener_enable_3d = true size = Vector2i(284, 160) render_target_update_mode = 4