Skip to content

Instantly share code, notes, and snippets.

@kareiva
Last active December 1, 2021 17:35
Show Gist options
  • Save kareiva/b109b54ae021bdb57d6ea2bf55d17f88 to your computer and use it in GitHub Desktop.
Save kareiva/b109b54ae021bdb57d6ea2bf55d17f88 to your computer and use it in GitHub Desktop.
This code is 20yrs old, but it somewhat works with ptcgraph unit
{
��������������������������ͻ
�Simonas Kareiva �
� 2000 12 22 6:30 AM �
� PinGPonG v0.01 �
� questions:molotov@mp3.lt �
��������������������������ͼ
}
program pingpong;
uses Crt, ptcgraph;
{}var{=========================}
tcolor:word;
ch1:char;dir:byte;
Gd,Gm,Mx,My,GSpre,GameSpeed:integer;
code,i,j,x1,x2,y1,y2,Pscore1,Pscore2:integer;
rx,ry,dirX,dirY,m,n:integer;
continue,CC,Sp:boolean;
PName1,PName2,pscore1s,pscore2s:string;
{===============================}
procedure proc_exit;
begin
CloseGraph;
ClrScr;
writeLn(' ����������������ͻ');
writeLn(' � PinGPonG v0.01 �');
writeLn(' � by Molotov �');
writeLn(' � molotov@mp3.lt �');
writeLn(' ����������������ͼ');
readkey;
halt;
end;
procedure menu_help; forward;
procedure proc_game; forward;
procedure game_cycle;forward;
procedure move_da_ball;
begin
SetColor(Black);
rectangle(rx-10,ry-10,rx+10,ry+10);
if rx+20 > GetMaxX then begin
Sound(1000);
Delay(10);
Nosound;
dirX:=-1;
end;
if rx-20 < 0 then begin
Sound(1000);
Delay(10);
Nosound;
dirX:=1;
end;
if (rx-11<=35) and (ry+10>y1) and (ry-10<(y1+100)) then begin
Sound(440);
Delay(10);
Nosound;
dirX:=1;
end;
if (rx-11<=35) and (((ry+10<y1) or (ry-10 > (y1+100)))) then begin
Sound(50);
Delay(1000);
NoSound;
inc(pscore2);
game_cycle;
end;
if (rx+11>=Mx-35) and ((ry+10<y2) or (ry-10>(y2+100))) then begin
Sound(50);
Delay(1000);
NoSound;
inc(pscore1);
game_cycle;
end;
if (rx+11>=Mx-35) and (ry+10>y2) and (ry-10<(y2+100)) then begin
Sound(440);
Delay(10);
Nosound;
dirX:=-1;
end;
if ry+20 > GetMaxY then begin
Sound(1000);
Delay(10);
Nosound;
dirY:=-1;
end;
if ry-20 < 50 then begin
Sound(1000);
Delay(10);
Nosound;
dirY:=1;
end;
inc(m);
if m > 200-GameSpeed then begin
inc(rx,dirX);
m:=1;
end;
inc(n);
if n > 200-GameSpeed then begin
inc(ry,dirY);
n:=1;
end;
SetColor(Red);
rectangle(rx-10,ry-10,rx+10,ry+10);
end;
{===============================}
procedure move_p1_up;
begin;
SetColor(black);
rectangle(10,y1,35,y1+100);
SetColor(yellow);
dec(y1,GameSpeed div 5);
if y1 < 60 then y1:=60;
rectangle(10,y1,35,y1+100);
end;
procedure move_p1_down;
begin;
SetColor(black);
rectangle(10,y1,35,y1+100);
SetColor(yellow);
inc(y1,GameSpeed div 5);
if y1 > My-110 then y1:=My-110;
rectangle(10,y1,35,y1+100);
end;
procedure move_p2_up;
begin;
SetColor(black);
rectangle(GetMaXx-35,y2,GetMaxX-10,y2+100);
SetColor(yellow);
dec(y2,GameSpeed div 5);
if y2 < 60 then y2:=60;
rectangle(GetMaxX-35,y2,GetMaxX-10,y2+100);
end;
procedure move_p2_down;
begin;
SetColor(black);
rectangle(Mx-35,y2,Mx-10,y2+100);
SetColor(yellow);
inc(y2,GameSpeed div 5);
if y2 > My-110 then y2:=My-110;
rectangle(Mx-35,y2,Mx-10,y2+100);
end;
procedure intro;
begin
for i:=1 to (My div 4)-30 do begin
if CC then SetColor(Black) else SetColor(Yellow);
CC:= not CC;
rectangle((Mx div 4)-1+i,(My div 4)-1+i,3*(Mx div 4)-i,3*(My div 4)-i);
Sound(25*i);
Delay(30);
end;
Sound(i*2);
Delay(100);
Nosound;
j:=1;
CC:=true;
continue:=false;
repeat
if KeyPressed then ch1:=ReadKey;
if ch1 = #27 then Halt;
inc(j);
if j > 100 then begin
if CC then begin
tcolor:=Red;
CC:=not CC;
j:=1;
end
else begin
tcolor:=Brown;
CC:=not CC;
j:=1;
end;
SetColor(tcolor);
SetTextStyle(DefaultFont,HorizDir,2);
OutTextXY((Mx div 4) + (My div 4) - 25,(My div 2)-10,'PinGPonG');
SetTextStyle(DefaultFont,HorizDir,1);
SetColor(yellow);
OutTextXY((Mx div 4) + (My div 4),(My div 2)+12,'by Molotov');
Delay(1000);
end;
until Keypressed;
readkey;
end;
procedure menu_main;
begin
ClearDevice;
pscore1:=0;
pscore2:=0;
SetColor(yellow);
SetTextStyle(DefaultFont,HorizDir,1);
rectangle((Mx div 4),(My div 4),3*(Mx div 4)-1,3*(My div 4)-1);
rectangle((Mx div 4)+2,(My div 4)+2,3*(Mx div 4)-3,3*(My div 4)-3);
OutTextXY((Mx div 2) - 110,My div 3, 'Play 1 vs 1 [ANY KEY]');
OutTextXY((Mx div 2) - 110,(My div 3)+20,'Get some help [H]');
OutTextXY((Mx div 2) - 110,(My div 3)+40,'Exit [ESC]');
ch1:=ReadKey;
if Upcase(ch1)='H' then menu_help;
if ch1=#27 then proc_exit
else proc_game;
end;
procedure menu_help;
begin
ClearDevice;
SetColor(yellow);
SetTextStyle(DefaultFont,HorizDir,1);
rectangle((Mx div 4),(My div 4),3*(Mx div 4)-1,3*(My div 4)-1);
rectangle((Mx div 4)+2,(My div 4)+2,3*(Mx div 4)-3,3*(My div 4)-3);
OutTextXY((Mx div 2) - 110,My div 3, 'Player 1 Controls : A/Z');
OutTextXY((Mx div 2) - 110,(My div 3)+20,'Player 2 Controls : K/M');
OutTextXY((Mx div 2) - 110,(My div 3)+40,'Game speed control: +/-');
OutTextXY((Mx div 2) - 110,(My div 3)+60,'Pause the game : [P]');
OutTextXY((Mx div 2) - 110,(My div 3)+100,' Author:');
OutTextXY((Mx div 2) - 110,(My div 3)+120,'Molotov (molotov@mp3.lt)');
OutTextXY((Mx div 2) - 110,(My div 3)+150,' Press any key...');
readkey;
menu_main;
end;
procedure proc_game;
begin
ClearDevice;
SetColor(yellow);
SetTextStyle(DefaultFont,HorizDir,1);
rectangle((Mx div 4),(My div 4),3*(Mx div 4)-1,3*(My div 4)-1);
rectangle((Mx div 4)+2,(My div 4)+2,3*(Mx div 4)-3,3*(My div 4)-3);
OutTextXY((Mx div 2) - 35,My div 3,'Player 1:');
SetColor(Red);
SetTextStyle(DefaultFont,HorizDir,2);
moveto((Mx div 4) + 10, (My div 2)-10);
repeat
ch1:=ReadKey;
PName1:=PName1+ch1;
outtext(ch1);
until (ch1=#13) or (ch1=#27);
PName1:=copy(PName1,1,length(PName1)-1);
if PName1='' then PName1:='Player 1';
ClearDevice;
SetColor(yellow);
rectangle((Mx div 4),(My div 4),3*(Mx div 4)-1,3*(My div 4)-1);
rectangle((Mx div 4)+2,(My div 4)+2,3*(Mx div 4)-3,3*(My div 4)-3);
SetTextStyle(DefaultFont,HorizDir,1);
OutTextXY((Mx div 2) - 35,My div 3,'Player 2:');
SetColor(Blue);
SetTextStyle(DefaultFont,HorizDir,2);
moveto((Mx div 4) + 10, (My div 2)-10);
repeat
ch1:=ReadKey;
PName2:=PName2+ch1;
outtext(ch1);
until (ch1=#13) or (ch1=#27);
PName2:=copy(PName2,1,length(PName2)-1);
if PName2='' then PName2:='Player 2';
ClearDevice;
SetColor(yellow);
rectangle((Mx div 4),(My div 4),3*(Mx div 4)-1,3*(My div 4)-1);
rectangle((Mx div 4)+2,(My div 4)+2,3*(Mx div 4)-3,3*(My div 4)-3);
SetTextStyle(DefaultFont,HorizDir,1);
OutTextXY((Mx div 2) - 40,My div 3,'Game speed:');
SetColor(White);
SetTextStyle(DefaultFont,HorizDir,2);
moveto((Mx div 2) - 10, (My div 2)-10);
repeat
ch1:=ReadKey;
val(ch1,GSpre,code);
until (code=0) or (ch1=#13);
Randomize;
if ch1=#13 then GameSpeed:=180 else GameSpeed:=GSpre*20;
outtext(ch1);
Delay(2000);
game_cycle;
end;
procedure game_cycle;
begin
ClearDevice;
SetColor(yellow);
rectangle(0,0,Mx,My);
line(0,50,Mx,50);
line(mx div 2,0,mx div 2, 50);
SetColor(Red);
OutTextXY(10,10,pname1);
str(pscore1,pscore1s);
OutTextXY((Mx div 2)-50,10,Pscore1s);
SetColor(Blue);
OutTextXY((Mx div 2)+10,10,pname2);
str(pscore2,pscore2s);
OutTextXY(Mx -50,10,Pscore2s);
y1:=(My div 2)-50;
y2:=(My div 2)-50;
SetColor(yellow);
rectangle(10, y1,35, y1+100);
rectangle(Mx-35,y2,Mx-10,y2+100);
SetColor(red);
Randomize;
dir:=Random(2);
if dir = 0 then dirX:=1 else dirX:=-1;
dir:=Random(2);
if dir = 0 then dirY:=1 else dirX:=-1;
m:=1;
n:=1;
rx:=Mx div 2;
ry:=My div 2;
rectangle(rx-10,ry-10,rx+10,ry+10);
{===================}repeat{=======================}
move_da_ball;
ch1:=' ';
if keypressed then ch1:=Readkey;
case Upcase(ch1) of
'A':move_p1_up;
'Z':move_p1_down;
'K':move_p2_up;
'M':move_p2_down;
#43:begin
if (gamespeed + 10) < 200 then inc(GameSpeed,10);
end;
#45:begin
if (gamespeed - 10) > 10 then dec(GameSpeed,10);
end;
'P':begin
readkey;
end;
end;
{============}until ch1=#27 {=======================};
menu_main;
end;
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
begin;
Gd:=Detect;Gm:=Detect;
ClrScr;
InitGraph(Gd,Gm,' ');
Mx:=GetMaxX;My:=GetMaxY;
CC:=true;
delay(5000);
intro;
menu_main;
{================================}
closegraph;
proc_exit;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment