2D bludisko za pomoci grafiky v pascale

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Kategórie: KMP (Programy mladých programátorů)
bludisko.pngAutor: Gabriel Staroň
Program: Bludisko.pas
Soubor exe: Bludisko.exe
Potřebné: Egavga.bgi

Bludisko urobené v 2D grafike. Musíte nájsť hubku pomocou ktorej potom môžete prejsť do ďalšieho levelu. Počas cesty zbierate prémie alebo životy.
{ BLUDISKO.PAS                                                      }
{                                                                   }
{ Author: Gabriel Staron                                            }
{ Date  : 15.02.1997                           http://www.trsek.com }
 
program Bludisko_Gabo;
uses crt,graph;
var
  grDriver      : Integer;
  grMode        : Integer;
  ErrCode       : Integer;
  x,y,xp,yp     : Integer;
  ch            : Char;
  hubka,level   : Integer;
  zivot,body    : Integer;
  ret_h,ret_l,s : String;
  ret_z,ret_b   : String;
 
procedure bludisko(x,y:integer);
begin
      hubka:=0;
      level:=1;
      zivot:=3;
      body:=0;
       setcolor(green);
       outtextxy(100,368,'  = "hubka" - potrebujes na prechod do druheho levelu');
       outtextxy(100,378,'L2 = koniec 1.levelu a zaciatok 2.levelu');
       outtextxy(100,388,'- = plus jeden zivot');
       outtextxy(100,398,'+ = minus jeden zivot');
       outtextxy(100,408,'  = premia');
       setcolor(cyan);
       str(hubka,ret_h);
       str(level,ret_l);
       str(zivot,ret_z);
       str(body,ret_b);
       outtextxy(328,38,'Pocet zivotov : '+ret_z);
       outtextxy(328,70,'Pocet bodov : '+ret_b);
       outtextxy(328,102,'Hubka : '+ret_h);
       outtextxy(328,134,'Level : '+ret_l);
 
       setcolor(white);
       setlinestyle(0,0,3);
       line(x+10,y+10,x+10,y+310);
       line(x+10,y+310,x+310,y+310);
       line(x+310,y+310,x+310,y+10);
       line(x+310,y+10,x+40,y+10);
       line(x+40,y+10,x+40,y+250);
       line(x+40,y+250,x+280,y+250);
       line(x+280,y+250,x+280,y+40);
       line(x+280,y+40,x+220,y+40);
       line(x+220,y+40,x+220,y+70);
       line(x+220,y+70,x+250,y+70);
       line(x+250,y+70,x+250,y+220);
       line(x+250,y+220,x+70,y+220);
       line(x+70,y+220,x+70,y+160);
       line(x+70,y+160,x+100,y+160);
       line(x+100,y+160,x+100,y+190);
       line(x+100,y+190,x+130,y+190);
       line(x+130,y+190,x+130,y+220);
       line(x+190,y+40,x+190,y+160);
       line(x+191,y+100,x+220,y+100);
       line(x+190,y+40,x+70,y+40);
       line(x+70,y+40,x+70,y+130);
       line(x+70,y+130,x+100,y+130);
       line(x+100,y+130,x+100,y+70);
       line(x+100,y+70,x+160,y+70);
       line(x+160,y+70,x+160,y+100);
       line(x+160,y+100,x+130,y+100);
       line(x+130,y+100,x+130,y+130);
       line(x+130,y+130,x+160,y+130);
       line(x+160,y+130,x+160,y+190);
       line(x+160,y+190,x+220,y+190);
       line(x+220,y+190,x+220,y+160);
       line(x+220,y+160,x+250,y+160);
    end;
 
procedure Level_2;
begin
      sound(620);
      delay(500);
      nosound;
      setcolor(black);
      outtextxy(328,134,'Level : 1');
      setcolor(cyan);
      outtextxy(328,134,'Level : 2');
      setcolor(black);
      outtextxy(80,115,'L2');
   end;
 
 function pohyb(x,y,kam:integer):boolean;
 var i:integer;
 begin
  pohyb:=true;
  if (kam=0) then
     for i:=x to x+20 do if (getpixel(i,y)=15) then pohyb:=false;
  if (kam=1) then
     for i:=y to y+20 do if (getpixel(x,i)=15) then pohyb:=false;
  if (kam=2) then
     for i:=x downto x-10 do if (getpixel(i,y)=15) then pohyb:=false;
  if (kam=3) then
     for i:=y downto y-10 do if (getpixel(x,i)=15) then pohyb:=false;
 end;
 
 begin
   grDriver := Detect;
   InitGraph(grDriver,grMode,'');
   x:=2;xp:=20;
   y:=2;yp:=20;
   bludisko(x,y);
   setlinestyle(1,0,3);
   setcolor(red);
   outtextxy(146,83,'');
   outtextxy(80,115,'L2');
   outtextxy(228,168,'-');
   outtextxy(138,113,'+');
   outtextxy(230,55,'');
 repeat
    ch:=readkey;
    if (ch=#0) then begin
       setcolor(black);
       outtextxy(xp,yp,'');
       ch:=readkey;
       if (ch='K') then if pohyb(xp,yp,2) then xp:=xp-10;
       if (ch='M') then if pohyb(xp,yp,0) then xp:=xp+10;
       if (ch='H') then if pohyb(xp,yp,3) then yp:=yp-10;
       if (ch='P') then if pohyb(xp,yp,1) then yp:=yp+10;
 
       if (xp=140) and (yp=110) then begin
             sound(220);                         { ubera pocet zivotov }
             delay(500);
             nosound;
             str(zivot,ret_z);
             setcolor(black);
             outtextxy(328,38,'Pocet zivotov : '+ret_z);
             zivot:=zivot-1;
             str(zivot,ret_z);
             setcolor(cyan);
             outtextxy(328,38,'Pocet zivotov : '+ret_z);
             setcolor(black);
             outtextxy(138,113,'+');
            end;
 
       if (xp=150) and (yp=80) then begin
            sound(320);                          { pridava pocet hubiek }
            delay(500);
            nosound;
            str(hubka,ret_h);
            setcolor(black);
            outtextxy(328,102,'Hubka : '+ret_h);
            hubka:=hubka+1;
            str(hubka,ret_h);
            setcolor(cyan);
            outtextxy(328,102,'Hubka : '+ret_h);
            setcolor(black);
            outtextxy(146,83,'');
           end;
 
        if (xp=230) and (yp=170) then begin
            sound(420);                          { pridava pocet zivotov }
            delay(500);
            nosound;
            str(zivot,ret_z);
            setcolor(black);
            outtextxy(328,38,'Pocet zivotov : '+ret_z);
            zivot:=zivot+1;
            str(zivot,ret_z);
            setcolor(cyan);
            outtextxy(328,38,'Pocet zivotov : '+ret_z);
            setcolor(black);
            outtextxy(228,168,'-');
           end;
 
        if (xp=230) and (yp=50) then begin
            sound(520);                         { pridava pocet bodov }
            delay(500);
            nosound;
            str(body,ret_b);
            setcolor(black);
            outtextxy(328,70,'Pocet bodov : '+ret_b);
            body:=body+100;
            str(body,ret_b);
            setcolor(cyan);
            outtextxy(328,70,'Pocet bodov : '+ret_b);
            setcolor(black);
            outtextxy(230,55,'');
           end;
 
        if (xp=80) and (yp=120) then Level_2;
        setcolor(blue);
        outtextxy(10,440,'ŰŰŰŰŰ');
        outtextxy(10,470,'ŰŰŰŰŰ');
        setcolor(white);
        str(xp,ret_h);outtextxy(10,440,ret_h);
        str(yp,ret_h);outtextxy(10,470,ret_h);
 
        if (body=200) or (body=400) or (body=800)  then begin
            sound(420);                          { pridava pocet zivotov, ked je pocet bodov 10 000 }
            delay(500);
            nosound;
            str(zivot,ret_z);
            setcolor(black);
            outtextxy(328,38,'Pocet zivotov : '+ret_z);
            zivot:=zivot+1;
            str(zivot,ret_z);
            setcolor(cyan);
            outtextxy(328,38,'Pocet zivotov : '+ret_z);
           end;
 
      setcolor(white);
      outtextxy(xp,yp,'');
     end;
 
until (ch=#27) or (zivot=0) or (body=900) or (zivot=5);
closegraph;
end.