552 lines
22 KiB
ObjectPascal
552 lines
22 KiB
ObjectPascal
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].x<marge_dreta)
|
||
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 dalt }
|
||
{----------------------------}
|
||
|
||
2:if (malos[i].y>marge_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].y<marge_baix)
|
||
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;
|
||
|
||
4:if a_v(malos[i].x,malos[i].y)=pepe then
|
||
begin aux:=2; break; end;
|
||
end;
|
||
end;
|
||
end;
|
||
moure_malos:=aux;
|
||
end;
|
||
|
||
{----------------------------------------------------------------------------------
|
||
Programa principal
|
||
-----------------------------------------------------------------------------------}
|
||
begin
|
||
InstalarKb;
|
||
amagar_cursor;
|
||
Clrscr;
|
||
repeat until teclapuls($02) or teclapuls($03);
|
||
if teclapuls($02) then begin
|
||
delay(100);
|
||
paleta;
|
||
end;
|
||
neteja_pantalla(0);
|
||
dibuixa_pantalla;
|
||
randomize;
|
||
|
||
|
||
|
||
malos[1].x:=63;
|
||
malos[1].y:=11;
|
||
malos[1].viu:=TRUE;
|
||
|
||
malos[2].x:=63;
|
||
malos[2].y:=11;
|
||
malos[2].viu:=TRUE;
|
||
|
||
|
||
|
||
sonido:=true;
|
||
moviment:=false;
|
||
total_blocs:=1302;
|
||
i:=64; {Posici¢ de columna inicial de pepe}
|
||
j:=11; {Posici¢ de fila inicial de pepe}
|
||
ix:=False;
|
||
pot:=90;
|
||
|
||
repeat
|
||
if (i=64) and (j=11) and (pot<90) then omplir_pot;
|
||
if total_blocs<1100 then mort:=moure_malos(malos,i,j);
|
||
{mort}
|
||
|
||
if mort=2 then begin
|
||
GotoXY(28,2);
|
||
TextColor(15);
|
||
TextBackground(4);
|
||
write('MORT');
|
||
nosound;
|
||
delay(2000);
|
||
break;
|
||
DesinstalarKb;
|
||
end;
|
||
|
||
{----------------------------------------------------------------------------------
|
||
Detecci¢ de tecles en el joc
|
||
-----------------------------------------------------------------------------------}
|
||
|
||
if TeclaPuls($10){tecla Q} then begin
|
||
|
||
{moure pep cap a dalt}
|
||
moviment:=true;
|
||
if sonido then sound(nota);delay(40);nosound;
|
||
if (j>marge_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 (j<marge_baix)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:=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 (i<marge_dreta)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:=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.
|