extends Control @onready var next_sound_button = $CenterContainer/VBoxContainer/NextSoundButton @onready var repeat_sound_button = $CenterContainer/VBoxContainer/HBoxContainer/RepeatSoundButton @onready var end_of_game_button = $CenterContainer/VBoxContainer/HBoxContainer/EndOfGameButton @onready var winner_selector = $WinnerSelector @onready var menu_players = $WinnerSelector/VBoxContainer/MenuPlayers @onready var exit_menu_confirm_exit_button = $ExitButtonWindow/VBoxContainer/HBoxContainer/ConfirmExitButton @onready var exit_menu_cancel_exit_button = $ExitButtonWindow/VBoxContainer/HBoxContainer/CancelExitButton var animales = [ { "nombre": "Elfante", "sonido": preload("res://audio/Elefant.mp3") }, { "nombre": "Caballo", "sonido": preload("res://audio/caballo.mp3") }, { "nombre": "Asno", "sonido": preload("res://audio/asno.mp3") }, { "nombre": "Cuervo", "sonido": preload("res://audio/cuervo.mp3") }, { "nombre": "Gallo", "sonido": preload("res://audio/gallo.mp3") }, { "nombre": "Gato", "sonido": preload("res://audio/gato.mp3") }, { "nombre": "Gaviota", "sonido": preload("res://audio/gaviota.mp3") }, { "nombre": "Oveja", "sonido": preload("res://audio/oveja.mp3") }, { "nombre": "Perro", "sonido": preload("res://audio/perro.mp3") }, { "nombre": "Vaca", "sonido": preload("res://audio/vaca.mp3") }, { "nombre": "Lobo", "sonido": preload("res://audio/wolf.mp3") } ] var animales_restantes = [] var sound_just_played @export var jugadores_seleccionados = [] var ganador = -1 func _ready(): $MenuButton.get_popup().add_item("Salir", 0) $MenuButton.get_popup().connect("id_pressed", self._on_menu_item_selected) exit_menu_confirm_exit_button.pressed.connect(_on_exit_menu_button_pressed.bind(true)) exit_menu_cancel_exit_button.pressed.connect(_on_exit_menu_button_pressed.bind(false)) animales_restantes = animales.duplicate() randomize() func _on_menu_item_selected(id): match id: 0: $ExitButtonWindow.show() $Bloqueador.visible = true func _on_exit_menu_button_pressed(exit : bool): if exit: GameData.clear_partidas_activas() ScreenManager.go_back_to_previous_scene() else: $ExitButtonWindow.hide() $Bloqueador.visible = false func _on_next_sound_button_pressed(): if animales_restantes.is_empty(): for i in jugadores_seleccionados.size(): menu_players.get_popup().add_item(jugadores_seleccionados[i].nombre, i) menu_players.get_popup().connect("id_pressed", Callable(self, "_on_jugador_seleccionado")) winner_selector.show() $Bloqueador.visible = true return var index = randi() % animales_restantes.size() var animal = animales_restantes[index] sound_just_played = animal # Reproduce el sonido $AnimalAudio.stream = animal["sonido"] $AnimalAudio.play() animales_restantes.erase(animal) func _on_repeat_sound_button_pressed(): $AnimalAudio.stream = sound_just_played["sonido"] $AnimalAudio.play() func _on_end_of_game_button_pressed(): for i in jugadores_seleccionados.size(): menu_players.get_popup().add_item(jugadores_seleccionados[i].nombre, i) menu_players.get_popup().connect("id_pressed", Callable(self, "_on_jugador_seleccionado")) winner_selector.show() $Bloqueador.visible = true func _on_jugador_seleccionado(index: int): ganador = jugadores_seleccionados[index].id func _on_winner_button_pressed(): if ganador != -1: GameData.end_game(ganador) ScreenManager.go_back_to_previous_scene()