mirror of
https://github.com/Steffo99/swear-jar.git
synced 2024-11-25 09:04:19 +00:00
Randomize sound
This commit is contained in:
parent
0d378f16d4
commit
9bcda63b84
3 changed files with 45 additions and 21 deletions
|
@ -1,8 +1,6 @@
|
||||||
extends StaticBody2D
|
extends StaticBody2D
|
||||||
class_name Converter
|
class_name Converter
|
||||||
|
|
||||||
var coda : int = 0
|
|
||||||
|
|
||||||
@export var sprite_front: AnimatedSprite2D
|
@export var sprite_front: AnimatedSprite2D
|
||||||
@export var sprite_back: AnimatedSprite2D
|
@export var sprite_back: AnimatedSprite2D
|
||||||
@export var conversion_timer: Timer
|
@export var conversion_timer: Timer
|
||||||
|
@ -10,25 +8,38 @@ var coda : int = 0
|
||||||
@export var sound_complete: AudioStreamPlayer
|
@export var sound_complete: AudioStreamPlayer
|
||||||
@export var spawner: Spawner
|
@export var spawner: Spawner
|
||||||
|
|
||||||
func _on_collector_goal():
|
## Amount of scenes this converter should produce.
|
||||||
coda+=1
|
var to_produce: int = 0
|
||||||
|
|
||||||
func _process(_delta):
|
## Amount of scenes this converter should spawn.
|
||||||
if coda>=1 and conversion_timer.is_stopped():
|
var to_spawn: int = 0
|
||||||
|
|
||||||
|
func _on_collector_goal():
|
||||||
|
to_produce += 1
|
||||||
|
|
||||||
|
func _physics_process(_delta):
|
||||||
|
if to_produce >= 1 and conversion_timer.is_stopped():
|
||||||
|
to_produce -= 1
|
||||||
|
produce()
|
||||||
|
|
||||||
|
func produce():
|
||||||
|
conversion_timer.start()
|
||||||
|
if sprite_front:
|
||||||
sprite_front.play()
|
sprite_front.play()
|
||||||
if not sprite_back==null:
|
if sprite_back:
|
||||||
sprite_back.play()
|
sprite_back.play()
|
||||||
conversion_timer.start()
|
if sound_working:
|
||||||
sound_working.play()
|
sound_working.play()
|
||||||
|
|
||||||
func _on_timer_timeout():
|
func _on_timer_timeout():
|
||||||
coda-=1
|
|
||||||
sprite_front.stop()
|
|
||||||
if not sprite_back==null:
|
|
||||||
sprite_back.stop()
|
|
||||||
sound_working.stop()
|
|
||||||
sound_complete.play()
|
|
||||||
spawner.spawn()
|
spawner.spawn()
|
||||||
|
if sprite_front:
|
||||||
|
sprite_front.stop()
|
||||||
|
if sprite_back:
|
||||||
|
sprite_back.stop()
|
||||||
|
if sound_working:
|
||||||
|
sound_working.stop()
|
||||||
|
|
||||||
|
|
||||||
var is_pending_deletion: bool = false
|
var is_pending_deletion: bool = false
|
||||||
|
|
||||||
|
@ -40,7 +51,7 @@ func ending_deletion():
|
||||||
sprite_front.modulate = Color.WHITE
|
sprite_front.modulate = Color.WHITE
|
||||||
is_pending_deletion = false
|
is_pending_deletion = false
|
||||||
|
|
||||||
func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int):
|
func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int):
|
||||||
if is_pending_deletion:
|
if is_pending_deletion:
|
||||||
if event is InputEventMouseButton or event is InputEventScreenTouch:
|
if event is InputEventMouseButton or event is InputEventScreenTouch:
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
|
@ -71,7 +71,7 @@ script = ExtResource("1_mas6k")
|
||||||
sprite_front = NodePath("SpriteFront")
|
sprite_front = NodePath("SpriteFront")
|
||||||
conversion_timer = NodePath("ConversionTimer")
|
conversion_timer = NodePath("ConversionTimer")
|
||||||
sound_working = NodePath("SoundWorking")
|
sound_working = NodePath("SoundWorking")
|
||||||
sound_complete = NodePath("SoundComplete")
|
sound_complete = NodePath("Spawner/SoundComplete")
|
||||||
spawner = NodePath("Spawner")
|
spawner = NodePath("Spawner")
|
||||||
|
|
||||||
[node name="SpriteBack" type="Sprite2D" parent="."]
|
[node name="SpriteBack" type="Sprite2D" parent="."]
|
||||||
|
@ -110,7 +110,7 @@ collecting_amount = 10
|
||||||
shape = SubResource("RectangleShape2D_k11if")
|
shape = SubResource("RectangleShape2D_k11if")
|
||||||
debug_color = Color(0, 0.701961, 0.188235, 0.419608)
|
debug_color = Color(0, 0.701961, 0.188235, 0.419608)
|
||||||
|
|
||||||
[node name="Spawner" parent="." instance=ExtResource("9_2wvgu")]
|
[node name="Spawner" parent="." node_paths=PackedStringArray("sound_complete") instance=ExtResource("9_2wvgu")]
|
||||||
position = Vector2(0, 8)
|
position = Vector2(0, 8)
|
||||||
scene = ExtResource("2_h5aul")
|
scene = ExtResource("2_h5aul")
|
||||||
buffer_cap = 1
|
buffer_cap = 1
|
||||||
|
@ -118,6 +118,7 @@ spawn_rect = Rect2(-8, 0, 16, 4)
|
||||||
spawn_rotation_degrees_min = 80.0
|
spawn_rotation_degrees_min = 80.0
|
||||||
spawn_rotation_degrees_max = 100.0
|
spawn_rotation_degrees_max = 100.0
|
||||||
overlapping_body_count_limit = 4
|
overlapping_body_count_limit = 4
|
||||||
|
sound_complete = NodePath("SoundComplete")
|
||||||
|
|
||||||
[node name="PreventSpawnShape" type="CollisionShape2D" parent="Spawner"]
|
[node name="PreventSpawnShape" type="CollisionShape2D" parent="Spawner"]
|
||||||
z_index = 3
|
z_index = 3
|
||||||
|
@ -125,6 +126,10 @@ position = Vector2(0, 3.5)
|
||||||
shape = SubResource("RectangleShape2D_jeo5f")
|
shape = SubResource("RectangleShape2D_jeo5f")
|
||||||
debug_color = Color(0.701961, 0, 0, 0.419608)
|
debug_color = Color(0.701961, 0, 0, 0.419608)
|
||||||
|
|
||||||
|
[node name="SoundComplete" type="AudioStreamPlayer" parent="Spawner"]
|
||||||
|
stream = ExtResource("11_r8505")
|
||||||
|
max_polyphony = 4
|
||||||
|
|
||||||
[node name="ConversionTimer" type="Timer" parent="."]
|
[node name="ConversionTimer" type="Timer" parent="."]
|
||||||
wait_time = 0.5
|
wait_time = 0.5
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
@ -132,9 +137,6 @@ one_shot = true
|
||||||
[node name="SoundWorking" type="AudioStreamPlayer" parent="."]
|
[node name="SoundWorking" type="AudioStreamPlayer" parent="."]
|
||||||
stream = ExtResource("10_6hhch")
|
stream = ExtResource("10_6hhch")
|
||||||
|
|
||||||
[node name="SoundComplete" type="AudioStreamPlayer" parent="."]
|
|
||||||
stream = ExtResource("11_r8505")
|
|
||||||
|
|
||||||
[node name="ConverterPlacementBody" parent="." instance=ExtResource("12_5qhgs")]
|
[node name="ConverterPlacementBody" parent="." instance=ExtResource("12_5qhgs")]
|
||||||
|
|
||||||
[connection signal="input_event" from="." to="." method="_on_input_event"]
|
[connection signal="input_event" from="." to="." method="_on_input_event"]
|
||||||
|
|
|
@ -27,6 +27,14 @@ var buffer: int = 0
|
||||||
## Maximum amount of bodies overlapping the spawner's area before the spawner stops spawning.
|
## Maximum amount of bodies overlapping the spawner's area before the spawner stops spawning.
|
||||||
@export_range(0, 16, 1, "or_greater") var overlapping_body_count_limit: int
|
@export_range(0, 16, 1, "or_greater") var overlapping_body_count_limit: int
|
||||||
|
|
||||||
|
## Sound to play when spawning an item.
|
||||||
|
##
|
||||||
|
## Doesn't spawn anything if not set.
|
||||||
|
@export var sound_complete: AudioStreamPlayer
|
||||||
|
|
||||||
|
@export_range(0.01, 8.0, 0.01, "or_greater") var sound_complete_pitch_min: float = 0.98
|
||||||
|
@export_range(0.01, 8.0, 0.01, "or_greater") var sound_complete_pitch_max: float = 1.02
|
||||||
|
|
||||||
|
|
||||||
signal spawned(what: Node2D)
|
signal spawned(what: Node2D)
|
||||||
|
|
||||||
|
@ -62,6 +70,9 @@ func _do_spawn():
|
||||||
instantiated.global_position = global_position + _select_spawn_position()
|
instantiated.global_position = global_position + _select_spawn_position()
|
||||||
instantiated.rotation_degrees = _select_spawn_rotation()
|
instantiated.rotation_degrees = _select_spawn_rotation()
|
||||||
target.add_child(instantiated)
|
target.add_child(instantiated)
|
||||||
|
if sound_complete:
|
||||||
|
sound_complete.pitch_scale = Randomizer.rng.randf_range(sound_complete_pitch_min, sound_complete_pitch_max)
|
||||||
|
sound_complete.play()
|
||||||
spawned.emit()
|
spawned.emit()
|
||||||
buffer -= 1
|
buffer -= 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue