Add pop sound when player adds nodes

This commit is contained in:
Sebastian Morr 2020-09-24 10:52:58 +02:00
parent a083e6a1da
commit 806c39069b
6 changed files with 45 additions and 4 deletions

12
main.gd
View file

@ -74,6 +74,8 @@ func list_levels():
return final_level_sequence
func load_level(id):
AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), true)
next_level_button.hide()
level_congrats.hide()
level_description.show()
@ -133,6 +135,16 @@ func load_level(id):
terminal.clear()
# Unmute the audio after a while, so that player can hear pop sounds for
# nodes they create.
var t = Timer.new()
t.wait_time = 3
add_child(t)
t.start()
yield(t, "timeout")
AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), false)
# FIXME: Need to clean these up when switching levels somehow.
func reload_level():
load_level(current_level)

View file

@ -12,9 +12,14 @@ var hovered = false
var arrow = preload("res://arrow.tscn")
func _ready():
pass
# var t = Timer.new()
# t.wait_time = rand_range(0.0, 0.1)
# add_child(t)
# t.start()
# yield(t, "timeout")
$Pop.pitch_scale = rand_range(0.8, 1.2)
$Pop.play()
func _process(_delta):
if held:

View file

@ -1,8 +1,9 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://node.gd" type="Script" id=1]
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2]
[ext_resource path="res://nodes/blob.svg" type="Texture" id=3]
[ext_resource path="res://nodes/pop.wav" type="AudioStream" id=4]
[sub_resource type="StyleBoxFlat" id=1]
content_margin_left = 5.0
@ -61,5 +62,8 @@ __meta__ = {
}
[node name="Arrows" type="Node2D" parent="."]
[node name="Pop" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource( 4 )
[connection signal="mouse_entered" from="Rect" to="." method="_on_hover"]
[connection signal="mouse_exited" from="Rect" to="." method="_on_unhover"]

BIN
nodes/pop.wav Normal file

Binary file not shown.

21
nodes/pop.wav.import Normal file
View file

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/pop.wav-c45fbac324d41566fc00fa2a6560f011.sample"
[deps]
source_file="res://nodes/pop.wav"
dest_files=[ "res://.import/pop.wav-c45fbac324d41566fc00fa2a6560f011.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=false
compress/mode=0

View file

@ -143,7 +143,6 @@ func apply_forces():
o.position += dir*f
o2.position -= dir*f
var center_of_gravity = nodes.rect_size/2
print(center_of_gravity)
var d = o.position.distance_to(center_of_gravity)
var dir = (o.position - center_of_gravity).normalized()
var f = (d+0.00001)*Vector2(0.03, 0.01)