[gd_scene load_steps=10 format=3 uid="uid://df5m716pd6mej"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_vumbr"] bounce = 0.2 [sub_resource type="GDScript" id="GDScript_rvq6k"] script/source = "extends RigidBody3D var stream_players: Array[AudioStreamPlayer] = [] func makeAudioStreamPlayers(music_name: String): var path: String = \"res://music/\" + music_name var dir: DirAccess = DirAccess.open(path) var file_paths: Array[String] = [] assert(dir, path + \" is not a valid path!\") if dir: dir.list_dir_begin() var file_name = dir.get_next() while file_name != \"\": if !dir.current_is_dir(): if file_name.ends_with(\".ogg\"): file_paths.push_back(path + \"/\" + file_name) file_name = dir.get_next() assert(len(file_paths), path + \" had no .ogg files!\") var players: Array[AudioStreamPlayer] = [] for file_path in file_paths: var stream: AudioStreamOggVorbis = AudioStreamOggVorbis.load_from_file(file_path) stream.loop = true stream.bpm = 124 var player: AudioStreamPlayer = AudioStreamPlayer.new() player.name = file_path.substr(10) player.stream = stream player.volume_db = -50 players.push_back(player) add_child(player) stream_players = players # Called when the node enters the scene tree for the first time. func _ready() -> void: var level = get_parent().get_parent() if is_instance_valid(level) and level is Node3D: makeAudioStreamPlayers(level.name.to_lower()) for player in stream_players: player.play() func handleMusicWithVelocity(velocity: float, delta: float) -> void: var instruments_needed = floor(velocity / 7) 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 -= delta * 32 elif playing.volume_db <= 0: playing.volume_db += delta * 8 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 += delta * 16 # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: for player in stream_players: if player.volume_db > 0: player.volume_db = 0 var velocity: float = abs(self.linear_velocity.x) + abs(self.linear_velocity.y) handleMusicWithVelocity(velocity, delta) " [sub_resource type="SphereShape3D" id="SphereShape3D_xfgrm"] [sub_resource type="Gradient" id="Gradient_bgp4x"] colors = PackedColorArray(0.942957, 7.89344e-06, 0.597148, 1, 0, 0.9912, 0.9912, 1) [sub_resource type="GradientTexture2D" id="GradientTexture2D_5d6uk"] gradient = SubResource("Gradient_bgp4x") fill_from = Vector2(0.504951, 0.00495049) fill_to = Vector2(0.549505, 1) [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_qcgmu"] albedo_texture = SubResource("GradientTexture2D_5d6uk") [sub_resource type="SphereMesh" id="SphereMesh_bor8g"] material = SubResource("StandardMaterial3D_qcgmu") [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_4tofj"] direction = Vector3(0, 0, 0) gravity = Vector3(0, 0, 0) [sub_resource type="SphereMesh" id="SphereMesh_1m3ut"] radius = 0.2 height = 0.4 radial_segments = 8 rings = 4 [node name="Sphere" type="RigidBody3D"] collision_priority = 100.0 axis_lock_linear_z = true physics_material_override = SubResource("PhysicsMaterial_vumbr") contact_monitor = true script = SubResource("GDScript_rvq6k") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] shape = SubResource("SphereShape3D_xfgrm") [node name="MeshInstance3D" type="MeshInstance3D" parent="."] mesh = SubResource("SphereMesh_bor8g") [node name="GPUParticles3D" type="GPUParticles3D" parent="."] amount = 16 process_material = SubResource("ParticleProcessMaterial_4tofj") draw_pass_1 = SubResource("SphereMesh_1m3ut")