42 lines
1.1 KiB
GDScript3
42 lines
1.1 KiB
GDScript3
|
extends AudioStreamPlayer
|
||
|
|
||
|
var music_list = (["res://Sounds/GiantsLullaby.ogg",
|
||
|
"res://Sounds/IslandBoogie.ogg",
|
||
|
"res://Sounds/OrangeSky.ogg",
|
||
|
"res://Sounds/SlimeParty.ogg",
|
||
|
"res://Sounds/WelcomeToOceanCity.ogg"])
|
||
|
|
||
|
var song = music_list[randi() % music_list.size()]
|
||
|
var time_left
|
||
|
|
||
|
const TRANSITIONTIME = 2.0
|
||
|
|
||
|
@onready var transition_timer = $Transition
|
||
|
@onready var tween_timer = $Tween
|
||
|
|
||
|
# Called when the node enters the scene tree for the first time.
|
||
|
func _ready():
|
||
|
self.stream = load(song)
|
||
|
time_left = self.stream.get_length() - TRANSITIONTIME
|
||
|
tween_timer.start(time_left)
|
||
|
self.play()
|
||
|
|
||
|
func _on_finished():
|
||
|
transition_timer.start(TRANSITIONTIME/2)
|
||
|
|
||
|
func _on_transition_timer_timeout():
|
||
|
var last_played = song
|
||
|
var new_song = music_list[randi()% music_list.size()]
|
||
|
|
||
|
while new_song == last_played:
|
||
|
new_song = music_list[randi()% music_list.size()]
|
||
|
|
||
|
self.stream = load(new_song)
|
||
|
time_left = self.stream.get_length()- TRANSITIONTIME
|
||
|
tween_timer.start(time_left)
|
||
|
self.play()
|
||
|
|
||
|
func _on_tween_timer_timeout():
|
||
|
var tween = create_tween()
|
||
|
tween.tween_property(self, "volume_db", -20, TRANSITIONTIME)
|