2025-03-24 18:13:08 +01:00
|
|
|
class_name Level
|
2025-02-23 00:46:23 +01:00
|
|
|
extends Node3D
|
|
|
|
|
2025-03-24 18:13:08 +01:00
|
|
|
var music: Music
|
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] = []
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2025-03-24 18:13:08 +01:00
|
|
|
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!")
|
2025-02-23 10:59:42 +01:00
|
|
|
|
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-03-24 18:13:08 +01:00
|
|
|
music.adaptInstrumentsToVelocity(velocity, delta)
|