2025-02-23 00:46:23 +01:00
|
|
|
extends Node3D
|
|
|
|
|
2025-02-23 14:27:35 +01:00
|
|
|
var velocity: float = 0.0
|
|
|
|
|
2025-02-23 00:46:23 +01:00
|
|
|
var rings_count = 72727
|
|
|
|
var finished_rings_count = 0
|
|
|
|
var rings: Array[Node] = []
|
|
|
|
|
2025-02-23 10:59:42 +01:00
|
|
|
var stream_players: Array[AudioStreamPlayer] = []
|
|
|
|
|
2025-02-23 00:46:23 +01:00
|
|
|
func _ready() -> void:
|
2025-02-23 10:59:42 +01:00
|
|
|
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)
|
|
|
|
|
2025-02-23 00:46:23 +01:00
|
|
|
var rings_node = get_node("Rings")
|
|
|
|
assert(is_instance_valid(rings_node), self.name + " has no rings!")
|
|
|
|
rings = rings_node.get_children()
|
|
|
|
rings_count = len(rings)
|
|
|
|
for ring in rings:
|
|
|
|
ring.connect("collect_signal", do_we_end_yet)
|
|
|
|
|
|
|
|
func do_we_end_yet():
|
|
|
|
finished_rings_count += 1
|
|
|
|
if finished_rings_count >= rings_count:
|
|
|
|
var game = get_parent().get_parent()
|
|
|
|
if is_instance_valid(game) and game.has_method("stop_level"):
|
|
|
|
game.stop_level()
|
2025-02-23 10:59:42 +01:00
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
var sphere = $Player/Sphere
|
2025-02-23 14:27:35 +01:00
|
|
|
velocity = abs(sphere.linear_velocity.x) + abs(sphere.linear_velocity.y)
|
2025-02-23 10:59:42 +01:00
|
|
|
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)
|