Balizas de marea para Android
Copia cada bloque en un archivo de texto sin formato con el nombre que figura después de ARCHIVO. Conserva las tabulaciones y la última línea de cada bloque. No copies las líneas ARCHIVO ni FIN DEL ARCHIVO. Guarda todos los archivos juntos en una carpeta e importa project.godot desde Godot.
ARCHIVO: project.godot
config_version=5
[application]
config/name="Balizas de marea"
config/icon="res://icono.svg"
run/main_scene="res://taller.tscn"
config/features=PackedStringArray("4.6", "GL Compatibility")
[display]
window/handheld/orientation=0
window/size/viewport_width=640
window/size/viewport_height=360
window/stretch/mode="canvas_items"
[rendering]
textures/vram_compression/import_etc2_astc=true
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"
[input]
mover_izq={"deadzone": 0.2, "events": [Object(InputEventKey,"physical_keycode":4194319)]}
mover_der={"deadzone": 0.2, "events": [Object(InputEventKey,"physical_keycode":4194321)]}
mover_arriba={"deadzone": 0.2, "events": [Object(InputEventKey,"physical_keycode":4194320)]}
mover_abajo={"deadzone": 0.2, "events": [Object(InputEventKey,"physical_keycode":4194322)]}
reiniciar={"deadzone": 0.2, "events": [Object(InputEventKey,"physical_keycode":82)]}
FIN DEL ARCHIVO
ARCHIVO: taller.gd
extends Node2D
const INICIO := Vector2(104, 184)
const SALIDA := Vector2(551, 184)
const BALIZAS := [Vector2(228, 100), Vector2(337, 234), Vector2(448, 120)]
const CAMPO := Rect2(34, 64, 572, 224)
const VELOCIDAD := 185.0
var jugador := INICIO
var recogidas: Array[Vector2] = []
var completado := false
var destino := INICIO
var toque_activo := false
var prueba: RefCounted
var ultimo_evento_qa := ""
func _ready() -> void:
reiniciar()
if "--pruebas" in OS.get_cmdline_user_args():
prueba = load("res://prueba.gd").new()
prueba.ejecutar(self)
func reiniciar() -> void:
jugador = INICIO
destino = INICIO
toque_activo = false
recogidas.clear()
completado = false
actualizar_marcador()
func _input(event: InputEvent) -> void:
if event is InputEventScreenTouch and event.pressed:
if completado:
reiniciar()
elif CAMPO.has_point(event.position):
destino = event.position
toque_activo = true
func _physics_process(delta: float) -> void:
if Input.is_action_just_pressed("reiniciar"):
reiniciar()
if completado:
return
var eje := Input.get_vector("mover_izq", "mover_der", "mover_arriba", "mover_abajo")
if eje != Vector2.ZERO:
toque_activo = false
jugador += eje * VELOCIDAD * delta
elif toque_activo:
jugador = jugador.move_toward(destino, VELOCIDAD * delta)
jugador = jugador.clamp(CAMPO.position + Vector2(12, 12), CAMPO.end - Vector2(12, 12))
for baliza: Vector2 in BALIZAS:
if jugador.distance_to(baliza) < 21.0 and not recogidas.has(baliza):
recogidas.append(baliza)
if recogidas.size() == BALIZAS.size() and jugador.distance_to(SALIDA) < 24.0:
completado = true
actualizar_marcador()
func actualizar_marcador() -> void:
if OS.has_feature("android"):
var evento_qa := "FIELD121_UMBRA balizas=%d fin=%s" % [recogidas.size(), completado]
if evento_qa != ultimo_evento_qa:
ultimo_evento_qa = evento_qa
print(evento_qa)
$Marcador.text = "Balizas de marea · %d / %d" % [recogidas.size(), BALIZAS.size()]
if completado:
$Ayuda.text = "Salida alcanzada. Pulsa R o toca para repetir."
elif recogidas.size() == BALIZAS.size():
$Ayuda.text = "Salida abierta. Acércate al guardián."
else:
$Ayuda.text = "Flechas o toca el tablero. Recoge tres balizas y vuelve al guardián."
queue_redraw()
func _draw() -> void:
draw_rect(Rect2(0, 0, 640, 360), Color("14243c"))
draw_rect(CAMPO, Color("1c3954"))
for baliza: Vector2 in BALIZAS:
if not recogidas.has(baliza):
draw_colored_polygon(PackedVector2Array([baliza + Vector2(0,-10), baliza + Vector2(10,0), baliza + Vector2(0,10), baliza + Vector2(-10,0)]), Color("ffd27c"))
var abierto := recogidas.size() == BALIZAS.size()
var luz := Color("73e9cf") if abierto else Color("c3a3c8")
draw_circle(SALIDA, 19, Color("14243c"))
draw_arc(SALIDA, 19, 0, TAU, 40, luz, 3.0, true)
if abierto:
draw_line(SALIDA + Vector2(-8, 1), SALIDA + Vector2(8, 1), luz, 3.0, true)
draw_line(SALIDA + Vector2(4, -3), SALIDA + Vector2(8, 1), luz, 3.0, true)
else:
draw_line(SALIDA + Vector2(-5, 5), SALIDA + Vector2(5, -5), luz, 3.0, true)
draw_circle(jugador, 11, Color("c4ebff"))
draw_circle(jugador, 4, Color("1c3954"))
FIN DEL ARCHIVO
ARCHIVO: taller.tscn
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://taller.gd" id="1"]
[node name="Taller" type="Node2D"]
script = ExtResource("1")
[node name="Marcador" type="Label" parent="."]
offset_left = 34.0
offset_top = 22.0
theme_override_font_sizes/font_size = 22
[node name="Ayuda" type="Label" parent="."]
offset_left = 34.0
offset_top = 302.0
theme_override_font_sizes/font_size = 16
FIN DEL ARCHIVO
ARCHIVO: prueba.gd
extends RefCounted
var errores := 0
func comprobar(condicion: bool, caso: String) -> void:
if not condicion:
errores += 1
print("%s %s" % ["PASS" if condicion else "FAIL", caso])
func captura(juego: Node2D, argumento: String) -> void:
if DisplayServer.get_name() == "headless":
return
await RenderingServer.frame_post_draw
var carpeta := ""
for arg in OS.get_cmdline_user_args():
if arg.begins_with("--capturas="):
carpeta = arg.trim_prefix("--capturas=")
if not carpeta.is_empty():
comprobar(juego.get_viewport().get_texture().get_image().save_png(carpeta.path_join(argumento + ".png")) == OK, argumento)
func ejecutar(juego: Node2D) -> void:
await juego.get_tree().process_frame
print(Engine.get_version_info().string, " | ", OS.get_name(), " | ", DisplayServer.get_name())
comprobar(juego.recogidas.is_empty() and juego.jugador == juego.INICIO, "inicio 0/3")
await captura(juego, "01-inicio")
var evento := InputEventKey.new()
evento.physical_keycode = KEY_RIGHT
evento.pressed = true
Input.parse_input_event(evento)
for i in range(4):
await juego.get_tree().physics_frame
comprobar(juego.jugador.x > juego.INICIO.x, "tecla física derecha: movimiento")
evento = InputEventKey.new()
evento.physical_keycode = KEY_RIGHT
evento.pressed = false
Input.parse_input_event(evento)
Input.flush_buffered_events()
Input.action_release("mover_der")
await juego.get_tree().physics_frame
await juego.get_tree().physics_frame
juego.reiniciar()
var toque := InputEventScreenTouch.new()
toque.pressed = true
toque.position = Vector2(166, 185)
var posicion_antes := Vector2(juego.jugador)
juego._input(toque)
juego._physics_process(0.02)
comprobar(juego.toque_activo and juego.destino == toque.position and juego.jugador.distance_to(toque.position) < posicion_antes.distance_to(toque.position), "callback ScreenTouch inyectado directamente en Windows")
juego.toque_activo = false
juego.jugador = juego.SALIDA
juego._physics_process(0.0)
comprobar(not juego.completado, "salida bloqueada 0/3")
for baliza in juego.BALIZAS:
juego.jugador = baliza
juego._physics_process(0.0)
juego._physics_process(0.0)
comprobar(juego.recogidas.size() == 3 and not juego.completado, "cada baliza cuenta una vez y la salida exige acercarse")
await captura(juego, "02-salida-abierta")
juego.jugador = juego.SALIDA
juego._physics_process(0.0)
comprobar(juego.completado, "salida alcanzada")
await captura(juego, "03-fin")
var reset := InputEventKey.new()
reset.physical_keycode = KEY_R
reset.pressed = true
Input.parse_input_event(reset)
await juego.get_tree().process_frame
await juego.get_tree().physics_frame
await juego.get_tree().physics_frame
comprobar(juego.recogidas.is_empty() and not juego.completado and juego.jugador == juego.INICIO, "R: estado inicial restaurado")
juego.get_tree().quit(errores)
FIN DEL ARCHIVO
ARCHIVO: icono.svg
FIN DEL ARCHIVO
ARCHIVO: export_presets.cfg
[preset.0]
name="Android"
platform="Android"
runnable=true
dedicated_server=false
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path=""
[preset.0.options]
gradle_build/use_gradle_build=false
architectures/armeabi-v7a=false
architectures/arm64-v8a=true
architectures/x86=false
architectures/x86_64=true
package/unique_name="org.umbralab.balizas"
package/name="Balizas de marea"
package/signed=true
FIN DEL ARCHIVO
ARCHIVO: LEEME.md
# Balizas de marea · variante de exportación Android
Godot 4.6.3 estándar, Compatibility, JDK 17 y plantillas de exportación de la misma versión. Configura las rutas del JDK y del Android SDK en los ajustes del editor. Instala Platform Tools, Build Tools 35.0.1 y plataforma android-35. La documentación de Godot incluye CMake y NDK para los flujos de preparación y compilación que los necesiten. Esta variante emplea la plantilla APK precompilada y el preset Android sin compilación Gradle personalizada.
Importa `project.godot`, deja que se complete la importación, elige Proyecto > Exportar y selecciona el preset Android. Exporta en modo de depuración con un almacén de claves de depuración local. El paquete de ejercicio usa el ID `org.umbralab.balizas`. Activa solo las arquitecturas necesarias. Aquí se preparan `arm64-v8a` y `x86_64`. No se comparte ningún almacén de claves.
Comando equivalente: `godot --headless --path . --export-debug Android balizas-android-debug.apk`. Si hay APK, verifica su firma y ABI con las herramientas Android. Usa `adb devices`, selecciona explícitamente el dispositivo y ejecuta `adb -s install -r balizas-android-debug.apk`. Abre el juego y toca tres balizas; antes de recogerlas, comprueba que el guardián no termina la partida. Con 3/3 toca el guardián. Toca otra vez para volver a 0/3. La actividad emite eventos `FIELD121_UMBRA` en `logcat`. La firma de depuración y la ejecución de prueba son para este ejercicio.
Los dibujos, las reglas y el código de juego son originales. La ejecución y redistribución de componentes de Godot se rige por sus avisos de licencia, disponibles en https://godotengine.org/license/.
FIN DEL ARCHIVO