properly fade out the music when finishing a level
This commit is contained in:
parent
a3e0c4d82d
commit
c0aed38065
12 changed files with 80 additions and 87 deletions
|
@ -1,20 +1,19 @@
|
|||
class_name Level
|
||||
extends Node3D
|
||||
|
||||
var music: Music
|
||||
var velocity: float = 0.0
|
||||
|
||||
var rings_count = 72727
|
||||
var finished_rings_count = 0
|
||||
var rings: Array[Node] = []
|
||||
|
||||
var stream_players: Array[AudioStreamPlayer] = []
|
||||
|
||||
func _ready() -> void:
|
||||
var music_node = get_node("Music")
|
||||
assert(is_instance_valid(music_node), self.name + " has no music!")
|
||||
var music = music_node.get_children()
|
||||
for music_player in music:
|
||||
if music_player is AudioStreamPlayer:
|
||||
stream_players.push_back(music_player)
|
||||
var children = get_children()
|
||||
for child in children:
|
||||
if is_instance_of(child, Music):
|
||||
music = child
|
||||
assert(is_instance_valid(music), self.name + " has no music!")
|
||||
|
||||
var rings_node = get_node("Rings")
|
||||
assert(is_instance_valid(rings_node), self.name + " has no rings!")
|
||||
|
@ -33,19 +32,4 @@ func do_we_end_yet():
|
|||
func _process(delta: float) -> void:
|
||||
var sphere = $Player/Sphere
|
||||
velocity = abs(sphere.linear_velocity.x) + abs(sphere.linear_velocity.y)
|
||||
var instruments_needed = floor(velocity / 8)
|
||||
var instruments_playing = stream_players.filter(func(p: AudioStreamPlayer): return p.volume_db > -50)
|
||||
|
||||
for index_p in len(instruments_playing):
|
||||
var playing = instruments_playing[index_p]
|
||||
if index_p + 1 > instruments_needed:
|
||||
playing.volume_db = max(playing.volume_db - (delta * 32), -50)
|
||||
elif playing.volume_db <= 0:
|
||||
playing.volume_db = min(playing.volume_db + (delta * 8), 0)
|
||||
|
||||
if instruments_needed > len(instruments_playing):
|
||||
var instruments_not_playing = stream_players.filter(func(p: AudioStreamPlayer): return p.volume_db <= -50)
|
||||
if len(instruments_not_playing):
|
||||
var to_play = instruments_not_playing.pick_random()
|
||||
if is_instance_valid(to_play):
|
||||
to_play.volume_db = min(to_play.volume_db + (delta * 16), 0)
|
||||
music.adaptInstrumentsToVelocity(velocity, delta)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue