@@ -6,14 +6,6 @@ var lastScene = null
66
77# this gets emited when the scene fades, used to load in level details and data to hide it from the player
88signal scene_faded
9- # signal that emits when volume fades
10- signal volume_set
11-
12- # note: volumes can be set with set_volume(), these variables are just for volume control reference
13- var startVolumeLevel = 0 # used as reference for when a volume change started
14- var setVolumeLevel = 0 # where to fade the volume to
15- var volumeLerp = 0 # current stage between start and set for volume level
16- var volumeFadeSpeed = 1 # speed for volume changing
179
1810# was paused enables menu control when the player pauses manually so they don't get stuck (get_tree().paused may want to be used by other intances)
1911var wasPaused = false
@@ -23,38 +15,9 @@ var sceneCanPause = false
2315func _ready ():
2416 # global object references
2517 Global .main = self
26- Global .musicParent = get_node_or_null ("Music" )
27- Global .music = get_node_or_null ("Music/Music" )
28- Global .bossMusic = get_node_or_null ("Music/BossTheme" )
29- Global .effectTheme = get_node_or_null ("Music/EffectTheme" )
30- Global .drowning = get_node_or_null ("Music/Drowning" )
31- Global .life = get_node_or_null ("Music/Life" )
3218 # initialize game data using global reset (it's better then assigning variables twice)
3319 Global .reset_values ()
3420
35- func _process (delta ):
36- # verify scene isn't paused
37- if ! get_tree ().paused and Global .music != null :
38- # pause main music if effect theme, boss music or drowning songs are playing
39- Global .music .stream_paused = Global .effectTheme .playing or Global .drowning .playing or Global .bossMusic .playing
40- # pause boss music if drowning
41- Global .bossMusic .stream_paused = Global .drowning .playing
42- # pause effect music if drowning
43- Global .effectTheme .stream_paused = Global .drowning .playing or Global .bossMusic .playing
44-
45- # check that volume lerp isn't transitioned yet
46- if volumeLerp < 1 :
47- # move volume lerp to 1
48- volumeLerp = move_toward (volumeLerp ,1 ,delta * volumeFadeSpeed )
49- # use volume lerp to set the effect volume
50- Global .music .volume_db = lerp (float (startVolumeLevel ),float (setVolumeLevel ),float (volumeLerp ))
51- # copy the volume to other songs (you'll want to add yours here if you add more)
52- Global .effectTheme .volume_db = Global .music .volume_db
53- Global .drowning .volume_db = Global .music .volume_db
54- Global .bossMusic .volume_db = Global .music .volume_db
55- if volumeLerp >= 1 :
56- volume_set .emit ()
57-
5821func _input (event ):
5922 # Pausing
6023 if event .is_action_pressed ("gm_pause" ) and sceneCanPause :
@@ -174,30 +137,3 @@ func change_scene_to_file(scene = null, fadeOut = "", fadeIn = "", length = 1, s
174137 # if fadeOut wasn't set either then just reset the fader
175138 elif fadeOut != "" :
176139 $ GUI/Fader .play ("RESET" )
177-
178- # stop life sound (if it's still playing)
179- if Global .life .is_playing ():
180- Global .life .stop ()
181- # set volume level to default
182- Global .music .volume_db = 0
183- # copy the volume to other songs (you'll want to add yours here if you add more)
184- Global .bossMusic .volume_db = Global .bossMusic .volume_db
185- Global .effectTheme .volume_db = Global .music .volume_db
186- Global .drowning .volume_db = Global .music .volume_db
187-
188- # executed when life sound has finished
189- func _on_Life_finished ():
190- # set volume level to default
191- set_volume ()
192-
193- # set the volume level
194- func set_volume (volume = 0 , fadeSpeed = 1 ):
195- # set the start volume level to the curren volume
196- startVolumeLevel = Global .music .volume_db
197- # set the volume level to go to
198- setVolumeLevel = volume
199- # set volume transition
200- volumeLerp = 0
201- # set the speed for the transition
202- volumeFadeSpeed = fadeSpeed
203- # this is continued in _process() as it needs to run during gameplay
0 commit comments