diff --git a/pepe_runner.lua b/pepe_runner.lua index b85dfc1..7e9f419 100644 --- a/pepe_runner.lua +++ b/pepe_runner.lua @@ -36,15 +36,19 @@ TICS = 6 -- frames per tick de joc (60fps / 6 = 10 Hz) NUM_MALOS = 3 TEMPS_IA = 30 -- iteracions del malo entre canvis de direccio MALO_RATIO = 4 -- els malos van 1/4 del ritme del Pepe (com en RUNNER.PAS) +NUM_FASES = 10 -- mapes 1..10 (el 0 esta reservat per al titol) +VIDES_INI = 3 -- l'original arrancava amb 0 (1 vida); 3 es mes raonable -- Estat global mapa = {} -- mapa[x][y] = { tipo=, color=, temps= } level = 1 -pepe = { x=19, y=23, dibuix=PEPE_C, color=COLOR_WHITE, vides=0, estat=NORMAL } +pepe = { x=19, y=23, dibuix=PEPE_C, color=COLOR_WHITE, vides=VIDES_INI, estat=NORMAL } malos = {} score = 0 diners_pantalla = 0 game_tic = 0 +hi_score = 0 +nom_hi_score = "..." function definir_glifs() setchar(BUIT, 0,0,0,0,0,0,0,0) @@ -148,6 +152,12 @@ function tic_pepe() -- Si no passa res especial, estat = normal (gravetat pot canviar-ho mes avall) pepe.estat = NORMAL + -- Final pantalla: si arriba a la fila 1, passa al nivel seguent + if pepe.y == 1 then + fase_nova() + return + end + -- Emparedat: si la cel·la actual s'ha tornat pedra, Pepe mor if tipo_a(pepe.x, pepe.y) == PEDRA then mort_pepe() @@ -179,7 +189,6 @@ function tic_pepe() if pepe.y > MAP_H-1 then pepe.y = MAP_H-1 end end --- De moment, mort = respawn (vides i game over van en la Fase 5) function mort_pepe() pepe.vides = pepe.vides - 1 pepe.x = 19 @@ -187,6 +196,32 @@ function mort_pepe() pepe.estat = NORMAL end +-- Inicialitza tot per a una nova partida (reset complet) +function inicialitzacio() + level = 1 + score = 0 + pepe.vides = VIDES_INI + pepe.x = 19; pepe.y = 23; pepe.estat = NORMAL + carregar_mapa(level) + init_malos() + game_tic = 0 +end + +-- Avanca al nivell seguent (sense reset de score ni vides) +function fase_nova() + level = level + 1 + if level > NUM_FASES then level = 1 end + pepe.x = 19; pepe.y = 23; pepe.estat = NORMAL + carregar_mapa(level) + init_malos() +end + +-- Game over de la Fase 5: simple reset a la inicialitzacio. +-- La pantalla de Game Over i records venen a la Fase 6. +function game_over() + inicialitzacio() +end + -- ==================================================================== -- ENEMICS -- ==================================================================== @@ -261,11 +296,12 @@ end -- A diferencia del Pascal, sols solta diners si en duia (l'original sempre -- escrivia diners a (carrega.x, carrega.y), deixant un $ a (0,0) com a bug). function mort_malo(m) + -- El comptador diners_pantalla NO canvia: l'enemic agafant/soltant es + -- transitori, sols compta el que el Pepe recull definitivament. if m.carrega.ok then local c = mapa[m.carrega.x][m.carrega.y] c.tipo = DINERS c.color = COL_DINERS - diners_pantalla = diners_pantalla + 1 end m.x = 39; m.y = 1 m.color = COLOR_CYAN @@ -346,6 +382,17 @@ function check_mort_per_malos() end end +-- Si Pepe ha recollit tots els diners, fa apareixer una escala a la columna 0 +-- des de la fila 1 cap avall, parant si troba pedra. (CheckMapaComplet) +function check_mapa_complet() + if diners_pantalla > 0 then return end + for j = 1, MAP_H-2 do + if mapa[0][j].tipo == PEDRA then break end + mapa[0][j].tipo = ESCALA + mapa[0][j].color = COL_ESCALA + end +end + -- Anima els forats: decrementa temps i cambia el tipus segons la fase -- (idem case statement de CheckMapa al RUNNER.PAS) function check_mapa() @@ -371,6 +418,20 @@ function check_mapa() -- t == -1 → idle, no fer res end end + check_mapa_complet() +end + +-- HUD: rotul inferior amb level/score/vides/hi-score sobre banda blava +function pintar_hud() + color(COLOR_LIGHT_GRAY, COLOR_BLUE) + local blank = " " + print(blank, 0, 25) + print(blank, 0, 26) + print(blank, 0, 27) + print(" LEVEL "..string.format("%02d", level), 0, 26) + print("SCORE "..string.format("%03d", score), 14, 26) + print("LIVES "..tostr(pepe.vides), 28, 26) + print("HI-SCORE "..string.format("%03d", hi_score).." "..nom_hi_score, 9, 27) end function init() @@ -378,8 +439,7 @@ function init() border(COLOR_BLUE) color(COLOR_LIGHT_GRAY, COLOR_BLACK) definir_glifs() - carregar_mapa(level) - init_malos() + inicialitzacio() cls() end @@ -400,6 +460,7 @@ function update() check_mort_per_malos() end check_mapa() + if pepe.vides < 0 then game_over() end end -- Render: cada frame @@ -407,4 +468,5 @@ function update() pintar_mapa() pintar_malos() pintar_pepe() + pintar_hud() end