From be3d7a9afc1e33b20ed624c86c760feb680c3d3d Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 3 Apr 2022 00:14:57 +0200 Subject: [PATCH] :sparkles: Add dynamic music --- src/levels/Game.tscn | 23 ++++++++++++++--------- src/levels/PhaseOneMusic.gd | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/levels/PhaseOneMusic.gd diff --git a/src/levels/Game.tscn b/src/levels/Game.tscn index 01f245d..2a29094 100644 --- a/src/levels/Game.tscn +++ b/src/levels/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=2] +[gd_scene load_steps=12 format=2] [ext_resource path="res://src/mechanics/Background.tscn" type="PackedScene" id=1] [ext_resource path="res://src/mechanics/Darkness.tscn" type="PackedScene" id=2] @@ -10,6 +10,7 @@ [ext_resource path="res://src/music/BaseChoir.mp3" type="AudioStream" id=8] [ext_resource path="res://src/music/BaseDrum.mp3" type="AudioStream" id=9] [ext_resource path="res://src/music/BaseBell.mp3" type="AudioStream" id=10] +[ext_resource path="res://src/levels/PhaseOneMusic.gd" type="Script" id=11] [node name="Game" type="Node2D"] script = ExtResource( 6 ) @@ -18,17 +19,22 @@ script = ExtResource( 6 ) layer = 0 [node name="PhaseOneMusic" type="Node" parent="PhaseOne"] +script = ExtResource( 11 ) +fire_path = NodePath("../PhaseOneContainer/Fire") -[node name="BaseBell" type="AudioStreamPlayer" parent="PhaseOne/PhaseOneMusic"] +[node name="Bell" type="AudioStreamPlayer" parent="PhaseOne/PhaseOneMusic"] stream = ExtResource( 10 ) +volume_db = -60.0 autoplay = true -[node name="BaseChoir" type="AudioStreamPlayer" parent="PhaseOne/PhaseOneMusic"] +[node name="Choir" type="AudioStreamPlayer" parent="PhaseOne/PhaseOneMusic"] stream = ExtResource( 8 ) +volume_db = -60.0 autoplay = true -[node name="BaseDrum" type="AudioStreamPlayer" parent="PhaseOne/PhaseOneMusic"] +[node name="Drum" type="AudioStreamPlayer" parent="PhaseOne/PhaseOneMusic"] stream = ExtResource( 9 ) +volume_db = -60.0 autoplay = true [node name="PhaseOneContainer" type="Node2D" parent="PhaseOne"] @@ -39,17 +45,16 @@ tile_data = PoolIntArray( 0, 2, 0, 1, 2, 0, 2, 2, 0, 3, 2, 0, 4, 2, 0, 5, 2, 0, [node name="Darkness" parent="PhaseOne/PhaseOneContainer" instance=ExtResource( 2 )] position = Vector2( 553, 296 ) -[node name="Fire" parent="PhaseOne/PhaseOneContainer" instance=ExtResource( 3 )] -position = Vector2( 597, 323 ) -script = null - [node name="Player" parent="PhaseOne/PhaseOneContainer" instance=ExtResource( 4 )] position = Vector2( 500, 438 ) [node name="Enemy" parent="PhaseOne/PhaseOneContainer" instance=ExtResource( 5 )] -visible = false position = Vector2( 755, 508 ) +[node name="Fire" parent="PhaseOne/PhaseOneContainer" instance=ExtResource( 3 )] +position = Vector2( 493, 305 ) +intensity = 0.3 + [node name="UserInterface" type="CanvasLayer" parent="."] [node name="UserIntefaceContainer" type="Panel" parent="UserInterface"] diff --git a/src/levels/PhaseOneMusic.gd b/src/levels/PhaseOneMusic.gd new file mode 100644 index 0000000..31c9c28 --- /dev/null +++ b/src/levels/PhaseOneMusic.gd @@ -0,0 +1,22 @@ +extends Node + +export var fire_path: NodePath + +export var choir_min: float = 0.05 +export var choir_max: float = 0.20 +export var bell_min: float = 0.20 +export var bell_max: float = 0.60 +export var drum_min: float = 0.40 +export var drum_max: float = 0.80 + + +func _ready(): + var fire = get_node(fire_path) + fire.connect("intensity_changed", self, "_on_fire_intensity_changed") + + +func _on_fire_intensity_changed(value): + $Choir.volume_db = (smoothstep(choir_min, choir_max, value) - 1) * 60 + $Bell.volume_db = (smoothstep(bell_min, bell_max, value) - 1) * 60 + $Drum.volume_db = (smoothstep(drum_min, drum_max, value) - 1) * 60 + pass