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.