El sistema de controles por teclado utiliza acciones mapeadas en Godot para permitir la interacción con el juego. Estas acciones se configuran en Project → Project Settings → Input Map.
codeImplementación
func _comprobar_teclado(event: InputEvent):
# Reiniciar el juego si hemos perdido
if muerto and event.is_action_pressed("ui_accept"):
_reiniciar_juego()
return
# Controles con teclado
if event.is_action_pressed("ui_left"):
tocando_izquierda = true
if event.is_action_released("ui_left"):
tocando_izquierda = false
if event.is_action_pressed("ui_right"):
tocando_derecha = true
if event.is_action_released("ui_right"):
tocando_derecha = false
# Reiniciar el juego si hemos perdido
if muerto and event.is_action_pressed("ui_accept"):
_reiniciar_juego()
return
# Controles con teclado
if event.is_action_pressed("ui_left"):
tocando_izquierda = true
if event.is_action_released("ui_left"):
tocando_izquierda = false
if event.is_action_pressed("ui_right"):
tocando_derecha = true
if event.is_action_released("ui_right"):
tocando_derecha = false
keyboardAcciones mapeadas
arrow_back
ui_left
Mover nave a la izquierda
arrow_forward
ui_right
Mover nave a la derecha
replay
ui_accept
Reiniciar juego (Enter/Espacio)
settings
Las acciones abstractas permiten cambiar las teclas sin modificar el código
touch_app
Se detectan tanto la presión (is_action_pressed) como la liberación (is_action_released)
loopReinicio del juego
refresh
Al perder, se muestra "GAME OVER" y se espera la acción ui_accept
autorenew
La función _reiniciar_juego() recarga la escena actual
code
Implementación mediante get_tree().reload_current_scene()
warning
Uso de call_deferred() para cerrar el juego de forma segura