-- Pepe Runner — port a ascii/Lua del joc original en Turbo Pascal (JailDesigner, 2000) -- Fase 1: render estatic d'un mapa -- Codis CP437 dels sprites del joc original (de TIPOS.PAS) BUIT = 0 DINERS = 36 -- $ PEDRA = 219 -- bloc solid ESCALA = 205 -- ═ (linia doble horitzontal, formant graons d'escala) CORDA = 196 -- ─ (linia simple horitzontal) BLOC1 = 176 -- ░ BLOC2 = 177 -- ▒ BLOC3 = 178 -- ▓ PEPE_C = 2 -- sprite del Pepe MALO_C = 88 -- 'X' enemics -- Colors (de TIPOS.PAS, paleta CGA — coincideix amb la d'ascii) COL_PEDRA = COLOR_BROWN -- 6 COL_DINERS = COLOR_YELLOW -- 14 COL_ESCALA = COLOR_LIGHT_GRAY -- 7 COL_CORDA = COLOR_LIGHT_GRAY -- 7 COL_BUIT = COLOR_BLACK -- 0 -- Mida del mapa (del joc original) MAP_W = 40 MAP_H = 25 -- Estat mapa = {} -- mapa[x][y] = { tipo=, color=, temps= } level = 1 function definir_glifs() -- Cel·la buida (sobreescrivim el glif 0 del ROM, que no es buit) setchar(BUIT, 0,0,0,0,0,0,0,0) -- Pedra (█) — bloc solid setchar(PEDRA, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF) -- Diners ($) — signe dolar classic setchar(DINERS, 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00) -- Escala (═) — doble linia horitzontal setchar(ESCALA, 0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00) -- Corda (─) — linia horitzontal simple setchar(CORDA, 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00) -- Blocs degradats (per al fade dels forats) setchar(BLOC1, 0x44,0x11,0x44,0x11,0x44,0x11,0x44,0x11) -- ░ light setchar(BLOC2, 0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55) -- ▒ medium setchar(BLOC3, 0xBB,0xEE,0xBB,0xEE,0xBB,0xEE,0xBB,0xEE) -- ▓ dark -- Pepe (cara feliç tipus CP437 char 2 ☻) setchar(PEPE_C, 0x7E,0x81,0xA5,0x81,0xBD,0x99,0x81,0x7E) -- Enemic — una 'X' marcada setchar(MALO_C, 0x00,0xC3,0x66,0x3C,0x18,0x3C,0x66,0xC3) end -- Retorna el color associat a un tipus de cel·la function color_de(tipo) if tipo == PEDRA then return COL_PEDRA end if tipo == DINERS then return COL_DINERS end if tipo == ESCALA then return COL_ESCALA end if tipo == CORDA then return COL_CORDA end return COL_BUIT end -- Carrega un mapa des d'un fitxer .map (1000 bytes, column-major: byte[x*25+y]) -- Estrategia: filein() a l'adreca 0 (sobreescriu char_screen), llegim amb peek() -- a una taula Lua, i despres fem cls() per netejar la pantalla. function carregar_mapa(num) filein("maps/"..tostr(num)..".map", 0, MAP_W*MAP_H) for x = 0, MAP_W-1 do mapa[x] = {} for y = 0, MAP_H-1 do local tipo = peek(x*MAP_H + y) mapa[x][y] = { tipo=tipo, color=color_de(tipo), temps=-1 } end end end function pintar_mapa() for x = 0, MAP_W-1 do for y = 0, MAP_H-1 do local c = mapa[x][y] if c.tipo ~= BUIT then color(c.color, COL_BUIT) print(chr(c.tipo), x, y) end end end end function init() mode(1) -- 40x30 chars, color per cel·la border(COLOR_BLUE) color(COLOR_LIGHT_GRAY, COLOR_BLACK) definir_glifs() carregar_mapa(level) cls() -- neteja despres del filein (que ha escrit a char_screen) pintar_mapa() end function update() -- Fase 1: nomes render estatic, res que actualitzar encara end