57 lines
1.6 KiB
GDScript
57 lines
1.6 KiB
GDScript
extends Control
|
|
|
|
@onready var next_sound_button = $VBoxContainer/NextSoundButton
|
|
@onready var repeat_sound_button = $VBoxContainer/HBoxContainer/RepeatSoundButton
|
|
@onready var end_of_game_button = $VBoxContainer/HBoxContainer/EndOfGameButton
|
|
|
|
@onready var winner_selector = $WinnerSelector
|
|
@onready var menu_players = $WinnerSelector/VBoxContainer/MenuPlayers
|
|
|
|
var animales = [
|
|
{ "nombre": "Elfante", "sonido": preload("res://audio/Elefant.mp3") },
|
|
|
|
]
|
|
var animales_restantes = []
|
|
var sound_just_played
|
|
|
|
@export var jugadores_seleccionados = []
|
|
var ganador = -1
|
|
|
|
func _ready():
|
|
animales_restantes = animales.duplicate()
|
|
randomize()
|
|
|
|
func _on_next_sound_button_pressed():
|
|
if animales_restantes.is_empty():
|
|
print("¡Todos los sonidos han sido usados!")
|
|
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(index)
|
|
|
|
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()
|