diff --git a/guante_blanco.lua b/guante_blanco.lua index 2c46cc3..7f913be 100644 --- a/guante_blanco.lua +++ b/guante_blanco.lua @@ -21,6 +21,9 @@ FILA_MSG = 23 -- mensajes "Choque", "MORDIDO" AREA_Y0 = 1 -- primera fila donde se pinta la habitación AREA_Y1 = 22 -- última fila +-- Ritmo del movimiento del jugador (frames entre pasos) +TICS_JUGADOR = 4 + -- ============================================================ -- PALETA (mapeo CPC firmware → CGA disponible) -- Original: INK 0,0 (negro) / 1,26 (pastel) / 2,15 (blanco) / @@ -195,6 +198,9 @@ rm = 1 -- habitación actual (variable rm del original) xp, yp = 6, 4 -- posición del ladrón hombre_glifo = GL_LADRON mapa = {} -- mapa[hab][x][y] = tipo de celda +ultimo_tic = 0 -- contador de frames para temporizar el movimiento +escapado = false -- se activa al alcanzar dir=0 (Fase 5 muestra el final) +muerto = false -- se activa al ser mordido por el perro (Fase 4) -- ============================================================ -- CONSTRUCCIÓN DEL MAPA LÓGICO @@ -354,8 +360,96 @@ function pintar_habitacion() end -- ============================================================ --- BUCLE PRINCIPAL — FASE 1 --- Solo render estático. Teclas 1..5 cambian habitación visible. +-- MOVIMIENTO Y CAMBIO DE HABITACIÓN +-- Reproducción de la lógica de las líneas 1520-1900 del original. +-- ============================================================ + +-- Aplica la nueva posición del ladrón tras cambiar a otra habitación, +-- según la dirección por la que ha entrado (línea 1810-1840 original). +function aplicar_dir(dir) + local hab = HABITACIONES[rm] + if dir == 1 then xp = 6; yp = hab.maxy + elseif dir == 2 then xp = 6; yp = hab.miny + elseif dir == 3 then xp = hab.minx; yp = 13 + elseif dir == 4 then xp = hab.maxx; yp = 13 + end +end + +-- Resuelve el cambio de habitación dada una dirección (1=N, 2=S, 3=E, 4=O). +-- dir(rm, dir) = -1 → bloqueado; = 0 → escapar; = n → ir a habitación n. +function cambiar_a_dir(dir) + local destino = HABITACIONES[rm].dir[dir] + if destino == -1 then return end + if destino == 0 then + escapado = true + return + end + rm = destino + aplicar_dir(dir) +end + +-- Dirección estándar según el vector de movimiento (xf, yf). +-- Original: línea 1770-1780 — prioridad al eje vertical si yf != 0. +function dir_de_movimiento(xf, yf) + local dir + if xf < 0 then dir = 4 + elseif xf > 0 then dir = 3 end + if yf < 0 then dir = 1 + elseif yf > 0 then dir = 2 end + return dir +end + +-- Parche del Pasillo para ventanas H (líneas 1860-1900 del original): +-- según xp (no xf/yf), decide la dirección de salida. +function dir_vent_h() + if xp > 5 and xp < 8 then + if yp > 13 then return 2 else return 1 end + else + if xp < 6 then return 4 else return 3 end + end +end + +-- Intenta mover el ladrón en (xf, yf). Replica la cadena gol del +-- original (línea 1670 y siguientes). +function mover_jugador(xf, yf) + if xf == 0 and yf == 0 then return end + local nx, ny = xp + xf, yp + yf + local t = mapa[rm][nx][ny] + + -- Conmutador (gol=1..4): no se mueve, no hace nada en Fase 2 (Fase 3 toggle) + if t == T_CONM_L or t == T_CONM_R then return end + + -- Puerta H o V (gol=5,6): cambio de habitación con dirección estándar + if t == T_PUERTA_H or t == T_PUERTA_V then + local d = dir_de_movimiento(xf, yf) + if d then cambiar_a_dir(d) end + return + end + + -- Ventana H (gol=7): parche del Pasillo + if t == T_VENT_H then + cambiar_a_dir(dir_vent_h()) + return + end + + -- Ventana V (gol=8): escape directo (línea 1910 del original) + if t == T_VENT_V then + escapado = true + return + end + + -- Pared: bloqueada + if t == T_PARED then return end + + -- Joya, obstáculo, perro: Fase 3/4 + if t == T_JOYA or t == T_OBSTACULO or t == T_PERRO then return end + + -- Vacío: mover + xp, yp = nx, ny +end + +-- ============================================================ +-- BUCLE PRINCIPAL -- ============================================================ function init() mode(MODO) @@ -364,33 +458,36 @@ function init() definir_glifos() init_mapa() rm = 1 - -- Posición inicial del ladrón en cada habitación (centrada-ish) - xp = flr((HABITACIONES[rm].minx + HABITACIONES[rm].maxx) / 2) - yp = HABITACIONES[rm].miny + 2 + xp = 6 + yp = 4 + escapado = false + muerto = false cls() end function update() - -- FASE 1: navegación manual entre habitaciones para verificar - if btnp(KEY_1) then rm = 1 end - if btnp(KEY_2) then rm = 2 end - if btnp(KEY_3) then rm = 3 end - if btnp(KEY_4) then rm = 4 end - if btnp(KEY_5) then rm = 5 end - -- Tecla L para alternar la luz de la habitación actual (debug) - if btnp(KEY_L) then HABITACIONES[rm].luz = not HABITACIONES[rm].luz end + -- Movimiento del jugador (cursores). Fase 5 manejará escapado/muerto. + if escapado or muerto then + pintar_fondo() + color(COL_TEXTO, COL_FONDO) + if escapado then print("ESCAPADO (Fase 5)", 1, 10) end + if muerto then print("MUERTO (Fase 5)", 1, 10) end + return + end - -- Reposicionar al ladrón al cambiar de habitación - local hab = HABITACIONES[rm] - if xp < hab.minx or xp > hab.maxx or yp < hab.miny or yp > hab.maxy then - xp = flr((hab.minx + hab.maxx) / 2) - yp = hab.miny + 2 + if (cnt() - ultimo_tic) >= TICS_JUGADOR then + local xf, yf = 0, 0 + if btn(KEY_UP) then yf = -1 + elseif btn(KEY_DOWN) then yf = 1 end + if btn(KEY_LEFT) then xf = -1 + elseif btn(KEY_RIGHT) then xf = 1 end + if xf ~= 0 or yf ~= 0 then + mover_jugador(xf, yf) + ultimo_tic = cnt() + end end pintar_fondo() pintar_banner() pintar_habitacion() - - color(COL_TEXTO, COL_FONDO) - print("1..5 hab. L luz", 1, FILA_MSG) end