Files
pepe_port/delphi/main.pas
2024-01-24 08:46:06 +01:00

479 lines
12 KiB
ObjectPascal
Raw Blame History

unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, DXDraws, MPlayer, DXClass;
type
TForm1 = class(TDXForm)
VGA: TDXDraw;
Pics: TDXImageList;
Pinta: TTimer;
mover: TTimer;
Musica: TMediaPlayer;
procedure NouNivell;
procedure FormCreate(Sender: TObject);
procedure PintaTimer(Sender: TObject);
procedure VGAClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure moverTimer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
const
MAPAWIDTH = 39;
MAPAHEIGHT = 29;
pUP = 38;
pLEFT = 37;
pRIGHT = 39;
pDOWN = 40;
STATERUNNING = 0;
STATEPINTURA = 1;
STATEINICIANT = 2;
SENTITHORIZ = 1;
SENTITVERT = 0;
FACIL = 4;
NORMAL = 2;
DIFICIL = 0;
type
TPersonatge = record
x, y : byte;
mUP, mDOWN, mLEFT, mRIGHT : boolean;
pintura, vides : byte;
punts : word;
tUP, tDOWN, tLEFT, tRIGHT : byte;
gNormal, gNoPint,
gMort1, gMort2,
gFin1, gFin2 : byte;
end;
TMalo = record
X, Y : byte;
Sentit : byte;
Viu : boolean;
Dibuix : byte;
end;
TFase = record
Mapa : array[0..MAPAWIDTH-1, 0..MAPAHEIGHT-1] of byte;
BlocsTotal, BlocsActual : integer;
NumEnemics : byte;
Disp1, Disp2, Disp3 : integer;
gBloc, gPintat, gPot : byte;
end;
var
Form1 : TForm1;
Pepe : TPersonatge;
malo : array[0..2] of TMalo;
Fase : TFase;
Nivell : byte;
AugPunts : word;
estat : byte;
dificultat : byte;
RAIVAR1,RAIVAR2,RAIVAR3 : integer;
RAI : byte;
implementation
{$R *.DFM}
procedure TForm1.NouNivell;
var
fitxer : file of char;
i,j : byte;
tmp : char;
begin
Fase.BlocsTotal := 0;
AugPunts := 2;
assignfile(fitxer,'mapa.txt');
reset(fitxer);
seek(fitxer, 1178*(Nivell-1));
for i:= 0 to MAPAWIDTH-2 do
begin
for j := 0 to MAPAHEIGHT-1 do
begin
blockread(fitxer, tmp, 1);
Fase.Mapa[i,j] := ord(tmp) - 48;
if Fase.Mapa[i,j] = 0 then inc(Fase.BlocsTotal);
// if mapa[i,j] = 3 then begin pepe.x := i; pepe.y := j; end;
end;
blockread(fitxer, tmp, 1);
blockread(fitxer, tmp, 1);
end;
closefile(fitxer);
Fase.Mapa[38,14] := 3;
RAIVAR1 := 0;
RAI := 0;
pepe.x := 38;
pepe.y := 14;
pepe.mRIGHT := false;
pepe.mLEFT := false;
pepe.mDOWN := false;
pepe.mUP := false;
pepe.pintura := 255;
pepe.tUP := pUP;
pepe.tDOWN := pDOWN;
pepe.tLEFT := pLEFT;
pepe.tRIGHT := pRIGHT;
pepe.vides := 5;
pepe.gNormal := 3;
pepe.gNoPint := 4;
pepe.gMort1 := 5;
pepe.gMort2 := 6;
pepe.gFin1 := 7;
pepe.gFin2 := 8;
Fase.BlocsActual := Fase.BlocsTotal;
Fase.gBloc := 31;
Fase.gPintat := 44;
Fase.gPot := 30;
Fase.Disp1 := (Fase.BlocsTotal div 4)*3;
Fase.Disp2 := (Fase.BlocsTotal div 4)*2;
Fase.Disp3 := (Fase.BlocsTotal div 4)*1;
estat := STATEINICIANT;
mover.Interval := 1;
dificultat := FACIL;
Malo[0].viu := False;
Malo[1].viu := False;
Malo[2].viu := False;
if Musica.Mode <> mpNotReady then
begin Musica.Close; end;
If Nivell mod 2 = 1
then Musica.FileName := ExtractFilePath(Application.Exename)+'musica\mfase01.mid'
else Musica.FileName := ExtractFilePath(Application.Exename)+'musica\mfase02.mid';
Musica.Open;
Musica.Play;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
VGA.Cursor := crNone;
Nivell := 1;
NouNivell;
Pepe.Punts := 0;
//Musica.FileName := 'musica\mfase01.mid';
//Musica.Open;
end;
procedure TForm1.PintaTimer(Sender: TObject);
var
i,j : byte;
begin
if not(VGA.CanDraw) then exit;
if estat = STATEINICIANT then
begin
VGA.Surface.Fill(0);
if RAI = 0 then
begin
pics.items[1].DrawWaveXAlpha(VGA.Surface,
0, 0, 250, 200, 0, 64-RAIVAR1, 64-RAIVAR1,
255-(RAIVAR1*4), RAIVAR1*4);
end;
if RAI = 1 then
begin
pics.items[1].draw(VGA.surface, 0, 0, 0);
pics.items[2].DrawWaveXAlpha(VGA.Surface,
250, 0, 70, 200, 0, 64-RAIVAR1, 64-RAIVAR1, 255-(RAIVAR1*4), RAIVAR1*4);
end;
if RAI = 2 then
begin
pics.items[1].draw(VGA.surface, 0, 0, 0);
pics.items[2].draw(VGA.surface, 250, 0, 0);
pics.items[4].DrawWaveXAlpha(VGA.Surface,
80, 80, 160, 40, 0, 64-RAIVAR1, 64-RAIVAR1, 255-(RAIVAR1*4), RAIVAR1*4);
// pics.items[1].draw(VGA.surface, 0, 0, 0);
// pics.items[2].draw(VGA.surface, 250, 0, 0);
// pics.items[4].draw(VGA.surface,RAIVAR1,80,nivell-1);
end;
if RAI = 3 then
begin
pics.items[1].draw(VGA.surface, 0, 0, 0);
pics.items[2].draw(VGA.surface, 250, 0, 0);
pics.items[4].draw(VGA.surface,80,80,nivell-1);
end;
if RAI = 4 then
begin
pics.items[1].draw(VGA.surface, 0, 0, 0);
pics.items[2].draw(VGA.surface, 250, 0, 0);
pics.items[4].DrawWaveXAlpha(VGA.Surface,
80, 80, 160, 40, 0, 64-RAIVAR1, 64-RAIVAR1, 255-(RAIVAR1*4), RAIVAR1*4);
end;
end;
if (estat = STATERUNNING) or (estat = STATEPINTURA) then
begin
// PINTEM EL FONDO, LA BARRA I LA PINTURA QUE LI QUEDA
pics.items[1].draw(VGA.surface, 0, 0, 0);
pics.items[2].draw(VGA.surface, 250, 0, 0);
If Pepe.Pintura > 0 then pics.items[0].stretchdraw(VGA.Surface, Rect(266,180-(pepe.pintura div 5),277,181), 44);
// PINTEM EL MAPA
for j := 0 to MAPAHEIGHT-1 do
for i := 0 to MAPAWIDTH-2 do
begin
If Fase.mapa[i,j] = 1 then pics.Items[0].draw(VGA.Surface, 11+(i*6), 13+(j*6), Fase.gBloc);
If Fase.mapa[i,j] = 2 then pics.Items[0].draw(VGA.Surface, 11+(i*6), 13+(j*6), Fase.gPintat);
end;
pics.Items[0].draw(VGA.Surface, 11+(38*6), 13+(14*6), Fase.gPot);
//PINTEM EL NIVELL ACTUAL, LES VIDES I EL INDICADOR DEL S<>
pics.Items[3].draw(VGA.Surface, 2, 2, 12+Nivell);
pics.Items[3].draw(VGA.Surface, 269, 170, 12+Pepe.vides);
pics.Items[3].draw(VGA.Surface, 3, 189, 11);
// PINTEM A PEPE
if pepe.pintura > 0
then pics.Items[0].draw(VGA.Surface, 11+(pepe.x*6), 13+(pepe.y*6), Pepe.gNormal)
else pics.Items[0].draw(VGA.Surface, 11+(pepe.x*6), 13+(pepe.y*6), Pepe.gNoPint);
// PINTEM ALS MALOS
for i := 0 to 2 do
if malo[i].viu then
pics.Items[0].draw(VGA.Surface, 11+(Malo[i].x*6), 13+(Malo[i].y*6), Malo[i].dibuix);
// PINTEM EL MARCADOR DE PUNTS
pics.items[3].draw(VGA.Surface, 266, 74, 12+( Pepe.Punts DIV 1000000));
pics.items[3].draw(VGA.Surface, 272, 74, 12+((Pepe.Punts MOD 1000000) DIV 100000 ));
pics.items[3].draw(VGA.Surface, 278, 74, 12+((Pepe.Punts MOD 100000) DIV 10000 ));
pics.items[3].draw(VGA.Surface, 284, 74, 12+((Pepe.Punts MOD 10000) DIV 1000 ));
pics.items[3].draw(VGA.Surface, 290, 74, 12+((Pepe.Punts MOD 1000) DIV 100 ));
pics.items[3].draw(VGA.Surface, 296, 74, 12+((Pepe.Punts MOD 100) DIV 10 ));
pics.items[3].draw(VGA.Surface, 302, 74, 12+( Pepe.Punts MOD 10 ));
end;
VGA.Flip;
end;
procedure TForm1.VGAClick(Sender: TObject);
begin
close;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = pepe.tUP then pepe.mUP := true;
if key = pepe.tDOWN then pepe.mDOWN := true;
if key = pepe.tLEFT then pepe.mLEFT := true;
if key = pepe.tRIGHT then pepe.mRIGHT := true;
inc(augPunts, 1);
// TRUCOS
if key = 65 then Fase.BlocsActual := 0;
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = pepe.tUP then pepe.mUP := false;
if key = pepe.tDOWN then pepe.mDOWN := false;
if key = pepe.tLEFT then pepe.mLEFT := false;
if key = pepe.tRIGHT then pepe.mRIGHT := false;
augPunts := 2;
end;
Procedure Moure_Malos;
var
i : byte;
begin
for i:=0 to 2 do
if malo[i].viu then
begin
case malo[i].sentit of
SENTITHORIZ:
if malo[i].x > Pepe.x then
begin
//if (malo[i].x-1 = Pepe.x) and (malo[i].y = Pepe.y) then
if Fase.Mapa[malo[i].x-1,malo[i].y] = 2 then dec(malo[i].x);
//mou_malo(i,esquerra);
malo[i].sentit:=random(2+dificultat);
end
else if malo[i].x < Pepe.x then
begin
if Fase.Mapa[malo[i].x+1,malo[i].y] = 2 then inc(malo[i].x);
//mou_malo(i,dreta);
malo[i].sentit:=random(2+dificultat);
end
else malo[i].sentit:=SENTITVERT;
SENTITVERT:
if malo[i].y > Pepe.y then
begin
if Fase.Mapa[malo[i].x,malo[i].y-1] = 2 then dec(malo[i].y);
//mou_malo(i,amunt);
malo[i].sentit:=random(2+dificultat);
end
else if malo[i].y < Pepe.y then
begin
if Fase.Mapa[malo[i].x,malo[i].y+1] = 2 then inc(malo[i].y);
//mou_malo(i,avall);
malo[i].sentit:=random(2+dificultat);
end
else malo[i].sentit:=SENTITHORIZ;
2,3,4,5: malo[i].sentit:=random(2+dificultat);
end;
end;
end;
procedure CreateMalos;
begin
if Fase.BlocsActual <= Fase.Disp1 then
if not(malo[0].viu) then
begin
malo[0].x := random(38);
malo[0].y := random(29);
if Fase.Mapa[malo[0].x,malo[0].y] = 2 then
begin
malo[0].dibuix := 22; malo[0].sentit := SENTITVERT;
malo[0].viu := True;
end;
end;
if Fase.BlocsActual <= Fase.Disp2 then
if not(malo[1].viu) then
begin
malo[1].x := random(38);
malo[1].y := random(29);
if Fase.Mapa[malo[1].x,malo[1].y] = 2 then
begin
malo[1].dibuix := 23; malo[1].sentit := SENTITVERT;
malo[1].viu := True;
end;
end;
(*
{ rellontge }
if story_mode_mode then
if blocs_per_pintar=(total_blocs_per_pintar div 3) then
if (not(rellontge.viu)) and (sense_rellontge) and (num_fase<10) then ini_rellontge;
*)
//if (Nivell=10) or (dificultat=DIFICIL)(* or (mode_nocturne)*) then
if Fase.BlocsActual <= Fase.Disp3 then
if not(malo[2].viu) then
begin
malo[2].x := random(38);
malo[2].y := random(29);
if Fase.Mapa[malo[2].x,malo[2].y] = 2 then
begin
malo[2].dibuix := 24; malo[2].sentit := SENTITVERT;
malo[2].viu := True;
end;
end;
end;
procedure TForm1.moverTimer(Sender: TObject);
var
tmpX, tmpY : byte;
begin
// LOOP DE LA MUSICA
if Musica.Mode <> mpPlaying then Musica.Play;
if estat = STATEINICIANT then
begin
if RAI = 0 then
if RAIVAR1 < 64 then inc(RAIVAR1,4) else begin RAI := 1; RAIVAR1 := 0; end;
if RAI = 1 then
if RAIVAR1 < 64 then inc(RAIVAR1,1) else begin RAI := 2; RAIVAR1 := 0; end;
if RAI = 2 then
if RAIVAR1 < 64 then inc(RAIVAR1,1) else begin RAI := 3; RAIVAR1 := 0; end;
if RAI = 3 then
if RAIVAR1 < 100 then inc(RAIVAR1,1) else begin RAI := 4; RAIVAR1 := 64; end;
if RAI = 4 then
if RAIVAR1 > 0 then dec(RAIVAR1,1) else begin RAI := 0; RAIVAR1 := 0;
estat := STATERUNNING; mover.Interval := 50; end;
end;
// ESTEM CARREGANT PINTURA
if estat = STATEPINTURA then
begin
if pepe.pintura+5 >= 255 then
begin
pepe.pintura := 255;
mover.Interval := 50;
estat := STATERUNNING;
end
else inc(pepe.pintura,5);
end;
// ESTEM JUGANT NORMAL
if estat = STATERUNNING then
begin
createmalos;
moure_malos;
if (pepe.pintura < 254) and (Fase.mapa[pepe.x, pepe.y] = 3) then
begin
mover.Interval := 1;
estat := STATEPINTURA;
end;
if (Fase.mapa[pepe.x, pepe.y] = 3) and (Fase.BlocsActual = 0) then
begin inc(Nivell); NouNivell; end;
tmpX := pepe.x; tmpY := pepe.y;
if pepe.mDOWN and (pepe.y<28) and (Pepe.x<38) then inc(pepe.y,1) else
if pepe.mUP and (pepe.y>0) and (Pepe.x<38) then dec(pepe.y,1) else
if pepe.mLEFT and (pepe.x>0) then dec(pepe.x,1) else
if pepe.mRIGHT and
( ( (pepe.y <> 14) and (pepe.x < 37) ) or
( (pepe.y = 14) and (pepe.x < 38) ) )
then inc(pepe.x,1) else exit;
if Fase.mapa[pepe.x, pepe.y] = 1 then
begin
pepe.x := tmpX; pepe.y := tmpY;
end
else
begin
If pepe.pintura > 0 then
begin
if Fase.mapa[tmpX, tmpY] <> 3 then
begin
if Fase.mapa[tmpX, tmpY] = 0 then
begin
dec(Fase.BlocsActual);
inc(pepe.punts);//, augPunts);
end;
Fase.mapa[tmpX, tmpY] := 2;
dec(pepe.pintura,1);
end;
end;
end;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Musica.Stop;
end;
end.