Program Pong;
Uses crt,graph;
{*------------------------------Procedimientos--------------------------------*}
Procedure Dibujar_Jugador(x:integer;y:integer);
Begin
setfillstyle(solidfill,white);
bar(x-6,y-15,x+6,y+15);
End;
Procedure Borrar_Jugador(x,y:integer);
Begin
setfillstyle(solidfill,green);
bar(x-6,y-15,x+6,y+15);
End;
Procedure Dibujar_Bola(xb,yb:integer);
Begin
setfillstyle(solidfill,red);
fillellipse(xb,yb,10,10);
End;
Procedure Borrar_Bola(xb,yb:integer);
Begin
setfillstyle(solidfill,green);
bar(xb-10,yb-10,xb+10,yb+10);
End;
{------------------------------------------------------------------------------}
Var x1,y1,x2,y2,xb,yb,movx,movy:integer;
tec:byte;
gd,gm:smallint;
pathtodriver:string;
Begin
{*---------------------Inicializacion de variables-----------------------*}
x1:=207;
y1:=340;
x2:=793;
y2:=340;
xb:=500;
yb:=340;
{*-------------------Inicialización del modo Gráfico---------------------*}
gd:=detect; { highest possible resolution }
gm:=0; { not needed, auto detection }
PathToDriver:='C:PPBGI';
Initgraph(gd,gm,pathtodriver);
{*--------------------Inicialización de posiciones-----------------------*}
setfillstyle(solidfill,green);
bar(200,140,800,540);
Dibujar_Jugador(x1,y1);
Dibujar_Jugador(x2,y2);
{*----------------Inicialización de movimiento de la bola----------------*}
if random(2)=1 then movx:=10 //Inicialización de
else movx:=-10; //dirección del
if random(2)=1 then movy:=10 //movimiento aleatoriamente
else movy:=-10;
{*-----------------------------------------------------------------------*}
repeat
if (yb=150)or(yb=530) then movy:=-movy; //La bola choca los bordes?
if (xb=210)and((yb>=y1-10)or(yb<=y1+10))then movx:=-movx; //Choca las
if (xb=790)and((yb>=y2-10)or(yb<=y2+10))then movx:=-movx; //paletas?
if keypressed then
begin
tec:=ord(readkey);
if (tec=ord('w')) and (y1>55) then
begin
Borrar_Jugador(x1,y1);
y1:=y1-1;
Dibujar_Jugador(x1,y1);
end
else
if (tec=ord('s')) and (y1<525) then
begin
Borrar_Jugador(x1,y1);
y1:=y1+1;
Dibujar_Jugador(x1,y1);
end;
end;
Borrar_Bola(xb,yb);
xb:=xb+movx; //Movimiento de la bola
yb:=yb+movy;
Dibujar_Bola(xb,yb);
delay(100);
until (xb=209)or(xb=791);
End.