diff --git a/.gitignore b/.gitignore index 7014d68..3d366d0 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,8 @@ $RECYCLE.BIN/ .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* @@ -67,3 +68,10 @@ Temporary Items # .nfs files are created when an open file is removed but is still being accessed .nfs* +# Claude Code local settings +.claude/ + +# Binaris del interpret ascii (no son del joc) +ascii +ascii.exe +SDL2.dll \ No newline at end of file diff --git a/ASCII_API.md b/ASCII_API.md new file mode 100644 index 0000000..657a413 --- /dev/null +++ b/ASCII_API.md @@ -0,0 +1,275 @@ +# ASCII — Referencia del intérprete Lua + +Documento extraído del código fuente en `c:/mingw/gitea/ascii/` (principalmente `ascii.cpp`, `lua.cpp`, `play.cpp`, `ascii.h`). Sirve como guía para portar Pepe Runner desde Turbo Pascal a Lua. + +> Versión analizada del intérprete: v0.6.1 aprox (según el mensaje del boot ROM en `lua.cpp`). + +--- + +## 1. Modelo de ejecución + +Cada juego/programa es **un solo fichero `.lua`** que define dos funciones globales: + +```lua +function init() + -- se llama una sola vez al arrancar +end + +function update() + -- se llama cada frame (~60 FPS, vsync) +end +``` + +- El intérprete se invoca como `ascii.exe nombre_juego.lua`. Si no se pasa argumento, intenta cargar `game.lua`. +- También se puede **arrastrar y soltar** un `.lua` sobre la ventana para cargarlo. +- **F5** reinicia el juego (re-llama a `init()` y vuelve a empezar el bucle). +- **ESC** pausa la ejecución y abre una consola de depuración (`> ` prompt). Los comandos `run` y `cont` la cierran. Comandos prefijados con `?` evalúan e imprimen (ej.: `?1+1`). +- Se usa la versión estándar de Lua que está vendorizada en `ascii/lua/` (con `luaL_openlibs`), así que están disponibles `string`, `math`, `table`, etc. + +--- + +## 2. Modos de pantalla — `mode(n)` + +| Modo | Resolución carácter | Resolución pixel | Notas | +|------|--------------------:|-----------------:|-------| +| 0 | 80 × 30 | 640 × 240 | Color único global (no por-carácter) — usado para depuración / texto. `current_color` aplica a toda la pantalla. | +| 1 | 40 × 30 | 320 × 240 | **Modo por defecto.** Color por carácter. | +| 2 | 20 × 15 | 160 × 120 | Mitad de resolución. Cómodo para tiles grandes (ej.: sokoban). | +| 3 | 32 × 24 | 256 × 192 | Estilo "ZX Spectrum" (con bordes anchos). | + +Cada carácter es **8×8 píxeles**. Los gráficos son texto coloreado, no píxeles libres — el "lienzo" es una matriz de celdas (carácter + atributo de color). + +--- + +## 3. Paleta de colores (16, CGA/EGA) + +Constantes Lua predefinidas (`lua.cpp` líneas 610-625): + +| Código | Constante | Aprox. | +|-------:|------------------------|---------------| +| 0 | `COLOR_BLACK` | #000000 | +| 1 | `COLOR_BLUE` | #0000AA | +| 2 | `COLOR_GREEN` | #00AA00 | +| 3 | `COLOR_CYAN` | #00AAAA | +| 4 | `COLOR_RED` | #AA0000 | +| 5 | `COLOR_MAGENTA` | #AA00AA | +| 6 | `COLOR_BROWN` | #AA5500 | +| 7 | `COLOR_LIGHT_GRAY` | #AAAAAA | +| 8 | `COLOR_DARK_GRAY` | #555555 | +| 9 | `COLOR_LIGHT_BLUE` | #5555FF | +| 10 | `COLOR_LIGHT_GREEN` | #55FF55 | +| 11 | `COLOR_LIGHT_CYAN` | #55FFFF | +| 12 | `COLOR_LIGHT_RED` | #FF5555 | +| 13 | `COLOR_LIGHT_MAGENTA` | #FF55FF | +| 14 | `COLOR_YELLOW` | #FFFF55 | +| 15 | `COLOR_WHITE` | #FFFFFF | + +El atributo de color de una celda es 1 byte: nibble bajo = INK (tinta), nibble alto = PAPER (fondo). + +--- + +## 4. API — Funciones expuestas a Lua + +### Pantalla y color + +| Función | Descripción | +|---------|-------------| +| `mode(n)` | Cambia modo de pantalla (0-3) y hace cls. | +| `cls([chr=32])` | Limpia con el carácter dado (32 = espacio). En modo ≠0 además rellena el color attr. | +| `ink(c)` | Color de tinta (0-15). | +| `paper(c)` | Color de fondo (0-15). | +| `border(c)` | Color del borde de la ventana. | +| `color(ink, paper, [border])` | Combina los tres. | +| `locate(x, y)` | Posiciona cursor en celda (x, y). | +| `print(str, [x, y])` | Imprime `str` (sin salto de línea). Si se dan x,y, primero hace `locate`. | +| `crlf()` | CR + LF (mueve cursor a inicio de siguiente línea). | + +### Entrada + +| Función | Descripción | +|---------|-------------| +| `btn(k)` | `true` si la tecla `k` está pulsada *en este frame* (estado SDL_GetKeyboardState). | +| `btnp(k)` | `true` solo en el frame en que la tecla se pulsa (edge). | +| `mousex()` / `mousey()` | Posición del ratón en **coordenadas de carácter** (ya escalado al modo). | +| `mousewheel()` | Delta de la rueda en este frame. | +| `mousebutton(i)` | `true` si el botón `i` está pulsado (1=izq, 2=medio, 3=der; usa `SDL_BUTTON(i)`). | + +> **Nota**: `whichbtn()` está declarado en `ascii.h` y existe en C++, pero **no está expuesto a Lua** (no aparece en los `lua_setglobal` de `lua.cpp`). Para detectar qué tecla se ha pulsado en un frame hay que iterar con `btnp()` sobre las constantes `KEY_*`. + +> **Bug de `tostr` con negativos**: la implementación de `tostr()` en `lua.cpp` (función `intToStr`) hace `(x % 10) + '0'` que con `x = -1` produce `-1 + 48 = 47`, o sea `'/'`. Por tanto `tostr(-1)` devuelve `"/"`, `tostr(-2)` devuelve `"."`, etc. Si vas a imprimir un número que puede ser negativo, usa `string.format("%d", n)` (que sí maneja signo) o clampa con `max(0, n)` antes de pasar a `tostr`. + +Códigos de tecla — todos definidos como globales `KEY_*` en Lua. Lista completa (de `lua.cpp` 502-608): + +``` +KEY_A..KEY_Z = 4..29 +KEY_1..KEY_0 = 30..39 (1=30, 2=31, ..., 9=38, 0=39) +KEY_RETURN=40 KEY_ESCAPE=41 KEY_BACKSPACE=42 KEY_TAB=43 KEY_SPACE=44 +KEY_MINUS=45 KEY_EQUALS=46 KEY_LEFTBRACKET=47 KEY_RIGHTBRACKET=48 +KEY_BACKSLASH=49 KEY_NONUSHASH=50 KEY_SEMICOLON=51 KEY_APOSTROPHE=52 +KEY_GRAVE=53 KEY_COMMA=54 KEY_PERIOD=55 KEY_SLASH=56 KEY_CAPSLOCK=57 +KEY_F1..KEY_F12 = 58..69 +KEY_PRINTSCREEN=70 KEY_SCROLLLOCK=71 KEY_PAUSE=72 +KEY_INSERT=73 KEY_HOME=74 KEY_PAGEUP=75 KEY_DELETE=76 KEY_END=77 KEY_PAGEDOWN=78 +KEY_RIGHT=79 KEY_LEFT=80 KEY_DOWN=81 KEY_UP=82 +KEY_NUMLOCKCLEAR=83 KEY_KP_DIVIDE=84 KEY_KP_MULTIPLY=85 KEY_KP_MINUS=86 KEY_KP_PLUS=87 KEY_KP_ENTER=88 +KEY_KP_1..KEY_KP_0 = 89..98 KEY_KP_PERIOD=99 +KEY_NONUSBACKSLASH=100 KEY_APPLICATION=101 +KEY_LCTRL=224 KEY_LSHIFT=225 KEY_LALT=226 KEY_LGUI=227 +KEY_RCTRL=228 KEY_RSHIFT=229 KEY_RALT=230 KEY_RGUI=231 +``` + +(Son los SDL2 scancodes.) + +### Matemáticas + +`abs(x)`, `ceil(x)`, `flr(x)`, `sgn(x)`, `sin(x)`, `cos(x)`, `atan2(dx, dy)`, `sqrt(x)`, `max(a,b)`, `min(a,b)`, `mid(a,b,c)` (devuelve el del medio, equivalente a `clamp`). + +`rnd(n)` devuelve un entero en `[0, n-1]` (`rand()%n`). `srand(seed)` siembra el RNG. + +### Strings + +| Función | Descripción | +|---------|-------------| +| `tostr(v)` | Convierte valor a string. Soporta nil, function, table (formato `{k=v,...}`), number, boolean, string. | +| `strlen(s)` | Longitud en bytes. | +| `ascii(s, i)` | Código del byte en índice `i` (0-based). | +| `chr(n)` | String de un solo carácter cuyo código es `n`. | +| `substr(s, start, length)` | Subcadena. | + +> Nota: Lua estándar también está disponible, así que `string.format`, `string.sub`, etc., funcionan. Pero los demos usan estas helpers. + +### Memoria + +| Función | Descripción | +|---------|-------------| +| `peek(addr)` | Lee 1 byte de la VRAM/memoria (0..0x1FFF). | +| `poke(addr, val)` | Escribe 1 byte. | +| `memcpy(dst, src, size)` | Copia bytes en la memoria del fantasy console. | +| `setchar(idx, b0..b7)` | Define los 8 bytes del carácter `idx` en el char-ROM (sobrescribe la fuente). | + +**Mapa de memoria** (8 KB total, `mem[8192]`): + +- `0x0000` (0): char_screen (matriz de códigos de carácter por celda) +- Tras char_screen viene color_screen (offset = `screen_width * screen_height`) +- `0x0A00` (2560 = `MEM_CHAR_OFFSET`): char-ROM (definición de glifos, 8 bytes por carácter, 256 chars = 2048 bytes) +- `0x1200` (4608 = `MEM_BOOT_OFFSET`): zona de boot/recursos de ROM + +Para los modos 1 y 2 los color_screen offsets son 1200 y 300 respectivamente; en modo 3 es 768; en modo 0 no hay color_screen por celda (color global). + +### Audio + +**Sonido simple:** +- `sound(freq, len)` — onda cuadrada a `freq` Hz durante `len` (en algo similar a centésimas de segundo; `audio_len = len*44.1`). +- `nosound()` — silencio inmediato. + +**Mini-lenguaje MML — `play(str)`:** + +Sintaxis tipo BASIC `PLAY` / MML. Tokens (case-sensitive, minúsculas): + +| Token | Significado | +|-------|-------------| +| `c d e f g a b` | Nota. Acepta sufijo `#` o `+` (sostenido) o `-` (bemol). Luego dígito 0-9 para duración. | +| `r` | Silencio. Acepta dígito de duración. | +| `o<0-7>` | Octava absoluta. | +| `>` `<` | Sube / baja octava. | +| `l<0-9>` | Longitud por defecto para notas sin duración. | +| `v<0-9>` | Volumen (se traduce a `(d-0)<<4`). | +| `t<0-9>` | Tempo. | + +Duraciones: índice 0-9 → tabla `{313,625,938,1250,1875,2500,3750,5000,7500,10000}` (de "redonda" a "trentaidosava", aproximadamente). + +Ejemplo (de `breakout.lua`): + +```lua +play("l0o3bagfedc") -- escala descendente como sonido de game-over +play("o5l0c") -- pitido agudo (rebote) +``` + +### Ficheros y portapapeles + +| Función | Descripción | +|---------|-------------| +| `load([filename])` | Reinicia y carga otro `.lua` (o el mismo si filename=nil). | +| `fileout(name, addr, size)` | Vuelca `size` bytes de memoria a un binario. | +| `filein(name, addr, size)` | Carga un binario a memoria. | +| `toclipboard(str)` | Copia al portapapeles del SO. | +| `fromclipboard()` | Lee del portapapeles (máx 1023 chars). | + +### Utilidades de tiempo / frame + +| Función | Descripción | +|---------|-------------| +| `time()` | Milisegundos desde inicio (`SDL_GetTicks()`). | +| `cnt()` | Contador de frames desde el último `rst()`. | +| `rst()` | Resetea el contador de frames a 0. | +| `log(str)` | Imprime en la consola de debug (no en pantalla). | + +--- + +## 5. Caracteres especiales útiles + +Los demos usan códigos > 127 que corresponden a glifos definidos en `rom.c` (el char-ROM por defecto). Algunos vistos: + +- `\003` (3) — un bloque relleno (usado en pong para los compases) +- `\016` (16) — cubo de caja (en sokoban) +- `\127` (127) — pared en sokoban (redefinido con `setchar(127, ...)`) +- `\143`, `\154`, `\150`, `\156`, `\149` — esquinas y trazos de marcos +- `\248`, `\250`, `\251` — sprite animado de "OK" en sokoban +- `\233` — pelota en breakout +- `\131` — pala en breakout +- `\001` — cubo de tetromino (redefinido con `setchar(1, 0xff,0x81,...)`) + +Para usarlos siempre se puede hacer `setchar(idx, b0..b7)` con la bitmap deseada y luego imprimirlo con `print(chr(idx), x, y)`. + +--- + +## 6. Patrón típico de un juego + +```lua +function init() + mode(1) + cls() + -- estado inicial + player = {x=10, y=15} + score = 0 +end + +function update() + -- input + if btnp(KEY_LEFT) then player.x = player.x - 1 end + if btnp(KEY_RIGHT) then player.x = player.x + 1 end + + -- lógica + -- ... + + -- render (no hay vsync explícito; el bucle ya hace flip al final) + cls() + color(COLOR_WHITE, COLOR_BLACK) + print("\248", player.x, player.y) + print("SCORE: "..tostr(score), 0, 0) +end +``` + +**Cosas a recordar:** + +- No se "pintan" píxeles; se imprime un código de carácter en una celda y se le asocia un atributo de color (ink + paper). Para gráficos personalizados, redefinir glifos con `setchar`. +- El bucle de render lo hace el motor C++ después de `update()` — no hay que llamar a ningún `flip`. +- El `state machine` típico se hace asignando `update = otra_funcion` (ver `demos/sokoban.lua`). +- Las coordenadas de pantalla son **enteras y por celda**, no por píxel. (0,0) es esquina superior izquierda. +- Para depurar: `log("mensaje")` o pulsar ESC y usar la consola con `?variable`. + +--- + +## 7. Cómo compilar el intérprete + +Desde `c:/mingw/gitea/ascii/`: + +```sh +make windows +``` + +Requiere MinGW (g++) y SDL2 para Windows. Produce `ascii.exe`. Para correr Pepe Runner: + +```sh +ascii.exe pepe_runner.lua +``` diff --git a/chuleta_font_ascii.png b/chuleta_font_ascii.png new file mode 100644 index 0000000..5356fa5 Binary files /dev/null and b/chuleta_font_ascii.png differ diff --git a/maps/3.map b/maps/3.map new file mode 100644 index 0000000..568d65f --- /dev/null +++ b/maps/3.map @@ -0,0 +1 @@ +±±±±±±±±±±±±±±±±±±±±±±±±±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ±±±±±±±±±±±±Û±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± \ No newline at end of file diff --git a/original_turbopascal/PEPEDIEG.PAS b/original_turbopascal/PEPEDIEG.PAS new file mode 100644 index 0000000..62faf77 --- /dev/null +++ b/original_turbopascal/PEPEDIEG.PAS @@ -0,0 +1,678 @@ +program Pepe_el_pintor; +uses dos,crt,keyboard,cursor,grafics; + +{---------------------------------------------------------------------------------- + constants, variables i tipus +-----------------------------------------------------------------------------------} + +const marge_dalt=0; {Fila on comen‡a el marge de dalt} {----------------------} +const marge_baix=24; {Fila on acaba el marge de baix} { Dimensions de } +const marge_dreta=80; {Columna on acaba marge dret} { la pantalla } +const marge_esq=1; {Columna on comen‡a el marge esquerre} {----------------------} +const tamany_video=2000; +const n_malos=3; +const bicho='X'; +const color_bicho=107; +const pepe=''; +const pared='±'; +const bg='Û'; +const color_pintura=6; +const n_malos_max=3; +const velocitat_joc=60; + + +type caracter=RECORD + car:char; + atrib:byte; + END; + + auxmalo=RECORD + x,y:byte; + viu:boolean; + END; + malo=array [1..n_malos] of auxmalo; + + pos=RECORD + a,b:byte; + END; + + llocsbg=array [1..1315] of pos; + +var malos:malo; + llocs_bg:llocsbg; + color_pepe,i,j,mort,direccio,vides,lloc_x,lloc_y:byte; + pot,nota,total_blocs:integer; + ix,truco,on,sonido,moviment,aparicio:boolean; + el_que_hi_havia,el_que_hi_havia_malo:char; + restant:real; + +{----------------------------------------------------------- + dibuixa la pantalla de joc +------------------------------------------------------------} + +procedure fase_1; +begin + GotoXY(1,1); + TextColor(4); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + TextColor(7);write(' - Beta Version - 1999 Sergi Valor Mart¡nez'); +end; + +procedure fase_2; +begin + GotoXY(1,1); + TextColor(4); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±±±±±±±± ±'); + writeln('± ±±±±±±±±±±±± ±'); + writeln('± ±±±±±±±±±±±±±±±± ±±'); + writeln('± ±'); + writeln('± ±±±±±±±±±±±±±±±± ±±'); + writeln('± ±±±±±±±±±±±± ±'); + writeln('± ±±±±±±±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + TextColor(7);write(' - Beta Version - 1999 Sergi Valor Mart¡nez'); +end; + +procedure dibuixa_pantalla; + +begin + + escriu('Pintura: 90',65,14,0,7); + escriu('',62,11,6,14); + escriu(chr(30),68,17,0,7); + escriu('Q',68,16,0,7); + escriu('A',68,20,0,7); + escriu(chr(31),68,19,0,7); + escriu('O',65,18,0,7); + escriu('P',71,18,0,7); + escriu(chr(16),70,18,0,7); + escriu(chr(17),66,18,0,7); + escriu('ESC - Eixir',65,3,0,7); + escriu('S - So ON',65,5,0,7); +end; + +{---------------------------------------------------------------------------------- + coloca el caracter 'ch' en la posici¢ de pantalla definida en posx i posy +-----------------------------------------------------------------------------------} + +procedure moure(ch:char;atrib,posx,posy:byte); +var pantalla:array [1..tamany_video] of caracter absolute $B800:0000; +begin + if (posy*marge_dreta+posx<=tamany_video) then begin + pantalla[posy*marge_dreta+posx].car:=ch; + pantalla[posy*marge_dreta+posx].atrib:=atrib; + end; +end; + +{---------------------------------------------------------------------------------- + a_v es un vector que emmagatzema la informaci¢ de totes les posicions de pantalla +-----------------------------------------------------------------------------------} + +function a_v(posx,posy:byte):char; +var pantalla:array [1..tamany_video] of caracter absolute $B800:0000; + c:char; +begin + c:=pantalla[posy*marge_dreta+posx].car; + a_v:=c; +end; + +procedure paleta; +begin + for i:=0 to 128 do + begin + moure(pepe,i,i mod 80,i mod 25); + GotoXY((i mod 80)+1,i mod 25);TextColor(7);Write(i); + end; + repeat until qteclapuls; +end; + +procedure una_menos(var i,j:byte); +var z:integer; +begin + z:=10000; + while z>1000 do begin sound(z);delay(1);z:=z-250;end; + vides:=vides-1; + nosound; + delay(2000); + i:=64; + j:=11; +end; + +procedure dibuixa_vides; +var y:byte; +begin + for y:=1 to vides do begin + escriu(' ',78-y,1,0,14); + end; +end; + +procedure musica_malos; +var i,j:byte; +begin + for i:=0 to 5 do + for j:=0 to 40 do begin delay(1);sound(j*200);end; + nosound; +end; + +procedure omplir_pot; +var i:byte; +begin + for i:=0 to 90-pot do begin + gotoXY(76,15);TextColor(7); + write(pot:2); + if sonido then sound(i*10); + pot:=pot+1; + delay(25); + end; + nosound; +end; + +procedure neteja_pantalla(color:byte); +var i:byte; +begin + for i:=1 to 80 do begin + for j:=0 to 24 do begin + moure('Û',color,i,j); + delay(1); + end; + end; +end; + +procedure beta_version; +var i:byte; +begin + Clrscr; + escriu('-AVÖS-',35,7,0,15); + Gotoxy(18,10);TextColor(15);write('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'); + Gotoxy(18,11);TextColor(15);write('º Aquest joc encara no est… acabat, ‚s una º'); + Gotoxy(18,12);TextColor(15);write('º versi¢ preliminar, amb la qual cosa el º'); + Gotoxy(18,13);TextColor(15);write('º resultat final del joc pot variar respecteº'); + Gotoxy(18,14);TextColor(15);write('º del que ara vas a jugar. Gracies º'); + Gotoxy(18,15);TextColor(15);write('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ'); + delay(800); + for i:=24 downto 16 do begin + escriu('-Pulsa una tecla per a continuar-',22,i,0,15); + delay(50); + escriu(' ',22,i,0,15); + end; + escriu('-Pulsa una tecla per a continuar-',22,16,0,15); + repeat until qteclapuls; + GotoXY(1,1); +end; +{---------------------------------------------------------------------------------- + Funci¢ per a menejar als malos +-----------------------------------------------------------------------------------} + +function moure_malos(var malos:malo;x,y:byte;n:word):integer; +var i,j,k:byte;meneja:byte;aux:integer; +begin + aux:=0; {aux es la proximitat dels malos respecte al bo + 0=fora del radar, 1=dins del radar, 2=xoc} + randomize; + for i:=1 to 1 do begin + if malos[n].viu=TRUE then begin {Si el malo 'i' encara est… viu aleshores + es menejara segons la seua posici¢} + + case random(2) of { -----------------------------------} + 0:if x-malos[n].x>0 then meneja:=1 { Funci¢ aleatoria que fa } + else if x-malos[n].x<0 then meneja:=0 { que el malo es moga cap } + { else meneja:=4}; { al bo en l'eix de les x } + 1:if y-malos[n].y>0 then meneja:=3 { o en l'eix de les y o en } + else if y-malos[n].y<0 then meneja:=2 { qualsevol de les quatre } +{ else meneja:=4}; { direccions posibles del } + end; {------------------------------------} + case meneja of + + {----------------------------------} + { Moure el malo cap a l'esquerra } + {----------------------------------} + + 0:if (malos[n].x>marge_esq) + and(not(a_v(malos[n].x-1,malos[n].y)=pared)) + and(not(a_v(malos[n].x-1,malos[n].y)=bicho)) + and(a_v(malos[n].x-1,malos[n].y)=bg)then begin + el_que_hi_havia_malo:=a_v(malos[n].x-1,malos[n].y); + moure(el_que_hi_havia_malo,color_pintura,malos[n].x,malos[n].y); + malos[n].x:=malos[n].x-1; + if a_v(malos[n].x-1,malos[n].y)=pepe then + begin moure(bicho,color_bicho,malos[n].x-1,malos[n].y); + moure(bg,color_pintura,malos[n].x-1,malos[n].y); + aux:=2; + end; + moure(bicho,color_bicho,malos[n].x,malos[n].y); + end; + + {--------------------------------} + { Moure el malo cap a la dreta } + {--------------------------------} + + 1:if (malos[n].xmarge_dalt) + and(not(a_v(malos[n].x,malos[n].y-1)=pared)) + and(not(a_v(malos[n].x,malos[n].y-1)=bicho)) + and(a_v(malos[n].x,malos[n].y-1)=bg) then begin + el_que_hi_havia_malo:=a_v(malos[n].x,malos[n].y-1); + moure(el_que_hi_havia_malo,color_pintura,malos[n].x,malos[n].y); + malos[n].y:=malos[n].y-1; + if a_v(malos[n].x,malos[n].y-1)=pepe then + begin moure(bicho,color_bicho,malos[n].x,malos[n].y-1); + moure(bg,color_pintura,malos[n].x,malos[n].y-1); + aux:=2; + end; + moure(bicho,color_bicho,malos[n].x,malos[n].y); + end; + + {----------------------------} + { Moure el malo cap a baix } + {----------------------------} + + 3:if (malos[n].ymarge_dalt)and(not(a_v(i,j-1)=pared)) then begin + begin + if pot>0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + + if (a_v(i,j-1)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i,j-1)); + if (not(a_v(i,j-1)=bg)) then + begin + j:=j-1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=0; + end + else begin + j:=j-1; + direccio:=0; + end; + end; + end; + + end else + if TeclaPuls($1E){tecla A} then begin + + {moure pepe cap a baix} + moviment:=true; + if sonido then sound(nota);delay(40);nosound; + if (j0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + + if (a_v(i,j+1)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i,j+1)); + if (not(a_v(i,j+1)=bg)) then + begin + j:=j+1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=2; + end + else begin + j:=j+1; + direccio:=2; + end; + end; + end; + + end else + if TeclaPuls($18){tecla O} then begin + + {moure pepe cap a l'esquerra} + moviment:=true; + + if sonido then sound(nota);delay(40);nosound; + if (i>marge_esq)and(not(a_v(i-1,j)=pared))then begin + begin + if pot>0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + if (a_v(i-1,j)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i-1,j)); + if (not(a_v(i-1,j)=bg)) then + begin + i:=i-1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=3; + end + else begin + i:=i-1; + direccio:=3; + end; + end; + end; + + end else + if TeclaPuls($19){tecla P} then begin + + {moure pepe cap a la dreta} + moviment:=true; + + if sonido then sound(nota);delay(40);nosound; + if (i0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + if (a_v(i+1,j)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i+1,j)); + if (not(a_v(i+1,j)=bg)) then + begin + i:=i+1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=1; + end + else begin + i:=i+1; + direccio:=1; + end; + end; + end; + + end; + +{ if TeclaPuls($17)tecla I then begin } + + {truco d'invulnerabilitat} + +{ if on=true then begin + truco:=true; + GotoXY(69,2); + TextColor(15); + TextBackground(4); + write('INVULNERABLE'); + on:=false; + end else begin + truco:=false; + GotoXY(69,2); + TextColor(1); + TextBackground(0); + write('INVULNERABLE'); + on:=true; + end; + end;} + + {terminaci¢ del programa} + if TeclaPuls($1F){tecla S} then begin + sonido:=not(sonido); + if sonido then escriu('ON ',72,5,0,7) + else escriu('OFF',72,5,0,7); + end; + + if TeclaPuls($01){tecla T} then ix:=True; + {-----------------------} + + if moviment then begin + if pot>0 then begin + moure(pepe,110,i,j); + nota:=5000; + end + else begin + if el_que_hi_havia=bg then begin + moure(pepe,111,i,j); + nota:=1000 + end + else begin + moure(chr(1),15,i,j); + nota:=1000; + end; + end; + end; + delay(velocitat_joc); + dibuixa_vides; + { restant:=(trunc(total_blocs*100)/1315); + GotoXY(70,3);Textcolor(7);write(restant:3,'%');} + GotoXY(70,3);Textcolor(7);write(total_blocs:4); + until (ix) or (total_blocs=0) or (vides=0); + nosound; + if total_blocs=0 then escriu('ENHORABONA!',30,11,2,0) + else escriu('ADEU',28,11,0,7); + delay(5000); + neteja_pantalla(0); + delay(1000); + mostrar_cursor; + DesinstalarKb; +end. diff --git a/original_turbopascal/PINTOR.PAS b/original_turbopascal/PINTOR.PAS new file mode 100644 index 0000000..751e148 --- /dev/null +++ b/original_turbopascal/PINTOR.PAS @@ -0,0 +1,551 @@ +program Pepe_el_pintor; +uses dos,crt,keyboard,cursor,grafics; + +{---------------------------------------------------------------------------------- + constants, variables i tipus +-----------------------------------------------------------------------------------} + +const marge_dalt=0; {Fila on comen‡a el marge de dalt} {----------------------} +const marge_baix=24; {Fila on acaba el marge de baix} { Dimensions de } +const marge_dreta=80; {Columna on acaba marge dret} { la pantalla } +const marge_esq=1; {Columna on comen‡a el marge esquerre} {----------------------} +const tamany_video=2000; +const n_malos=2; +const bicho='X'; +const color_bicho=107; +const pepe=''; +const pared='±'; +const bg='Û'; +const color_pintura=6; +const n_malos_max=2; +const velocitat_joc=60; + + +type caracter=RECORD + car:char; + atrib:byte; + END; + + auxmalo=RECORD + x,y:byte; + viu:boolean; + END; + malo=array [1..n_malos] of auxmalo; + +var malos:malo; + color_pepe,i,j,mort,direccio:byte; + pot,nota,total_blocs:integer; + ix,truco,on,sonido,moviment:boolean; + el_que_hi_havia,el_que_hi_havia_malo:char; + +{----------------------------------------------------------- + dibuixa la pantalla de joc +------------------------------------------------------------} + +procedure dibuixa_pantalla; + +begin + GotoXY(1,1); + TextColor(4); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + TextColor(7);write(' - Beta Version - 1999 Sergi Valor Mart¡nez'); + escriu('Pintura: 90',65,14,0,7); + escriu('',62,11,6,14); + escriu(chr(30),68,17,0,7); + escriu('Q',68,16,0,7); + escriu('A',68,20,0,7); + escriu(chr(31),68,19,0,7); + escriu('O',65,18,0,7); + escriu('P',71,18,0,7); + escriu(chr(16),70,18,0,7); + escriu(chr(17),66,18,0,7); + escriu('ESC - Eixir',65,3,0,7); + escriu('S - So ON',65,5,0,7); +end; + +{---------------------------------------------------------------------------------- + coloca el caracter 'ch' en la posici¢ de pantalla definida en posx i posy +-----------------------------------------------------------------------------------} + +procedure moure(ch:char;atrib,posx,posy:byte); +var pantalla:array [1..tamany_video] of caracter absolute $B800:0000; +begin + if (posy*marge_dreta+posx<=tamany_video) then begin + pantalla[posy*marge_dreta+posx].car:=ch; + pantalla[posy*marge_dreta+posx].atrib:=atrib; + end; +end; + +{---------------------------------------------------------------------------------- + a_v es un vector que emmagatzema la informaci¢ de totes les posicions de pantalla +-----------------------------------------------------------------------------------} + +function a_v(posx,posy:byte):char; +var pantalla:array [1..tamany_video] of caracter absolute $B800:0000; + c:char; +begin + c:=pantalla[posy*marge_dreta+posx].car; + a_v:=c; +end; + +procedure paleta; +begin + for i:=0 to 128 do + begin + moure(pepe,i,i mod 80,i mod 25); + GotoXY((i mod 80)+1,i mod 25);TextColor(7);Write(i); + end; + repeat until qteclapuls; +end; + +procedure omplir_pot; +var i:byte; +begin + for i:=0 to 90-pot do begin + gotoXY(76,15);TextColor(7); + write(pot:2); + if sonido then sound(i*10); + pot:=pot+1; + delay(25); + end; + nosound; +end; + +procedure neteja_pantalla(color:byte); +var i:byte; +begin + for i:=1 to 80 do begin + for j:=0 to 24 do begin + moure('Û',color,i,j); + delay(1); + end; + end; +end; + +procedure beta_version; +var i:byte; +begin + Clrscr; + escriu('-AVÖS-',35,7,0,15); + Gotoxy(18,10);TextColor(15);write('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'); + Gotoxy(18,11);TextColor(15);write('º Aquest joc encara no est… acabat, ‚s una º'); + Gotoxy(18,12);TextColor(15);write('º versi¢ preliminar, amb la qual cosa el º'); + Gotoxy(18,13);TextColor(15);write('º resultat final del joc pot variar respecteº'); + Gotoxy(18,14);TextColor(15);write('º del que ara vas a jugar. Gracies º'); + Gotoxy(18,15);TextColor(15);write('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ'); + delay(800); + for i:=24 downto 16 do begin + escriu('-Pulsa una tecla per a continuar-',22,i,0,15); + delay(50); + escriu(' ',22,i,0,15); + end; + escriu('-Pulsa una tecla per a continuar-',22,16,0,15); + repeat until qteclapuls; + GotoXY(1,1); +end; +{---------------------------------------------------------------------------------- + Funci¢ per a menejar als malos +-----------------------------------------------------------------------------------} + +function moure_malos(var malos:malo;x,y:byte):integer; +var i,j,k:byte;meneja:byte;aux:integer; +begin + aux:=0; {aux es la proximitat dels malos respecte al bo + 0=fora del radar, 1=dins del radar, 2=xoc} + randomize; + for i:=1 to n_malos_max do begin + if malos[i].viu=TRUE then begin {Si el malo 'i' encara est… viu aleshores + es menejara segons la seua posici¢} + + case random(2) of { -----------------------------------} + 0:if x-malos[i].x>0 then meneja:=1 { Funci¢ aleatoria que fa } + else if x-malos[i].x<0 then meneja:=0 { que el malo es moga cap } + else meneja:=4; { al bo en l'eix de les x } + 1:if y-malos[i].y>0 then meneja:=3 { o en l'eix de les y o en } + else if y-malos[i].y<0 then meneja:=2 { qualsevol de les quatre } + else meneja:=4; { direccions posibles del } + end; {------------------------------------} + case meneja of + + {----------------------------------} + { Moure el malo cap a l'esquerra } + {----------------------------------} + + 0:if (malos[i].x>marge_esq) + and(not(a_v(malos[i].x-1,malos[i].y)=pared)) + and(not(a_v(malos[i].x-1,malos[i].y)=bicho)) + and(a_v(malos[i].x-1,malos[i].y)=bg)then begin + el_que_hi_havia_malo:=a_v(malos[i].x-1,malos[i].y); + moure(el_que_hi_havia_malo,color_pintura,malos[i].x,malos[i].y); + malos[i].x:=malos[i].x-1; + if a_v(malos[i].x,malos[i].y)=pepe then + begin aux:=2; break; end; + moure(bicho,color_bicho,malos[i].x,malos[i].y); + end; + + {--------------------------------} + { Moure el malo cap a la dreta } + {--------------------------------} + + 1:if (malos[i].xmarge_dalt) + and(not(a_v(malos[i].x,malos[i].y-1)=pared)) + and(not(a_v(malos[i].x,malos[i].y-1)=bicho)) + and(a_v(malos[i].x,malos[i].y-1)=bg) then begin + el_que_hi_havia_malo:=a_v(malos[i].x,malos[i].y-1); + moure(el_que_hi_havia_malo,color_pintura,malos[i].x,malos[i].y); + malos[i].y:=malos[i].y-1; + if a_v(malos[i].x,malos[i].y)=pepe then + begin aux:=2;break;end; + moure(bicho,color_bicho,malos[i].x,malos[i].y); + end; + + {----------------------------} + { Moure el malo cap a baix } + {----------------------------} + + 3:if (malos[i].ymarge_dalt)and(not(a_v(i,j-1)=pared)) then begin + begin + if pot>0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + + if (a_v(i,j-1)=bicho)and(truco=false) then begin + GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break; + end else begin + el_que_hi_havia:=(a_v(i,j-1)); + if (not(a_v(i,j-1)=bg)) then + begin + j:=j-1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=0; + end + else begin + j:=j-1; + direccio:=0; + end; + end; + end; + + end else + if TeclaPuls($1E){tecla A} then begin + + {moure pepe cap a baix} + moviment:=true; + if sonido then sound(nota);delay(40);nosound; + if (j0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + + if (a_v(i,j+1)=bicho)and(truco=false) then begin + GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break; + end else begin + el_que_hi_havia:=(a_v(i,j+1)); + if (not(a_v(i,j+1)=bg)) then + begin + j:=j+1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=2; + end + else begin + j:=j+1; + direccio:=2; + end; + end; + end; + + end else + if TeclaPuls($18){tecla O} then begin + + {moure pepe cap a l'esquerra} + moviment:=true; + + if sonido then sound(nota);delay(40);nosound; + if (i>marge_esq)and(not(a_v(i-1,j)=pared))then begin + begin + if pot>0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + if (a_v(i-1,j)=bicho)and(truco=false) then begin + GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break; + end else begin + el_que_hi_havia:=(a_v(i-1,j)); + if (not(a_v(i-1,j)=bg)) then + begin + i:=i-1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=3; + end + else begin + i:=i-1; + direccio:=3; + end; + end; + end; + + end else + if TeclaPuls($19){tecla P} then begin + + {moure pepe cap a la dreta} + moviment:=true; + + if sonido then sound(nota);delay(40);nosound; + if (i0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + if (a_v(i+1,j)=bicho)and(truco=false) then begin + GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break; + end else begin + el_que_hi_havia:=(a_v(i+1,j)); + if (not(a_v(i+1,j)=bg)) then + begin + i:=i+1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=1; + end + else begin + i:=i+1; + direccio:=1; + end; + end; + end; + + end; + +{ if TeclaPuls($17)tecla I then begin } + + {truco d'invulnerabilitat} + +{ if on=true then begin + truco:=true; + GotoXY(69,2); + TextColor(15); + TextBackground(4); + write('INVULNERABLE'); + on:=false; + end else begin + truco:=false; + GotoXY(69,2); + TextColor(1); + TextBackground(0); + write('INVULNERABLE'); + on:=true; + end; + end;} + + {terminaci¢ del programa} + if TeclaPuls($1F){tecla S} then begin + sonido:=not(sonido); + if sonido then escriu('ON ',72,5,0,7) + else escriu('OFF',72,5,0,7); + end; + + if TeclaPuls($01){tecla T} then ix:=True; + {-----------------------} + + if moviment then begin + if pot>0 then begin + moure(pepe,110,i,j); + nota:=5000; + end + else begin + if el_que_hi_havia=bg then begin + moure(pepe,111,i,j); + nota:=1000 + end + else begin + moure(pepe,15,i,j); + nota:=1000; + end; + end; + end; + delay(velocitat_joc); + GotoXY(75,1);Textcolor(7);write(total_blocs:4); + until (ix) or (total_blocs=0); + nosound; + if total_blocs=0 then escriu('ENHORABONA!',30,11,2,0) + else escriu('ADEU',28,11,0,7); + delay(2000); + neteja_pantalla(0); + delay(1000); + mostrar_cursor; + DesinstalarKb; +end. diff --git a/original_turbopascal/PINTOR2.PAS b/original_turbopascal/PINTOR2.PAS new file mode 100644 index 0000000..3002037 --- /dev/null +++ b/original_turbopascal/PINTOR2.PAS @@ -0,0 +1,634 @@ +program Pepe_el_pintor; +uses dos,crt,keyboard,cursor,grafics; + +{---------------------------------------------------------------------------------- + constants, variables i tipus +-----------------------------------------------------------------------------------} + +const marge_dalt=0; {Fila on comen‡a el marge de dalt} {----------------------} +const marge_baix=24; {Fila on acaba el marge de baix} { Dimensions de } +const marge_dreta=80; {Columna on acaba marge dret} { la pantalla } +const marge_esq=1; {Columna on comen‡a el marge esquerre} {----------------------} +const tamany_video=2000; +const n_malos=3; +const bicho='X'; +const color_bicho=107; +const pepe=''; +const pared='±'; +const bg='Û'; +const color_pintura=6; +const n_malos_max=3; +const velocitat_joc=60; + + +type caracter=RECORD + car:char; + atrib:byte; + END; + + auxmalo=RECORD + x,y:byte; + viu:boolean; + END; + malo=array [1..n_malos] of auxmalo; + + pos=RECORD + a,b:byte; + END; + + llocsbg=array [1..1315] of pos; + +var malos:malo; + llocs_bg:llocsbg; + color_pepe,i,j,mort,direccio,vides,lloc_x,lloc_y:byte; + pot,nota,total_blocs:integer; + ix,truco,on,sonido,moviment:boolean; + el_que_hi_havia,el_que_hi_havia_malo:char; + restant:real; + +{----------------------------------------------------------- + dibuixa la pantalla de joc +------------------------------------------------------------} + +procedure dibuixa_pantalla; + +begin + GotoXY(1,1); + TextColor(4); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + TextColor(7);write(' - Beta Version - 1999 Sergi Valor Mart¡nez'); + escriu('Pintura: 90',65,14,0,7); + escriu('',62,11,6,14); + escriu(chr(30),68,17,0,7); + escriu('Q',68,16,0,7); + escriu('A',68,20,0,7); + escriu(chr(31),68,19,0,7); + escriu('O',65,18,0,7); + escriu('P',71,18,0,7); + escriu(chr(16),70,18,0,7); + escriu(chr(17),66,18,0,7); + escriu('ESC - Eixir',65,3,0,7); + escriu('S - So ON',65,5,0,7); +end; + +{---------------------------------------------------------------------------------- + coloca el caracter 'ch' en la posici¢ de pantalla definida en posx i posy +-----------------------------------------------------------------------------------} + +procedure moure(ch:char;atrib,posx,posy:byte); +var pantalla:array [1..tamany_video] of caracter absolute $B800:0000; +begin + if (posy*marge_dreta+posx<=tamany_video) then begin + pantalla[posy*marge_dreta+posx].car:=ch; + pantalla[posy*marge_dreta+posx].atrib:=atrib; + end; +end; + +{---------------------------------------------------------------------------------- + a_v es un vector que emmagatzema la informaci¢ de totes les posicions de pantalla +-----------------------------------------------------------------------------------} + +function a_v(posx,posy:byte):char; +var pantalla:array [1..tamany_video] of caracter absolute $B800:0000; + c:char; +begin + c:=pantalla[posy*marge_dreta+posx].car; + a_v:=c; +end; + +procedure paleta; +begin + for i:=0 to 128 do + begin + moure(pepe,i,i mod 80,i mod 25); + GotoXY((i mod 80)+1,i mod 25);TextColor(7);Write(i); + end; + repeat until qteclapuls; +end; + +procedure una_menos(var i,j:byte); +var z:integer; +begin + z:=10000; + while z>1000 do begin sound(z);delay(1);z:=z-250;end; + vides:=vides-1; + nosound; + delay(2000); + i:=64; + j:=11; +end; + +procedure dibuixa_vides; +var y:byte; +begin + for y:=1 to vides do begin + escriu(' ',78-y,1,0,14); + end; +end; + +procedure musica_malos; +var i,j:byte; +begin + for i:=0 to 5 do + for j:=0 to 40 do begin delay(1);sound(j*200);end; + nosound; +end; + +procedure omplir_pot; +var i:byte; +begin + for i:=0 to 90-pot do begin + gotoXY(76,15);TextColor(7); + write(pot:2); + if sonido then sound(i*10); + pot:=pot+1; + delay(25); + end; + nosound; +end; + +procedure neteja_pantalla(color:byte); +var i:byte; +begin + for i:=1 to 80 do begin + for j:=0 to 24 do begin + moure('Û',color,i,j); + delay(1); + end; + end; +end; + +procedure beta_version; +var i:byte; +begin + Clrscr; + escriu('-AVÖS-',35,7,0,15); + Gotoxy(18,10);TextColor(15);write('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'); + Gotoxy(18,11);TextColor(15);write('º Aquest joc encara no est… acabat, ‚s una º'); + Gotoxy(18,12);TextColor(15);write('º versi¢ preliminar, amb la qual cosa el º'); + Gotoxy(18,13);TextColor(15);write('º resultat final del joc pot variar respecteº'); + Gotoxy(18,14);TextColor(15);write('º del que ara vas a jugar. Gracies º'); + Gotoxy(18,15);TextColor(15);write('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ'); + delay(800); + for i:=24 downto 16 do begin + escriu('-Pulsa una tecla per a continuar-',22,i,0,15); + delay(50); + escriu(' ',22,i,0,15); + end; + escriu('-Pulsa una tecla per a continuar-',22,16,0,15); + repeat until qteclapuls; + GotoXY(1,1); +end; +{---------------------------------------------------------------------------------- + Funci¢ per a menejar als malos +-----------------------------------------------------------------------------------} + +function moure_malos(var malos:malo;x,y:byte;n:word):integer; +var i,j,k:byte;meneja:byte;aux:integer; +begin + aux:=0; {aux es la proximitat dels malos respecte al bo + 0=fora del radar, 1=dins del radar, 2=xoc} + randomize; + for i:=1 to 1 do begin + if malos[n].viu=TRUE then begin {Si el malo 'i' encara est… viu aleshores + es menejara segons la seua posici¢} + + case random(2) of { -----------------------------------} + 0:if x-malos[n].x>0 then meneja:=1 { Funci¢ aleatoria que fa } + else if x-malos[n].x<0 then meneja:=0 { que el malo es moga cap } + { else meneja:=4}; { al bo en l'eix de les x } + 1:if y-malos[n].y>0 then meneja:=3 { o en l'eix de les y o en } + else if y-malos[n].y<0 then meneja:=2 { qualsevol de les quatre } +{ else meneja:=4}; { direccions posibles del } + end; {------------------------------------} + case meneja of + + {----------------------------------} + { Moure el malo cap a l'esquerra } + {----------------------------------} + + 0:if (malos[n].x>marge_esq) + and(not(a_v(malos[n].x-1,malos[n].y)=pared)) + and(not(a_v(malos[n].x-1,malos[n].y)=bicho)) + and(a_v(malos[n].x-1,malos[n].y)=bg)then begin + el_que_hi_havia_malo:=a_v(malos[n].x-1,malos[n].y); + moure(el_que_hi_havia_malo,color_pintura,malos[n].x,malos[n].y); + malos[n].x:=malos[n].x-1; + if a_v(malos[n].x-1,malos[n].y)=pepe then + begin moure(bicho,color_bicho,malos[n].x-1,malos[n].y); + moure(bg,color_pintura,malos[n].x-1,malos[n].y); + aux:=2; + end; + moure(bicho,color_bicho,malos[n].x,malos[n].y); + end; + + {--------------------------------} + { Moure el malo cap a la dreta } + {--------------------------------} + + 1:if (malos[n].xmarge_dalt) + and(not(a_v(malos[n].x,malos[n].y-1)=pared)) + and(not(a_v(malos[n].x,malos[n].y-1)=bicho)) + and(a_v(malos[n].x,malos[n].y-1)=bg) then begin + el_que_hi_havia_malo:=a_v(malos[n].x,malos[n].y-1); + moure(el_que_hi_havia_malo,color_pintura,malos[n].x,malos[n].y); + malos[n].y:=malos[n].y-1; + if a_v(malos[n].x,malos[n].y-1)=pepe then + begin moure(bicho,color_bicho,malos[n].x,malos[n].y-1); + moure(bg,color_pintura,malos[n].x,malos[n].y-1); + aux:=2; + end; + moure(bicho,color_bicho,malos[n].x,malos[n].y); + end; + + {----------------------------} + { Moure el malo cap a baix } + {----------------------------} + + 3:if (malos[n].ymarge_dalt)and(not(a_v(i,j-1)=pared)) then begin + begin + if pot>0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + + if (a_v(i,j-1)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i,j-1)); + if (not(a_v(i,j-1)=bg)) then + begin + j:=j-1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=0; + end + else begin + j:=j-1; + direccio:=0; + end; + end; + end; + + end else + if TeclaPuls($1E){tecla A} then begin + + {moure pepe cap a baix} + moviment:=true; + if sonido then sound(nota);delay(40);nosound; + if (j0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + + if (a_v(i,j+1)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i,j+1)); + if (not(a_v(i,j+1)=bg)) then + begin + j:=j+1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=2; + end + else begin + j:=j+1; + direccio:=2; + end; + end; + end; + + end else + if TeclaPuls($18){tecla O} then begin + + {moure pepe cap a l'esquerra} + moviment:=true; + + if sonido then sound(nota);delay(40);nosound; + if (i>marge_esq)and(not(a_v(i-1,j)=pared))then begin + begin + if pot>0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + if (a_v(i-1,j)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i-1,j)); + if (not(a_v(i-1,j)=bg)) then + begin + i:=i-1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=3; + end + else begin + i:=i-1; + direccio:=3; + end; + end; + end; + + end else + if TeclaPuls($19){tecla P} then begin + + {moure pepe cap a la dreta} + moviment:=true; + + if sonido then sound(nota);delay(40);nosound; + if (i0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + if (a_v(i+1,j)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i+1,j)); + if (not(a_v(i+1,j)=bg)) then + begin + i:=i+1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=1; + end + else begin + i:=i+1; + direccio:=1; + end; + end; + end; + + end; + +{ if TeclaPuls($17)tecla I then begin } + + {truco d'invulnerabilitat} + +{ if on=true then begin + truco:=true; + GotoXY(69,2); + TextColor(15); + TextBackground(4); + write('INVULNERABLE'); + on:=false; + end else begin + truco:=false; + GotoXY(69,2); + TextColor(1); + TextBackground(0); + write('INVULNERABLE'); + on:=true; + end; + end;} + + {terminaci¢ del programa} + if TeclaPuls($1F){tecla S} then begin + sonido:=not(sonido); + if sonido then escriu('ON ',72,5,0,7) + else escriu('OFF',72,5,0,7); + end; + + if TeclaPuls($01){tecla T} then ix:=True; + {-----------------------} + + if moviment then begin + if pot>0 then begin + moure(pepe,110,i,j); + nota:=5000; + end + else begin + if el_que_hi_havia=bg then begin + moure(pepe,111,i,j); + nota:=1000 + end + else begin + moure(chr(1),15,i,j); + nota:=1000; + end; + end; + end; + delay(velocitat_joc); + dibuixa_vides; + { restant:=(trunc(total_blocs*100)/1315); + GotoXY(70,3);Textcolor(7);write(restant:3,'%');} + until (ix) or (total_blocs=0) or (vides=0); + nosound; + if total_blocs=0 then escriu('ENHORABONA!',30,11,2,0) + else escriu('ADEU',28,11,0,7); + delay(2000); + neteja_pantalla(0); + delay(1000); + mostrar_cursor; + DesinstalarKb; +end. diff --git a/original_turbopascal/PINTOR3.PAS b/original_turbopascal/PINTOR3.PAS new file mode 100644 index 0000000..07f3135 --- /dev/null +++ b/original_turbopascal/PINTOR3.PAS @@ -0,0 +1,740 @@ +program Pepe_el_pintor; +uses dos,crt,keyboard,cursor,grafics; + +{---------------------------------------------------------------------------------- + constants, variables i tipus +-----------------------------------------------------------------------------------} + +const marge_dalt=0; {Fila on comen‡a el marge de dalt} {----------------------} +const marge_baix=24; {Fila on acaba el marge de baix} { Dimensions de } +const marge_dreta=80; {Columna on acaba marge dret} { la pantalla } +const marge_esq=1; {Columna on comen‡a el marge esquerre} {----------------------} +const tamany_video=2000; +const n_malos=3; +const bicho='X'; +const color_bicho=107; +const pepe=''; +const pared='±'; +const bg='Û'; +const color_pintura=6; +const n_malos_max=3; +const velocitat_joc=60; + + +type caracter=RECORD + car:char; + atrib:byte; + END; + + auxmalo=RECORD + x,y:byte; + viu:boolean; + END; + malo=array [1..n_malos] of auxmalo; + + pos=RECORD + a,b:byte; + END; + + llocsbg=array [1..1315] of pos; + +var malos:malo; + llocs_bg:llocsbg; + nfase,color_pepe,i,j,mort,direccio,vides,lloc_x,lloc_y:byte; + pot,nota,total_blocs:integer; + ix,truco,on,sonido,moviment,aparicio:boolean; + el_que_hi_havia,el_que_hi_havia_malo:char; + restant:real; + +{----------------------------------------------------------- + dibuixa la pantalla de joc +------------------------------------------------------------} +procedure fase_1; +begin + GotoXY(1,1); + TextColor(4); + writeln(' ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±±'); + writeln(' ± ±'); + writeln(' ± ±±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ± ±'); + writeln(' ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + TextColor(7);write(' - Beta Version - 1999 Sergi Valor Mart¡nez'); +end; + +procedure fase_3; +begin + GotoXY(1,1); + TextColor(4); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + TextColor(7);write(' - Beta Version - 1999 Sergi Valor Mart¡nez'); +end; + +procedure fase_2; +begin + GotoXY(1,1); + TextColor(4); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±±±±±±±± ±'); + writeln('± ±±±±±±±±±±±± ±'); + writeln('± ±±±±±±±±±±±±±±±± ±±'); + writeln('± ±'); + writeln('± ±±±±±±±±±±±±±±±± ±±'); + writeln('± ±±±±±±±±±±±± ±'); + writeln('± ±±±±±±±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + TextColor(7);write(' - Beta Version - 1999 Sergi Valor Mart¡nez'); +end; + + procedure MCGA; + begin + asm + mov ax,0013h + int 10h + end; + directvideo:= false; + end; + + procedure Text; + begin + asm + mov ax,0003h + int 10h + end; + end; + + +procedure dibuixa_pantalla; + +begin + + escriu('Pintura: 90',65,14,0,7); + escriu('',62,11,6,14); + escriu(chr(30),68,17,0,7); + escriu('Q',68,16,0,7); + escriu('A',68,20,0,7); + escriu(chr(31),68,19,0,7); + escriu('O',65,18,0,7); + escriu('P',71,18,0,7); + escriu(chr(16),70,18,0,7); + escriu(chr(17),66,18,0,7); + escriu('ESC - Eixir',65,3,0,7); + escriu('S - So ON',65,5,0,7); +end; + +{---------------------------------------------------------------------------------- + coloca el caracter 'ch' en la posici¢ de pantalla definida en posx i posy +-----------------------------------------------------------------------------------} + +procedure moure(ch:char;atrib,posx,posy:byte); +var pantalla:array [1..tamany_video] of caracter absolute $B800:0000; +begin + if (posy*marge_dreta+posx<=tamany_video) then begin + pantalla[posy*marge_dreta+posx].car:=ch; + pantalla[posy*marge_dreta+posx].atrib:=atrib; + end; +end; + +{---------------------------------------------------------------------------------- + a_v es un vector que emmagatzema la informaci¢ de totes les posicions de pantalla +-----------------------------------------------------------------------------------} + +function a_v(posx,posy:byte):char; +var pantalla:array [1..tamany_video] of caracter absolute $B800:0000; + c:char; +begin + c:=pantalla[posy*marge_dreta+posx].car; + a_v:=c; +end; + +procedure paleta; +begin + for i:=0 to 128 do + begin + moure(pepe,i,i mod 80,i mod 25); + GotoXY((i mod 80)+1,i mod 25);TextColor(7);Write(i); + end; + repeat until qteclapuls; +end; + +procedure una_menos(var i,j:byte); +var z:integer; +begin + z:=10000; + while z>1000 do begin sound(z);delay(1);z:=z-250;end; + vides:=vides-1; + nosound; + delay(2000); + i:=64; + j:=11; +end; + +procedure dibuixa_vides; +var y:byte; +begin + for y:=1 to vides do begin + escriu(' ',78-y,1,0,14); + end; +end; + +procedure musica_malos; +var i,j:byte; +begin + for i:=0 to 5 do + for j:=0 to 40 do begin delay(1);sound(j*200);end; + nosound; +end; + +procedure omplir_pot; +var i:byte; +begin + for i:=0 to 90-pot do begin + gotoXY(76,15);TextColor(7); + write(pot:2); + if sonido then sound(i*10); + pot:=pot+1; + delay(25); + end; + nosound; +end; + +procedure neteja_pantalla(color:byte); +var i:byte; +begin + for i:=1 to 80 do begin + for j:=0 to 24 do begin + moure('Û',color,i,j); + delay(1); + end; + end; +end; + +procedure beta_version; +var i:byte; +begin + Clrscr; + escriu('-AVÖS-',35,7,0,15); + Gotoxy(18,10);TextColor(15);write('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'); + Gotoxy(18,11);TextColor(15);write('º Aquest joc encara no est… acabat, ‚s una º'); + Gotoxy(18,12);TextColor(15);write('º versi¢ preliminar, amb la qual cosa el º'); + Gotoxy(18,13);TextColor(15);write('º resultat final del joc pot variar respecteº'); + Gotoxy(18,14);TextColor(15);write('º del que ara vas a jugar. Gracies º'); + Gotoxy(18,15);TextColor(15);write('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ'); + delay(800); + for i:=24 downto 16 do begin + escriu('-Pulsa una tecla per a continuar-',22,i,0,15); + delay(50); + escriu(' ',22,i,0,15); + end; + escriu('-Pulsa una tecla per a continuar-',22,16,0,15); + repeat until qteclapuls; + GotoXY(1,1); +end; +{---------------------------------------------------------------------------------- + Funci¢ per a menejar als malos +-----------------------------------------------------------------------------------} + +function moure_malos(var malos:malo;x,y:byte;n:word):integer; +var i,j,k:byte;meneja:byte;aux:integer; +begin + aux:=0; {aux es la proximitat dels malos respecte al bo + 0=fora del radar, 1=dins del radar, 2=xoc} + randomize; + for i:=1 to 1 do begin + if malos[n].viu=TRUE then begin {Si el malo 'i' encara est… viu aleshores + es menejara segons la seua posici¢} + + case random(2) of { -----------------------------------} + 0:if x-malos[n].x>0 then meneja:=1 { Funci¢ aleatoria que fa } + else if x-malos[n].x<0 then meneja:=0 { que el malo es moga cap } + { else meneja:=4}; { al bo en l'eix de les x } + 1:if y-malos[n].y>0 then meneja:=3 { o en l'eix de les y o en } + else if y-malos[n].y<0 then meneja:=2 { qualsevol de les quatre } +{ else meneja:=4}; { direccions posibles del } + end; {------------------------------------} + case meneja of + + {----------------------------------} + { Moure el malo cap a l'esquerra } + {----------------------------------} + + 0:if (malos[n].x>marge_esq) + and(not(a_v(malos[n].x-1,malos[n].y)=pared)) + and(not(a_v(malos[n].x-1,malos[n].y)=bicho)) + and(a_v(malos[n].x-1,malos[n].y)=bg)then begin + el_que_hi_havia_malo:=a_v(malos[n].x-1,malos[n].y); + moure(el_que_hi_havia_malo,color_pintura,malos[n].x,malos[n].y); + malos[n].x:=malos[n].x-1; + if a_v(malos[n].x-1,malos[n].y)=pepe then + begin moure(bicho,color_bicho,malos[n].x-1,malos[n].y); + moure(bg,color_pintura,malos[n].x-1,malos[n].y); + aux:=2; + end; + moure(bicho,color_bicho,malos[n].x,malos[n].y); + end; + + {--------------------------------} + { Moure el malo cap a la dreta } + {--------------------------------} + + 1:if (malos[n].xmarge_dalt) + and(not(a_v(malos[n].x,malos[n].y-1)=pared)) + and(not(a_v(malos[n].x,malos[n].y-1)=bicho)) + and(a_v(malos[n].x,malos[n].y-1)=bg) then begin + el_que_hi_havia_malo:=a_v(malos[n].x,malos[n].y-1); + moure(el_que_hi_havia_malo,color_pintura,malos[n].x,malos[n].y); + malos[n].y:=malos[n].y-1; + if a_v(malos[n].x,malos[n].y-1)=pepe then + begin moure(bicho,color_bicho,malos[n].x,malos[n].y-1); + moure(bg,color_pintura,malos[n].x,malos[n].y-1); + aux:=2; + end; + moure(bicho,color_bicho,malos[n].x,malos[n].y); + end; + + {----------------------------} + { Moure el malo cap a baix } + {----------------------------} + + 3:if (malos[n].ymarge_dalt)and(not(a_v(i,j-1)=pared)) then begin + begin + if pot>0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + + if (a_v(i,j-1)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i,j-1)); + if (not(a_v(i,j-1)=bg)) then + begin + j:=j-1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=0; + end + else begin + j:=j-1; + direccio:=0; + end; + end; + end; + + end else + if TeclaPuls($1E){tecla A} then begin + + {moure pepe cap a baix} + moviment:=true; + if sonido then sound(nota);delay(40);nosound; + if (j0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + + if (a_v(i,j+1)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i,j+1)); + if (not(a_v(i,j+1)=bg)) then + begin + j:=j+1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=2; + end + else begin + j:=j+1; + direccio:=2; + end; + end; + end; + + end else + if TeclaPuls($18){tecla O} then begin + + {moure pepe cap a l'esquerra} + moviment:=true; + + if sonido then sound(nota);delay(40);nosound; + if (i>marge_esq)and(not(a_v(i-1,j)=pared))then begin + begin + if pot>0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + if (a_v(i-1,j)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i-1,j)); + if (not(a_v(i-1,j)=bg)) then + begin + i:=i-1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=3; + end + else begin + i:=i-1; + direccio:=3; + end; + end; + end; + + end else + if TeclaPuls($19){tecla P} then begin + + {moure pepe cap a la dreta} + moviment:=true; + + if sonido then sound(nota);delay(40);nosound; + if (i0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + if (a_v(i+1,j)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i+1,j)); + if (not(a_v(i+1,j)=bg)) then + begin + i:=i+1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=1; + end + else begin + i:=i+1; + direccio:=1; + end; + end; + end; + + end; + +{ if TeclaPuls($17)tecla I then begin } + + {truco d'invulnerabilitat} + +{ if on=true then begin + truco:=true; + GotoXY(69,2); + TextColor(15); + TextBackground(4); + write('INVULNERABLE'); + on:=false; + end else begin + truco:=false; + GotoXY(69,2); + TextColor(1); + TextBackground(0); + write('INVULNERABLE'); + on:=true; + end; + end;} + + {terminaci¢ del programa} + if TeclaPuls($1F){tecla S} then begin + sonido:=not(sonido); + if sonido then escriu('ON ',72,5,0,7) + else escriu('OFF',72,5,0,7); + end; + + if TeclaPuls($01){tecla T} then ix:=True; + {-----------------------} + + if moviment then begin + if pot>0 then begin + moure(pepe,110,i,j); + nota:=5000; + end + else begin + if el_que_hi_havia=bg then begin + moure(pepe,111,i,j); + nota:=1000 + end + else begin + moure(chr(1),15,i,j); + nota:=1000; + end; + end; + end; + delay(velocitat_joc); + dibuixa_vides; + { restant:=(trunc(total_blocs*100)/1315); + GotoXY(70,3);Textcolor(7);write(restant:3,'%');} + GotoXY(70,3);Textcolor(7);write(total_blocs:4); + until (ix) or (total_blocs=0) or (vides=0); + nosound; + if total_blocs=0 then begin + escriu('ENHORABONA!',30,11,2,0); + delay(5000); + vides:=5; + nfase:=nfase+1; + end; + until (ix) or (vides=0); + escriu('ADEU',28,11,0,7); + text; + delay(2000); + neteja_pantalla(0); + delay(1000); + mostrar_cursor; + DesinstalarKb; +end. diff --git a/original_turbopascal/PINTORCG.PAS b/original_turbopascal/PINTORCG.PAS new file mode 100644 index 0000000..4f4b76b --- /dev/null +++ b/original_turbopascal/PINTORCG.PAS @@ -0,0 +1,759 @@ +program Pepe_el_pintor; +uses dos,crt,keyboard,cursor,grafics; + +{---------------------------------------------------------------------------------- + constants, variables i tipus +-----------------------------------------------------------------------------------} + +const marge_dalt=0; {Fila on comen‡a el marge de dalt} {----------------------} +const marge_baix=24; {Fila on acaba el marge de baix} { Dimensions de } +const marge_dreta=80; {Columna on acaba marge dret} { la pantalla } +const marge_esq=1; {Columna on comen‡a el marge esquerre} {----------------------} +const tamany_video=2000; +const n_malos=3; +const bicho='X'; +const color_bicho=107; +const pepe=''; +const pared='±'; +const bg='Û'; +const color_pintura=6; +const n_malos_max=3; +const velocitat_joc=60; +const ini_pepe_x=26; +const ini_pepe_y=12; + +type caracter=RECORD + car:char; + atrib:byte; + END; + + auxmalo=RECORD + x,y:byte; + viu:boolean; + END; + malo=array [1..n_malos] of auxmalo; + + pos=RECORD + a,b:byte; + END; + + llocsbg=array [1..1315] of pos; + +var malos:malo; + llocs_bg:llocsbg; + nfase,color_pepe,i,j,mort,direccio,vides,lloc_x,lloc_y:byte; + pot,nota,total_blocs:integer; + ix,truco,on,sonido,moviment,aparicio:boolean; + el_que_hi_havia,el_que_hi_havia_malo:char; + restant:real; + +{----------------------------------------------------------- + dibuixa la pantalla de joc +------------------------------------------------------------} + +procedure escriu(text:string;x,y:byte;bk,tx:byte); + +begin + Gotoxy(x,y);Textcolor(tx);Textbackground(bk); + write(text); + +end; + +procedure moure(text:string;tx,x,y:byte); + +begin + Gotoxy(x,y);Textcolor(tx); + write(text); + +end; + +procedure fase_1; +begin + GotoXY(1,1); + TextColor(4); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±'); + TextColor(7);write('- Beta Version - 1999 Sergi Valor'); +end; + +procedure fase_3; +begin + GotoXY(1,1); + TextColor(4); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('± ±'); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + TextColor(7);write(' - Beta Version - 1999 Sergi Valor Mart¡nez'); +end; + +procedure fase_2; +begin + GotoXY(1,1); + TextColor(4); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±±±±±±±± ±'); + writeln('± ±±±±±±±±±±±± ±'); + writeln('± ±±±±±±±±±±±±±±±± ±±'); + writeln('± ±'); + writeln('± ±±±±±±±±±±±±±±±± ±±'); + writeln('± ±±±±±±±±±±±± ±'); + writeln('± ±±±±±±±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('± ±'); + writeln('± ±± ±'); + writeln('± ±± ±'); + writeln('±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±'); + TextColor(7);write(' - Beta Version - 1999 Sergi Valor Mart¡nez'); +end; + + procedure MCGA; + begin + asm + mov ax,0013h + int 10h + end; + directvideo:= false; + end; + + procedure Text; + begin + asm + mov ax,0003h + int 10h + end; + end; + + +procedure dibuixa_pantalla; + +begin + + escriu('Pintura: 90',65,14,0,7); + escriu('',40,11,6,14); + escriu(chr(30),68,17,0,7); + escriu('Q',68,16,0,7); + escriu('A',68,20,0,7); + escriu(chr(31),68,19,0,7); + escriu('O',65,18,0,7); + escriu('P',71,18,0,7); + escriu(chr(16),70,18,0,7); + escriu(chr(17),66,18,0,7); + escriu('ESC - Eixir',65,3,0,7); + escriu('S - So ON',65,5,0,7); +end; + +{---------------------------------------------------------------------------------- + coloca el caracter 'ch' en la posici¢ de pantalla definida en posx i posy +-----------------------------------------------------------------------------------} + +procedure moure_x(ch:char;atrib,posx,posy:byte); +var pantalla:array [1..tamany_video] of caracter absolute $B800:0000; +begin + if (posy*marge_dreta+posx<=tamany_video) then begin + pantalla[posy*marge_dreta+posx].car:=ch; + pantalla[posy*marge_dreta+posx].atrib:=atrib; + end; +end; + +{---------------------------------------------------------------------------------- + a_v es un vector que emmagatzema la informaci¢ de totes les posicions de pantalla +-----------------------------------------------------------------------------------} + +function a_v(posx,posy:byte):char; +var pantalla:array [1..tamany_video] of caracter absolute $A000:0000; + c:char; +begin + c:=pantalla[posy*marge_dreta*8+posx*8].car; + a_v:=c; +end; + +procedure paleta; +begin + for i:=0 to 128 do + begin + moure(pepe,i,i mod 80,i mod 25); + GotoXY((i mod 80)+1,i mod 25);TextColor(7);Write(i); + end; + repeat until qteclapuls; +end; + +procedure una_menos(var i,j:byte); +var z:integer; +begin + z:=10000; + while z>1000 do begin sound(z);delay(1);z:=z-250;end; + vides:=vides-1; + nosound; + delay(2000); + i:=ini_pepe_x; + j:=ini_pepe_y; +end; + +procedure dibuixa_vides; +var y:byte; +begin + for y:=1 to vides do begin + escriu(' ',78-y,1,0,14); + end; +end; + +procedure musica_malos; +var i,j:byte; +begin + for i:=0 to 5 do + for j:=0 to 40 do begin delay(1);sound(j*200);end; + nosound; +end; + +procedure omplir_pot; +var i:byte; +begin + for i:=0 to 90-pot do begin + gotoXY(76,15);TextColor(7); + write(pot:2); + if sonido then sound(i*10); + pot:=pot+1; + delay(25); + end; + nosound; +end; + +procedure neteja_pantalla(color:byte); +var i:byte; +begin + for i:=1 to 80 do begin + for j:=0 to 24 do begin + moure('Û',color,i,j); + delay(1); + end; + end; +end; + +procedure beta_version; +var i:byte; +begin + Clrscr; + escriu('-AVÖS-',35,7,0,15); + Gotoxy(18,10);TextColor(15);write('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'); + Gotoxy(18,11);TextColor(15);write('º Aquest joc encara no est… acabat, ‚s una º'); + Gotoxy(18,12);TextColor(15);write('º versi¢ preliminar, amb la qual cosa el º'); + Gotoxy(18,13);TextColor(15);write('º resultat final del joc pot variar respecteº'); + Gotoxy(18,14);TextColor(15);write('º del que ara vas a jugar. Gracies º'); + Gotoxy(18,15);TextColor(15);write('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ'); + delay(800); + for i:=24 downto 16 do begin + escriu('-Pulsa una tecla per a continuar-',22,i,0,15); + delay(50); + escriu(' ',22,i,0,15); + end; + escriu('-Pulsa una tecla per a continuar-',22,16,0,15); + repeat until qteclapuls; + GotoXY(1,1); +end; +{---------------------------------------------------------------------------------- + Funci¢ per a menejar als malos +-----------------------------------------------------------------------------------} + +function moure_malos(var malos:malo;x,y:byte;n:word):integer; +var i,j,k:byte;meneja:byte;aux:integer; +begin + aux:=0; {aux es la proximitat dels malos respecte al bo + 0=fora del radar, 1=dins del radar, 2=xoc} + randomize; + for i:=1 to 1 do begin + if malos[n].viu=TRUE then begin {Si el malo 'i' encara est… viu aleshores + es menejara segons la seua posici¢} + + case random(2) of { -----------------------------------} + 0:if x-malos[n].x>0 then meneja:=1 { Funci¢ aleatoria que fa } + else if x-malos[n].x<0 then meneja:=0 { que el malo es moga cap } + { else meneja:=4}; { al bo en l'eix de les x } + 1:if y-malos[n].y>0 then meneja:=3 { o en l'eix de les y o en } + else if y-malos[n].y<0 then meneja:=2 { qualsevol de les quatre } +{ else meneja:=4}; { direccions posibles del } + end; {------------------------------------} + case meneja of + + {----------------------------------} + { Moure el malo cap a l'esquerra } + {----------------------------------} + + 0:if (malos[n].x>marge_esq) + and(not(a_v(malos[n].x-1,malos[n].y)=pared)) + and(not(a_v(malos[n].x-1,malos[n].y)=bicho)) + and(a_v(malos[n].x-1,malos[n].y)=bg)then begin + el_que_hi_havia_malo:=a_v(malos[n].x-1,malos[n].y); + moure(el_que_hi_havia_malo,color_pintura,malos[n].x,malos[n].y); + malos[n].x:=malos[n].x-1; + if a_v(malos[n].x-1,malos[n].y)=pepe then + begin moure(bicho,color_bicho,malos[n].x-1,malos[n].y); + moure(bg,color_pintura,malos[n].x-1,malos[n].y); + aux:=2; + end; + moure(bicho,color_bicho,malos[n].x,malos[n].y); + end; + + {--------------------------------} + { Moure el malo cap a la dreta } + {--------------------------------} + + 1:if (malos[n].xmarge_dalt) + and(not(a_v(malos[n].x,malos[n].y-1)=pared)) + and(not(a_v(malos[n].x,malos[n].y-1)=bicho)) + and(a_v(malos[n].x,malos[n].y-1)=bg) then begin + el_que_hi_havia_malo:=a_v(malos[n].x,malos[n].y-1); + moure(el_que_hi_havia_malo,color_pintura,malos[n].x,malos[n].y); + malos[n].y:=malos[n].y-1; + if a_v(malos[n].x,malos[n].y-1)=pepe then + begin moure(bicho,color_bicho,malos[n].x,malos[n].y-1); + moure(bg,color_pintura,malos[n].x,malos[n].y-1); + aux:=2; + end; + moure(bicho,color_bicho,malos[n].x,malos[n].y); + end; + + {----------------------------} + { Moure el malo cap a baix } + {----------------------------} + + 3:if (malos[n].ymarge_dalt)and(not(a_v(i,j-1)=pared)) then begin + begin + if pot>0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + + if (a_v(i,j-1)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i,j-1)); + if (not(a_v(i,j-1)=bg)) then + begin + j:=j-1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=0; + end + else begin + j:=j-1; + direccio:=0; + end; + end; + end; + + end else + if TeclaPuls($1E){tecla A} then begin + + {moure pepe cap a baix} + moviment:=true; + if sonido then sound(nota);delay(40);nosound; + if (j0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + + if (a_v(i,j+1)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i,j+1)); + if (not(a_v(i,j+1)=bg)) then + begin + j:=j+1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=2; + end + else begin + j:=j+1; + direccio:=2; + end; + end; + end; + + end else + if TeclaPuls($18){tecla O} then begin + + {moure pepe cap a l'esquerra} + moviment:=true; + + if sonido then sound(nota);delay(40);nosound; + if (i>marge_esq)and(not(a_v(i-1,j)=pared))then begin + begin + if pot>0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + if (a_v(i-1,j)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i-1,j)); + if (not(a_v(i-1,j)=bg)) then + begin + i:=i-1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=3; + end + else begin + i:=i-1; + direccio:=3; + end; + end; + end; + + end else + if TeclaPuls($19){tecla P} then begin + + {moure pepe cap a la dreta} + moviment:=true; + + if sonido then sound(nota);delay(40);nosound; + if (i0 then begin + moure(bg,color_pintura,i,j); + + end + else begin + moure(el_que_hi_havia,color_pintura,i,j); + end; + end; + + if (a_v(i+1,j)=bicho)and(truco=false) then begin + una_menos(i,j); + {GotoXY(28,2); + TextColor(15); + TextBackground(4); + write('MORT'); + break;} + end else begin + el_que_hi_havia:=(a_v(i+1,j)); + if (not(a_v(i+1,j)=bg)) then + begin + i:=i+1; + if pot=0 then pot:=0 else begin + pot:=pot-1; + total_blocs:=total_blocs-1; + GotoXY(76,15);TextColor(7);write(pot:2); + end; + direccio:=1; + end + else begin + i:=i+1; + direccio:=1; + end; + end; + end; + + end; + +{ if TeclaPuls($17)tecla I then begin } + + {truco d'invulnerabilitat} + +{ if on=true then begin + truco:=true; + GotoXY(69,2); + TextColor(15); + TextBackground(4); + write('INVULNERABLE'); + on:=false; + end else begin + truco:=false; + GotoXY(69,2); + TextColor(1); + TextBackground(0); + write('INVULNERABLE'); + on:=true; + end; + end;} + + {terminaci¢ del programa} + if TeclaPuls($1F){tecla S} then begin + sonido:=not(sonido); + if sonido then escriu('ON ',72,5,0,7) + else escriu('OFF',72,5,0,7); + end; + + if TeclaPuls($01){tecla T} then ix:=True; + {-----------------------} + + if moviment then begin + if pot>0 then begin + moure(pepe,110,i,j); + nota:=5000; + end + else begin + if el_que_hi_havia=bg then begin + moure(pepe,111,i,j); + nota:=1000 + end + else begin + moure(chr(1),15,i,j); + nota:=1000; + end; + end; + end; + delay(velocitat_joc); + dibuixa_vides; + { restant:=(trunc(total_blocs*100)/1315); + GotoXY(70,3);Textcolor(7);write(restant:3,'%');} + GotoXY(70,3);Textcolor(7);write(total_blocs:4); + until (ix) or (total_blocs=0) or (vides=0); + nosound; + if total_blocs=0 then begin + escriu('ENHORABONA!',30,11,2,0); + delay(5000); + vides:=5; + nfase:=nfase+1; + end; + until (ix) or (vides=0); + escriu('ADEU',28,11,0,7); + text; + delay(2000); + neteja_pantalla(0); + delay(1000); + mostrar_cursor; + DesinstalarKb; +end. diff --git a/pepe_pintor.lua b/pepe_pintor.lua new file mode 100644 index 0000000..66eae90 --- /dev/null +++ b/pepe_pintor.lua @@ -0,0 +1,243 @@ +-- Pepe el Pintor — port a ascii/Lua del joc original en Turbo Pascal +-- (Sergi Valor Martínez, 1999). Base: PINTOR3.PAS. +-- +-- ITER 1: motor mínim — fase única (la 3 = rectangle gran), Pepe es mou amb +-- O P Q A, pinta el fons al pas, gasta el pot de pintura i el recarrega al +-- tornar a la posició inicial. Sense enemics, vides ni transicions. + +-- ==================================================================== +-- CONSTANTS +-- ==================================================================== +MAP_W, MAP_H = 40, 25 +HUD_Y0 = 25 -- HUD ocupa files 25..29 + +-- Glifs (codis CP437 originals). Els redefinim amb setchar per a fidelitat. +PEPE_PLE = 2 -- ☻ Pepe amb pintura (cara plena) +PEPE_BUIT = 1 -- ☺ Pepe sense pintura (cara buida) +PARED = 0xB1 -- â–’ paret +FONS = 0xDB -- â–ˆ fons (sense pintar i pintat, distingit per atribut) +POT_GLIF = 232 -- â—˜ marca visual del pot + +-- Constants del joc +POT_MAX = 90 +PEPE_INI_X = 37 -- cambra del pot, 1 cel·la sortint del marc a la dreta (fidel al PINTOR3) +PEPE_INI_Y = 11 +TICS_MOVIMENT = 5 -- frames entre intents de moviment (60/5 = 12 Hz) +TICS_OMPLIR = 3 -- frames entre +1 de pot al recarregar + +-- ==================================================================== +-- ESTAT +-- ==================================================================== +mapa = {} -- mapa[x][y] = { tipo=, pintat=bool } +pepe = { x=PEPE_INI_X, y=PEPE_INI_Y, pinta=true } +pot = POT_MAX +total_blocs = 0 -- es calcula al carregar mapa +omplint = false -- en mig d'una recàrrega? +omplir_i = 0 -- comptador del bucle de recàrrega (fidel al Pascal) +omplir_max = 0 -- valor de (90-pot) en el moment d'entrar al pot + +-- Buffer d'edges d'input direccional. +-- update() corre a 60 fps però la lògica del Pepe avança cada TICS_MOVIMENT +-- frames. Si l'usuari fa un tap curt entre dos tics, btn() al moment del tic +-- ja no detecta la pulsació. Bufferitzem només l'edge (btnp), així un tap +-- ràpid sempre genera UN moviment. El moviment "mantingut" segueix funcionant +-- per btn() directe al tic. Buffer binari: si poses 3 taps en un tic, només +-- compta com 1 — no se sobren moviments al pròxim tic. +input_buf = { up=false, down=false, left=false, right=false } + +function sample_input() + if btnp(KEY_Q) then input_buf.up = true end + if btnp(KEY_A) then input_buf.down = true end + if btnp(KEY_O) then input_buf.left = true end + if btnp(KEY_P) then input_buf.right = true end +end + +function reset_input() + input_buf.up, input_buf.down, input_buf.left, input_buf.right = false, false, false, false +end + +-- ==================================================================== +-- GLIFS CUSTOM (bitmaps CP437) +-- ==================================================================== +function definir_glifs() + -- Pepe ple (CP437 chr 2 — smiley relleno) + setchar(PEPE_PLE, 0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E) + -- Pepe buit (CP437 chr 1 — smiley contorn) + setchar(PEPE_BUIT, 0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E) + -- Paret â–’ (CP437 chr 177 — half-tone gris) + setchar(PARED, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11) + -- Fons â–ˆ ple + setchar(FONS, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF) + -- Pot de pintura: un trapezoide amb pintura dins (sprite propi) + setchar(POT_GLIF, 0x00, 0x7E, 0x7E, 0x42, 0x66, 0x7E, 0x3C, 0x00) +end + +-- ==================================================================== +-- MAPA +-- ==================================================================== +function tipo_a(x, y) + if x < 0 or x >= MAP_W or y < 0 or y >= MAP_H then return PARED end + return mapa[x][y].tipo +end + +function carregar_mapa(num) + filein("maps/"..tostr(num)..".map", 0, MAP_W*MAP_H) + total_blocs = 0 + for x = 0, MAP_W-1 do + mapa[x] = {} + for y = 0, MAP_H-1 do + local b = peek(x*MAP_H + y) + mapa[x][y] = { tipo=b, pintat=false } + if b == FONS then total_blocs = total_blocs + 1 end + end + end + -- La cel·la del pot no es pinta: la marquem com "ja pintada" i la traiem + -- del compte, així `total_blocs == 0` és assolible com a condició de victòria. + mapa[PEPE_INI_X][PEPE_INI_Y].pintat = true + total_blocs = total_blocs - 1 +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 == PARED then + color(COLOR_RED, COLOR_BLACK) + print(chr(PARED), x, y) + elseif c.tipo == FONS and c.pintat then + color(COLOR_BROWN, COLOR_BLACK) + print(chr(FONS), x, y) + end + -- FONS no pintat: deixem la cel·la negra (cls); no es dibuixa res + end + end +end + +function pintar_pot() + -- Dibuixem la marca visual del pot només si Pepe NO hi és damunt + if not (pepe.x == PEPE_INI_X and pepe.y == PEPE_INI_Y) then + color(COLOR_YELLOW, COLOR_BROWN) + print(chr(POT_GLIF), PEPE_INI_X, PEPE_INI_Y) + end +end + +function pintar_pepe() + local glif = pepe.pinta and PEPE_PLE or PEPE_BUIT + local fons_color + if mapa[pepe.x][pepe.y].pintat then + fons_color = COLOR_BROWN + else + fons_color = COLOR_BLACK + end + color(COLOR_YELLOW, fons_color) + print(chr(glif), pepe.x, pepe.y) +end + +function pintar_hud() + color(COLOR_LIGHT_GRAY, COLOR_BLUE) + local blank = " " + for i = HUD_Y0, 29 do print(blank, 0, i) end + + color(COLOR_WHITE, COLOR_BLUE) + print("PINTURA "..string.format("%02d", pot).."/"..tostr(POT_MAX), 1, 26) + color(COLOR_YELLOW, COLOR_BLUE) + print("BLOCS "..string.format("%04d", total_blocs), 22, 26) + + color(COLOR_LIGHT_CYAN, COLOR_BLUE) + print("O P Q A: moure", 1, 28) +end + +-- ==================================================================== +-- LÃ’GICA DEL JOC +-- ==================================================================== + +-- Intent de moviment en (dx, dy). Si la cel·la destí és paret, no es mou. +-- Si és fons no pintat i hi ha pintura, la pinta i descompta del pot. +function intent_moviment(dx, dy) + local nx, ny = pepe.x + dx, pepe.y + dy + local t = tipo_a(nx, ny) + if t == PARED then return end + if t ~= FONS then return end + + pepe.x, pepe.y = nx, ny + local c = mapa[nx][ny] + + -- La cel·la del pot no es pinta mai (es queda neta per a la recàrrega) + if nx == PEPE_INI_X and ny == PEPE_INI_Y then + sound(2000, 4) + return + end + + if not c.pintat then + if pot > 0 then + c.pintat = true + pot = pot - 1 + total_blocs = total_blocs - 1 + sound(5000, 3) + pepe.pinta = (pot > 0) + else + sound(800, 3) + end + end +end + +function tic_pepe() + if omplint then return end -- bloquejat durant l'animació de recàrrega + -- Cada direcció: edge bufferitzat (tap curt) OR tecla mantinguda al moment del tic. + if input_buf.up or btn(KEY_Q) then intent_moviment( 0, -1) + elseif input_buf.down or btn(KEY_A) then intent_moviment( 0, 1) + elseif input_buf.left or btn(KEY_O) then intent_moviment(-1, 0) + elseif input_buf.right or btn(KEY_P) then intent_moviment( 1, 0) + end + + -- Arribar al pot dispara la recàrrega + if pepe.x == PEPE_INI_X and pepe.y == PEPE_INI_Y and pot < POT_MAX then + omplint = true + omplir_i = 0 + omplir_max = POT_MAX - pot -- (90 - pot) en el moment d'entrar + end +end + +-- Fidel al Pascal original: `for i:=0 to 90-pot do sound(i*10); pot:=pot+1;` +-- El so depèn del comptador del bucle (sempre arranca a 0 Hz), no del nivell del pot. +function tic_omplir() + if not omplint then return end + sound(omplir_i * 10, 2) + pot = pot + 1 + omplir_i = omplir_i + 1 + if omplir_i > omplir_max then + if pot > POT_MAX then pot = POT_MAX end + omplint = false + nosound() + end + pepe.pinta = true +end + +-- ==================================================================== +-- BUCLE PRINCIPAL +-- ==================================================================== +function init() + mode(1) + border(COLOR_BLUE) + definir_glifs() + carregar_mapa(3) + cls() +end + +function update() + -- Sample d'edges d'input cada frame (mentre el joc està actiu i no en recàrrega) + if not omplint then sample_input() end + + if omplint and (cnt() % TICS_OMPLIR) == 0 then tic_omplir() end + + if not omplint and (cnt() % TICS_MOVIMENT) == 0 then + tic_pepe() + reset_input() -- descartem edges acumulats després de processar el tic + end + + cls() + pintar_mapa() + pintar_pot() + pintar_pepe() + pintar_hud() +end