diff --git a/converters/converter.gd b/converters/converter.gd index 835b979..141a8f9 100644 --- a/converters/converter.gd +++ b/converters/converter.gd @@ -1,8 +1,6 @@ extends StaticBody2D class_name Converter -var coda : int = 0 - @export var sprite_front: AnimatedSprite2D @export var sprite_back: AnimatedSprite2D @export var conversion_timer: Timer @@ -10,25 +8,38 @@ var coda : int = 0 @export var sound_complete: AudioStreamPlayer @export var spawner: Spawner -func _on_collector_goal(): - coda+=1 +## Amount of scenes this converter should produce. +var to_produce: int = 0 -func _process(_delta): - if coda>=1 and conversion_timer.is_stopped(): +## Amount of scenes this converter should spawn. +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() - if not sprite_back==null: - sprite_back.play() - conversion_timer.start() + if sprite_back: + sprite_back.play() + if sound_working: sound_working.play() 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() + if sprite_front: + sprite_front.stop() + if sprite_back: + sprite_back.stop() + if sound_working: + sound_working.stop() + var is_pending_deletion: bool = false @@ -40,7 +51,7 @@ func ending_deletion(): sprite_front.modulate = Color.WHITE 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 event is InputEventMouseButton or event is InputEventScreenTouch: queue_free() diff --git a/converters/copper_to_silver/copper_converter.tscn b/converters/copper_to_silver/copper_converter.tscn index 2b7da3c..a2a9ea7 100644 --- a/converters/copper_to_silver/copper_converter.tscn +++ b/converters/copper_to_silver/copper_converter.tscn @@ -71,7 +71,7 @@ script = ExtResource("1_mas6k") sprite_front = NodePath("SpriteFront") conversion_timer = NodePath("ConversionTimer") sound_working = NodePath("SoundWorking") -sound_complete = NodePath("SoundComplete") +sound_complete = NodePath("Spawner/SoundComplete") spawner = NodePath("Spawner") [node name="SpriteBack" type="Sprite2D" parent="."] @@ -110,7 +110,7 @@ collecting_amount = 10 shape = SubResource("RectangleShape2D_k11if") 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) scene = ExtResource("2_h5aul") buffer_cap = 1 @@ -118,6 +118,7 @@ spawn_rect = Rect2(-8, 0, 16, 4) spawn_rotation_degrees_min = 80.0 spawn_rotation_degrees_max = 100.0 overlapping_body_count_limit = 4 +sound_complete = NodePath("SoundComplete") [node name="PreventSpawnShape" type="CollisionShape2D" parent="Spawner"] z_index = 3 @@ -125,6 +126,10 @@ position = Vector2(0, 3.5) shape = SubResource("RectangleShape2D_jeo5f") 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="."] wait_time = 0.5 one_shot = true @@ -132,9 +137,6 @@ one_shot = true [node name="SoundWorking" type="AudioStreamPlayer" parent="."] stream = ExtResource("10_6hhch") -[node name="SoundComplete" type="AudioStreamPlayer" parent="."] -stream = ExtResource("11_r8505") - [node name="ConverterPlacementBody" parent="." instance=ExtResource("12_5qhgs")] [connection signal="input_event" from="." to="." method="_on_input_event"] diff --git a/spawner/spawner.gd b/spawner/spawner.gd index c6cd1a0..0eacb7f 100644 --- a/spawner/spawner.gd +++ b/spawner/spawner.gd @@ -27,6 +27,14 @@ var buffer: int = 0 ## 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 +## 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) @@ -62,6 +70,9 @@ func _do_spawn(): instantiated.global_position = global_position + _select_spawn_position() instantiated.rotation_degrees = _select_spawn_rotation() 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() buffer -= 1