Program Siege; Uses LogoScreen,
DOS, VGA13h, VGASpr, Retrace, Buttons,
SiegeLogo, SiegeS
pr;
Type
EnemyType = record
X,Y,D,S,A:Integer;
Falling:Boolean;
Free:Boolean;
end;
Const
MaxEnemies = 50;
ComboStr:Array [0..5] of String[20] =
('Looser!!!',
'',
'2 hit combo',
'Eat this!',
'Ough! 4 mans at once',
'Aaaaaaaaamazing!!!');
Var
ManX,StoneY,StoneX,EnemyDelay,EnemyLimit:Integer;
Enemies:Array [1..MaxEnemies] of EnemyType;
Score,Level,Kills,Combo:Word;
Timer:Longint;
GameOver:Boolean;
{==================================================================}
Const
ca:Word = 0;
cc:String[20] = '';
Procedure ComboString(s:String);
begin
if s<>'' then
begin
cc:=s;
ca:=10;
end;
if ca>0 then
begin
DrawString(Base2,160-Byte(cc[0])*4,90,cc);
Dec(ca);
end;
end;
Procedure NextLevel; forward;
{==================================================================}
Procedure InitEnemies;
Var
i:Byte;
begin
for i:=1 to MaxEnemies do Enemies[i].Free:=true;
end;
Procedure DrawEnemies;
Var
i:Byte;
begin
for i:=1 to MaxEnemies do
With Enemies[i] do if not Free then
DrawTSpr(Base2,X,Y,EnemyHgt,EnemyWdt,@EnemySpr[A]);
end;
Procedure MoveEnemies;
Var
i:Byte;
begin
for i:=1 to MaxEnemies do
With Enemies[i] do
if not Free then
begin
if Falling then
begin
Y:=Y+10;
if Y>199 then
begin
Free:=true;
if Kills=(Level+1)*20 then NextLevel;
end;
if D=0 then
begin
Inc(A);
if A>2 then A:=1;
D:=2;
end else Dec(D);
end else
if D=0 then
begin
Y:=Y-5;
if Y<40 then GameOver:=true;
Inc(A);
if A>2 then A:=1;
D:=S;
end else Dec(D);
end else
if (EnemyLimit>0) and (EnemyDelay=0) then
begin
X:=Random(38)*8;
Y:=200;
D:=0;
S:=(10-Level);
A:=1;
EnemyDelay:=(13-Level)*2+1;
Falling:=false;
Free:=false;
Dec(EnemyLimit);
end;
Dec(EnemyDelay);
end;
{==================================================================}
Procedure DrawScreen;
Var
x,y:Integer;
s:String[80];
tmp:String[6];
begin
Bar(Base2,0,0,319,9,8);
FillBase(Base2,3200,9600,$03030303);
for y:=0 to 15 do
for x:=0 to 31 do
DrawOSpr(Base2,x*10,40+y*10,BrickHgt,BrickWdt,@BrickSpr);
s:='ю ~SIEGE~ ю Level:';
Str(Level,tmp);
While Byte(tmp[0])<2 do tmp:='ъ'+tmp;
s:=s+tmp+' ю Score:';
Str(Score,tmp);
While Byte(tmp[0])<5 do tmp:='ъ'+tmp;
s:=s+tmp+' ю';
DrawString(Base2,1,1,s);
end;
{==================================================================}
Procedure DrawMan;
begin
if StoneY=0 then
begin
DrawTSpr(Base2,ManX*8,20,ManHgt,ManWdt,@ManSpr[2]);
DrawTSpr(Base2,ManX*8+4,17,StoneHgt,StoneWdt,@StoneSpr);
end else
begin
DrawTSpr(Base2,ManX*8,20,ManHgt,ManWdt,@ManSpr[1]);
DrawTSpr(Base2,StoneX,StoneY,StoneHgt,StoneWdt,@StoneSpr);
Inc(StoneY,10);
if StoneY>199 then
begin
StoneY:=0;
if Combo<7 then ComboString(ComboStr[Combo]) else ComboString('Kiiler!!!');
Combo:=0;
end;
end;
end;
{==================================================================}
Procedure CheckCollisions;
Var
i:Byte;
begin
if StoneY>0 then
for i:=1 to MaxEnemies do
With Enemies[i] do
if not Free and not Falling then
begin
if ((StoneX+8>X) and (StoneX((StoneY+8>Y) and (StoneYbegin
Falling:=true;
D:=0;
Inc(Score);
Inc(Kills);
Inc(Combo);
end;
end;
end;
{==================================================================}
Procedure NextLevel;
Var
i:Byte;
begin
Timer:=MemL[Seg0040:$006C];
Inc(Level);
for i:=1 to 30 do
begin
ClearBase(Base2);
DrawScreen;
DrawTSpr(Base2,ManX*8,20,ManHgt,ManWdt,@ManSpr[1+Byte(i and 1=1)]);
DrawString(Base2,132,80,'Level '+Char($30+Level));
WaitRetraceMode;
CopyBase(Base2,Base1);
While Timer=MemL[Seg0040:$006C] do;
Timer:=MemL[Seg0040:$006C];
end;
EnemyLimit:=(1+Level)*20;
EnemyDelay:=0;
Kills:=0;
ca:=0;
end;
Procedure GameOverProc;
Var
i:Byte;
begin
ClearBase(Base2);
DrawScreen;
DrawString(Base2,124,80,'Game Over');
WaitRetraceMode;
CopyBase(Base2,Base1);
Timer:=MemL[Seg0040:$006C];
for i:=1 to 30 do
begin
While Timer=MemL[Seg0040:$006C] do;
Timer:=MemL[Seg0040:$006C];
end;
end;
{==================================================================}
Procedure Init;
begin
if not DetectVGA then
begin
Writeln('Необходим VGA совместимый видеоадаптер.'#7);
Halt(1);
end;
SetGraphMode;
InitButtons;
Randomize;
ManX:=19;
Timer:=MemL[Seg0040:$006C];
EnemyLimit:=(Level+1)*20;
GetIntVec($43, Pointer(Font));
end;
Procedure Game;
begin
InitEnemies;
Level:=0;
Score:=0;
Kills:=0;
Combo:=0;
EnemyLimit:=(Level+1)*20;
GameOver:=false;
Repeat
ClearBase(Base2);
DrawScreen;
DrawEnemies;
DrawMan;
ComboString('');
MoveEnemies;
CheckCollisions;
if Key[keyLeft] then if ManX>0 then Dec(ManX);
if Key[keyRight] then if ManX<38 then Inc(ManX);
if Key[keySpace] then if StoneY=0 then
begin
StoneX:=(ManX*8)+4;
StoneY:=24;
end;
WaitRetraceMode;
CopyBase(Base2,Base1);
While Timer=MemL[Seg0040:$006C] do;
Timer:=MemL[Seg0040:$006C];
Until Key[keyEsc] or (Level>=10) or GameOver;
if GameOver then GameOverProc;
end;
Procedure Done;
begin
DoneButtons;
SetTextMode;
DoneVirtualPage;
end;
{==================================================================}
Var
choice:Byte;
begin
Init;
Repeat
choice:=Logo;
Case choice of
1:Game;
2:Info;
3:Story;
end;
Until choice=4;
Done;
end.