diff --git a/guante_blanco.lua b/guante_blanco.lua index 7f913be..566f680 100644 --- a/guante_blanco.lua +++ b/guante_blanco.lua @@ -24,6 +24,22 @@ AREA_Y1 = 22 -- última fila -- Ritmo del movimiento del jugador (frames entre pasos) TICS_JUGADOR = 4 +-- Generación procedural (líneas 1000-1170 del original): +-- joyar = INT(RND*8) + 2 → 2..9 joyas por habitación +-- objr = INT(RND*10) + 5 → 5..14 obstáculos por habitación +JOYAS_MIN = 2 +JOYAS_RND = 8 +OBJ_MIN = 5 +OBJ_RND = 10 + +-- Retardo del perro (línea 60): empieza en 200, cada choque ruidoso resta 50, +-- mínimo 50. La activación del perro la maneja la Fase 4. +RETARDO_INI = 200 +RETARDO_MIN = 50 +RETARDO_STEP = 50 +RUIDO_RND = 15 +RUIDO_UMBRAL = 10 + -- ============================================================ -- PALETA (mapeo CPC firmware → CGA disponible) -- Original: INK 0,0 (negro) / 1,26 (pastel) / 2,15 (blanco) / @@ -202,6 +218,14 @@ 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) +-- Joyas y obstáculos (listas paralelas al mapa por habitación) +joyas_lista = {} -- joyas_lista[rm] = { {x,y}, ... } +obj_lista = {} -- obj_lista[rm] = { {x,y}, ... } +joyas_total = 0 -- total inicial (suma de las 5 habitaciones) +robado = 0 -- joyas recogidas por el ladrón +mensaje_msg = "" -- mensaje de la fila inferior (Choque, etc.) +retardo = RETARDO_INI + -- ============================================================ -- CONSTRUCCIÓN DEL MAPA LÓGICO -- Por habitación se construye una matriz [x][y] con el tipo de @@ -336,19 +360,24 @@ function pintar_habitacion() end end - -- Paredes y elementos + -- Paredes y elementos. Las joyas y obstáculos solo se ven con la luz + -- encendida (línea 1280 del original: INK 7,10 ↔ INK 7,0). for y = hab.miny - 1, hab.maxy + 1 do for x = hab.minx - 1, hab.maxx + 1 do local t = mapa[rm][x][y] if t ~= T_VACIO then - local on = false - if t == T_CONM_L or t == T_CONM_R then - on = conm_estado(hab, x, y) - end - local g = glifo_de(t, on) - if g then - color(color_de(t), COL_FONDO) - print(chr(g), x + off_x, y + off_y) + local oculto = (not hab.luz) and (t == T_JOYA or t == T_OBSTACULO) + if not oculto then + local on = false + if t == T_CONM_L or t == T_CONM_R then + on = conm_estado(hab, x, y) + end + local g = glifo_de(t, on) + if g then + local bg = (t == T_JOYA or t == T_OBSTACULO) and paper or COL_FONDO + color(color_de(t), bg) + print(chr(g), x + off_x, y + off_y) + end end end end @@ -359,6 +388,116 @@ function pintar_habitacion() print(chr(hombre_glifo), xp + off_x, yp + off_y) end +-- Marcador lateral de joyas robadas: una marca vertical por joya, replicando +-- el "MOVE 400,150+(robado*2):DRAW 555,150+(robado*2)" del original. +function pintar_marcador() + color(COL_JOYA, COL_FONDO) + print("Joyas", 26, 1) + print(string.format("%02d", robado), 27, 2) + for i = 1, robado do + local y = AREA_Y1 - (i - 1) + if y >= 4 then + print(chr(154), 28, y) + end + end +end + +function pintar_msg() + if mensaje_msg ~= "" then + color(COL_MSG, COL_FONDO) + print(mensaje_msg, 4, FILA_MSG) + end +end + +-- ============================================================ +-- GENERACIÓN PROCEDURAL DE JOYAS Y OBSTÁCULOS +-- Líneas 980-1170 del original. Las posiciones se eligen al +-- azar dentro del interior, sin comprobar conflictos (fiel al +-- original — una joya/obstáculo puede caer encima de otra). +-- ============================================================ +function generar_objetos() + joyas_total = 0 + robado = 0 + joyas_lista = {} + obj_lista = {} + for id, hab in pairs(HABITACIONES) do + joyas_lista[id] = {} + obj_lista[id] = {} + local nj = rnd(JOYAS_RND) + JOYAS_MIN + local no = rnd(OBJ_RND) + OBJ_MIN + for i = 1, nj do + local x = rnd(hab.maxx - hab.minx + 1) + hab.minx + local y = rnd(hab.maxy - hab.miny + 1) + hab.miny + joyas_lista[id][#joyas_lista[id] + 1] = { x=x, y=y } + mapa[id][x][y] = T_JOYA + joyas_total = joyas_total + 1 + end + for i = 1, no do + local x = rnd(hab.maxx - hab.minx + 1) + hab.minx + local y = rnd(hab.maxy - hab.miny + 1) + hab.miny + obj_lista[id][#obj_lista[id] + 1] = { x=x, y=y } + if mapa[id][x][y] ~= T_JOYA then + mapa[id][x][y] = T_OBSTACULO + end + end + end +end + +-- ============================================================ +-- TOGGLE DE CONMUTADOR Y LUZ (líneas 1700-1740 del original) +-- ============================================================ +function toggle_conmutador(x, y) + local hab = HABITACIONES[rm] + for _, e in ipairs(hab.elementos) do + if e.tipo == "conm" and e.x == x and e.y == y then + e.on = not e.on + break + end + end + hab.luz = not hab.luz -- línea 1730: luces(rm) XOR 1 + sfx_conm() +end + +-- ============================================================ +-- RECOGIDA DE JOYAS (líneas 1980-2090 del original) +-- El bucle recoge TODAS las joyas que estén en (x,y) — fiel al +-- "GOTO 1990" del original. +-- ============================================================ +function recoger_joyas_en(x, y) + local i = 1 + while i <= #joyas_lista[rm] do + local j = joyas_lista[rm][i] + if j.x == x and j.y == y then + table.remove(joyas_lista[rm], i) + robado = robado + 1 + sfx_joya() + else + i = i + 1 + end + end + mapa[rm][x][y] = T_VACIO +end + +-- ============================================================ +-- CHOQUE CONTRA OBSTÁCULO (líneas 2100-2170 del original) +-- ============================================================ +function chocar_obstaculo() + local ruido = rnd(RUIDO_RND) + sfx_obstaculo(ruido) + mensaje_msg = "Choque" + if ruido >= RUIDO_UMBRAL and retardo > RETARDO_MIN then + retardo = retardo - RETARDO_STEP + -- La activación del perro en sí la maneja la Fase 4. + end +end + +-- ============================================================ +-- SFX +-- ============================================================ +function sfx_joya() sound(2000, 6) end +function sfx_obstaculo(r) sound(3000, 5 + r) end +function sfx_conm() sound(800, 3) end + -- ============================================================ -- MOVIMIENTO Y CAMBIO DE HABITACIÓN -- Reproducción de la lógica de las líneas 1520-1900 del original. @@ -416,8 +555,11 @@ function mover_jugador(xf, yf) 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 + -- Conmutador (gol=1..4): toggle luz, no se mueve + if t == T_CONM_L or t == T_CONM_R then + toggle_conmutador(nx, ny) + 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 @@ -441,11 +583,29 @@ function mover_jugador(xf, yf) -- 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 + -- Joya (gol=9): mover y recoger + if t == T_JOYA then + xp, yp = nx, ny + recoger_joyas_en(nx, ny) + mensaje_msg = "" + return + end + + -- Obstáculo (gol=10): no mueve, ruido + if t == T_OBSTACULO then + chocar_obstaculo() + return + end + + -- Perro (gol=11): mordido (Fase 4 implementa la consecuencia) + if t == T_PERRO then + muerto = true + return + end -- Vacío: mover xp, yp = nx, ny + mensaje_msg = "" end -- ============================================================ @@ -457,6 +617,9 @@ function init() color(COL_TEXTO, COL_FONDO) definir_glifos() init_mapa() + generar_objetos() + retardo = RETARDO_INI + mensaje_msg = "" rm = 1 xp = 6 yp = 4 @@ -490,4 +653,6 @@ function update() pintar_fondo() pintar_banner() pintar_habitacion() + pintar_marcador() + pintar_msg() end