program splatintro;

{This uses 3d2dmotionphongghouradsuperanalogicsonicretracer mode by UNT}
{Also mode13h by spellcaster}

uses mode13h,crt,sprites;

Type RgbItem=Record
                   R,G,B:Byte;
             End;
     RgbList=Array[0..255] of RgbItem;

var image:array [1..11] of pointer;
    abc: array [1..30] of pointer;
    color:array [1..25] of integer;
    temp: rgblist;
    a: integer;
    x,y,z: byte;
    h: integer;
    r,g,b,d,e,f:byte;

procedure start;
begin
     initgraph;
     initvirt;
end;

procedure close;
begin
     closegraph;
     closevirt;
     textcolor (white);
     writeln ('The time has come! You must go now!');
     writeln ('');
end;

procedure fadeto (x,y,z:byte;h:integer);
var a:integer;
    r,g,b:byte;
begin
     delay (h);
     for a:=0 to 255 do
     begin
          getcolor (a,r,g,b);
          if r>x then r:=r-1;
          if r<x then r:=r+1;
          if g>y then g:=g-1;
          if g<y then g:=g+1;
          if b>z then b:=b-1;
          if b<z then b:=b+1;
          setcolor (a,r,g,b);
          end;
end;

procedure fadefrom (temp:rgblist;h:integer);
var a:integer;
    r,g,b:byte;
begin
     delay (h);
     for a:=0 to 255 do
     begin
          getcolor (a,r,g,b);
          if r>temp[a].r then r:=r-1;
          if r<temp[a].r then r:=r+1;
          if g>temp[a].g then g:=g-1;
          if g<temp[a].g then g:=g+1;
          if b>temp[a].b then b:=b-1;
          if b<temp[a].b then b:=b+1;
          setcolor (a,r,g,b);
     end;
end;

procedure palrotation;
var a:integer;
    r,g,b,d,e,f:byte;
begin
     getcolor (color[25],d,e,f);
     for a:=24 downto 2 do
         begin
              getcolor (color[a],r,g,b);
              setcolor (color[a+1],r,g,b);
         end;
     setcolor (color[2],d,e,f);
end;

procedure correctpic;
var a:integer;
    r,g,b:byte;
    x,y:integer;
begin                                       {DO REMEMBER:              }
     for x:=0 to 319 do                     {I have to do this because }
         begin                              {of the blueish color being}
              for y:=0 to 199 do            {equal to 15               }
                  begin
                  b:=getpixel (x,y,vp[2]);
                  if b= 15 then
                     begin
                          getcolor (b,r,g,b);
                          setcolor (255,r,g,b);
                          putpixel (x,y,255,vp[2]);
                     end;
                  end;
         end;
     for a:=2 to 25 do
         begin
              color[a]:= getpixel (76+a,33,vp[2]);
         end;
end;

procedure savepal;
var a:integer;
begin
     for a:=0 to 255 do getcolor (a,temp[a].r,temp[a].g,temp[a].b);
end;

procedure restorepal;
var a:integer;
begin
     for a:=0 to 255 do setcolor (a,temp[a].r,temp[a].g,temp[a].b);
end;

procedure loading;
begin
     textcolor (red);
     write ('L');
     delay (50);
     write ('o');
     delay (50);
     write ('a');
     delay (50);
     write ('d');
     delay (50);
     write ('i');
     delay (50);
     write ('n');
     delay (50);
     write ('g');
     delay (50);
     write ('.');
     delay (50);
     write ('.');
     delay (50);
     writeln ('.');
     delay (50);
     write ('P');
     delay (50);
     write ('l');
     delay (50);
     write ('e');
     delay (50);
     write ('a');
     delay (50);
     write ('s');
     delay (50);
     write ('e');
     delay (50);
     write (' w');
     delay (50);
     write ('a');
     delay (50);
     write ('i');
     delay (50);
     write ('t');
     write ('.');
     delay (50);
     write ('.');
     delay (50);
     write ('.');
     for a:=0 to 63 do fadeto (0,0,0,50);
end;

procedure splat;
begin
     {for a:=0 to 63 do fadeto (0,0,0,1); }
     copypage (vp[2],vga);
     for a:=0 to 63 do fadefrom (temp,30);
     for a:=0 to 63 do
         begin
              setcolor (61,63-a,63-a,63-a);
              delay (50);
              palrotation;
         end;
     for a:=0 to 63 do
         begin
              setcolor (61,a,a,a);
              delay (50);
              palrotation;
         end;
     for a:=0 to 63 do fadeto (63,63,63,15);
end;

procedure square (x1,y1,x2,y2,c:integer;w:word);
var x,y:integer;
begin
     for x:=x1 to x2 do putpixel (x,y1,c,w);
     for y:=y1 to y2 do putpixel (x1,y,c,w);
     for x:=x1 to x2 do putpixel (x,y2,c,w);
     for y:=y1 to y2 do putpixel (x2,y,c,w);
end;

procedure intro;
begin
     for a:=1 to 30 do getimage (3+8*a,178,10+8*a,190,abc[a],vp[1]);

     setcolor (159,0,0,63);
     getcolor (159,r,g,b);

     cls (159,vga);

     putimage (120,130,abc[9],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (140,100,abc[9],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (190,100,abc[4],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (135,80,abc[1],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (135,60,abc[18],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (120,100,abc[30],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (170,130,abc[15],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (200,130,abc[30],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (150,100,abc[20],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (125,60,abc[3],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (160,100,abc[3],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (180,100,abc[5],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (180,130,abc[21],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (155,80,abc[4],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (160,130,abc[25],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (140,130,abc[7],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (100,130,abc[2],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (145,60,abc[21],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (170,100,abc[8],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (165,60,abc[8],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (210,130,abc[30],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (110,100,abc[2],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (155,60,abc[19],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (110,130,abc[18],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (170,100,abc[8],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (130,100,abc[23],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (145,80,abc[14],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (190,130,abc[30],vga);
     setcolor (159,r+2,g+2,b-2);
     delay (300);
     getcolor (159,r,g,b);

     putimage (130,130,abc[14],vga);
     setcolor (159,r+2,g+2,b-2);

     for a:=0 to 63 do fadeto (63,63,0,35);
end;

procedure credits01;
var a:integer;
begin
     cls (159,vga);
     square (0,0,319,199,0,vga);
     square (1,1,318,198,1,vga);
     square (2,2,317,197,3,vga);
     square (3,3,316,196,4,vga);
     square (4,4,315,195,5,vga);
     square (5,5,314,194,6,vga);
     square (6,6,313,193,7,vga);
     square (7,7,312,192,8,vga);
     square (8,8,311,191,9,vga);
     square (9,9,310,190,10,vga);
     square (10,10,309,189,11,vga);
     square (11,11,308,188,12,vga);
     square (12,12,307,187,12,vga);
     square (13,13,306,186,11,vga);
     square (14,14,305,185,10,vga);
     square (15,15,304,184,9,vga);
     square (16,16,303,183,8,vga);
     square (17,17,302,182,7,vga);
     square (18,18,301,181,6,vga);
     square (19,19,300,180,5,vga);
     square (20,20,299,179,4,vga);
     square (21,21,298,178,3,vga);
     square (22,22,297,177,2,vga);
     square (23,23,296,176,1,vga);

     putimage (135,40,abc[3],vga);
     putimage (145,40,abc[18],vga);
     putimage (155,40,abc[21],vga);
     putimage (165,40,abc[19],vga);
     putimage (175,40,abc[8],vga);

     putimage (140,80,abc[3],vga);
     putimage (150,80,abc[15],vga);
     putimage (160,80,abc[4],vga);
     putimage (170,80,abc[5],vga);

     putimage (65,100,abc[1],vga);
     putimage (75,100,abc[4],vga);
     putimage (85,100,abc[4],vga);
     putimage (95,100,abc[9],vga);
     putimage (105,100,abc[20],vga);
     putimage (115,100,abc[9],vga);
     putimage (125,100,abc[15],vga);
     putimage (135,100,abc[14],vga);
     putimage (145,100,abc[1],vga);
     putimage (155,100,abc[12],vga);
     putimage (175,100,abc[7],vga);
     putimage (185,100,abc[18],vga);
     putimage (195,100,abc[1],vga);
     putimage (205,100,abc[16],vga);
     putimage (215,100,abc[8],vga);
     putimage (225,100,abc[9],vga);
     putimage (235,100,abc[3],vga);
     putimage (245,100,abc[19],vga);
     for a:=0 to 63 do fadefrom (temp,30);
     for a:=0 to 30 do
         begin
              delay (30);
              getcolor (159,r,g,b);
              if r>0 then r:=r-1;
              if r<0 then r:=r+1;
              if g>0 then g:=g-1;
              if g<0 then g:=g+1;
              if b>0 then b:=b-1;
              if b<0 then b:=b+1;
              setcolor (159,r,g,b);
         end;
     for a:= 0 to 63 do
         begin
              setcolor (159,a,a,a);
              delay (30);
         end;
     for a:=0 to 63 do fadeto (63,63,63,30);
end;

procedure credits02;
var a:integer;
begin
     cls (159,vga);
     square (0,0,319,199,0,vga);
     square (1,1,318,198,1,vga);
     square (2,2,317,197,3,vga);
     square (3,3,316,196,4,vga);
     square (4,4,315,195,5,vga);
     square (5,5,314,194,6,vga);
     square (6,6,313,193,7,vga);
     square (7,7,312,192,8,vga);
     square (8,8,311,191,9,vga);
     square (9,9,310,190,10,vga);
     square (10,10,309,189,11,vga);
     square (11,11,308,188,12,vga);
     square (12,12,307,187,12,vga);
     square (13,13,306,186,11,vga);
     square (14,14,305,185,10,vga);
     square (15,15,304,184,9,vga);
     square (16,16,303,183,8,vga);
     square (17,17,302,182,7,vga);
     square (18,18,301,181,6,vga);
     square (19,19,300,180,5,vga);
     square (20,20,299,179,4,vga);
     square (21,21,298,178,3,vga);
     square (22,22,297,177,2,vga);
     square (23,23,296,176,1,vga);

     putimage (110,40,abc[2],vga);
     putimage (120,40,abc[30],vga);
     putimage (130,40,abc[23],vga);
     putimage (140,40,abc[9],vga);
     putimage (150,40,abc[20],vga);
     putimage (160,40,abc[3],vga);
     putimage (170,40,abc[8],vga);
     putimage (180,40,abc[5],vga);
     putimage (190,40,abc[4],vga);

     putimage (125,80,abc[19],vga);
     putimage (135,80,abc[11],vga);
     putimage (145,80,abc[5],vga);
     putimage (155,80,abc[20],vga);
     putimage (165,80,abc[3],vga);
     putimage (175,80,abc[8],vga);

     putimage (115,100,abc[7],vga);
     putimage (125,100,abc[18],vga);
     putimage (135,100,abc[1],vga);
     putimage (145,100,abc[16],vga);
     putimage (155,100,abc[8],vga);
     putimage (165,100,abc[9],vga);
     putimage (175,100,abc[3],vga);
     putimage (185,100,abc[19],vga);

     for a:=0 to 63 do fadefrom (temp,30);
     for a:=0 to 45 do
         begin
              delay (30);
              getcolor (159,r,g,b);
              if r>63 then r:=r-1;
              if r<63 then r:=r+1;
              if g>63 then g:=g-1;
              if g<63 then g:=g+1;
              if b>63 then b:=b-1;
              if b<63 then b:=b+1;
              setcolor (159,r,g,b);
         end;
     for a:= 0 to 63 do
         begin
              setcolor (159,63-a,63-a,63-a);
              delay (30);
         end;
     for a:=0 to 63 do fadeto (0,0,0,30);
end;

procedure loadfiles;
begin
     loadpcx ('splat!.001',vp[1]);
     loadpcx ('splat!.002',vp[2]);
     correctpic;
     savepal;
end;

procedure getimages;
begin
     getimage (62,13,112,42,image[1],vp[1]);
     getimage (6,52,44,117,image[2],vp[1]);
     getimage (60,55,120,98,image[3],vp[1]);
     getimage (201,2,266,49,image[4],vp[1]);
     getimage (254,107,285,154,image[5],vp[1]);
     getimage (3,2,49,49,image[6],vp[1]);
     getimage (243,66,268,85,image[8],vp[1]);
     getimage (273,66,298,85,image[9],vp[1]);
     getimage (76,104,117,171,image[10],vp[1]);
     getimage (62,13,111,42,image[11],vp[1]);
end;

procedure blinkon;
begin
     putpixel (168,141,61,vp[2]);
     putpixel (169,142,61,vp[2]);
     putpixel (169,141,61,vp[2]);
     putpixel (168,142,61,vp[2]);
     putpixel (163,141,61,vp[2]);
     putpixel (164,142,61,vp[2]);
     putpixel (164,141,61,vp[2]);
     putpixel (163,142,61,vp[2]);
end;

procedure blinkoff;
begin
     putpixel (168,141,0,vp[2]);
     putpixel (169,142,0,vp[2]);
     putpixel (169,141,0,vp[2]);
     putpixel (168,142,0,vp[2]);
     putpixel (163,141,0,vp[2]);
     putpixel (164,142,0,vp[2]);
     putpixel (164,141,0,vp[2]);
     putpixel (163,142,0,vp[2]);
end;

procedure cloud(a:integer);
begin
     putimage (240-2*a,50,image[1],vp[2]);
     putimage (160-a,20,image[11],vp[2]);
end;

procedure flowers;
begin
     putimage (50,125,image[2],vp[2]);
     putimage (250,135,image[10],vp[2]);
end;

procedure anvil (a:integer);
begin
     putimage (135,10*a,image[3],vp[2]);
end;

procedure drops (a:integer);
begin
     putimage (125-8*a,138-10*a,image[8],vp[2]);
     putimage (185+8*a,138-10*a,image[9],vp[2]);
     putimage (115-4*a,148-4*a,image[8],vp[2]);
     putimage (185+4*a,148-4*a,image[9],vp[2]);
end;

procedure scene2;
begin
     for a:=0 to 12 do
         begin
              cloud (a+80);
              flowers;
              putimage (150,122,image[5],vp[2]);
              putimage (10,1,image[6],vp[2]);
              blinkoff;
              for b:=0 to 15 do
                  begin
                       if a= b*10 then blinkon;
                  end;
              anvil(a);
              copypage (vp[2],vga);
              delay (90);
         end;
end;

procedure scene1;
begin
     for a:=0 to 80 do
         begin
              cloud (a);
              flowers;
              putimage (150,122,image[5],vp[2]);
              putimage (10,1,image[6],vp[2]);
              blinkoff;
              for b:=0 to 15 do
                  begin
                       if a= b*10 then blinkon;
                  end;
              copypage (vp[2],vga);
              delay (90);
         end;
end;

procedure scene3;
var x,y:integer;
begin
     for a:=0 to 5 do
         begin
              cls (151,vp[2]);
              for x:=0 to 319 do for y:=170 to 199 do putpixel (x,y,175,vp[2]);
              cloud (a+92);
              flowers;
              putimage (135,138,image[4],vp[2]);
              putimage (10,1,image[6],vp[2]);
              drops (a);
              copypage (vp[2],vga);
              delay (90);
         end;
end;

procedure anvildown;
var x,y:integer;
    a,b:integer;
begin
     cls (151,vp[2]);
     for x:=0 to 319 do for y:=170 to 199 do putpixel (x,y,175,vp[2]);
     cloud (0);
     flowers;
     putimage (150,122,image[5],vp[2]);
     putimage (10,1,image[6],vp[2]);
     copypage (vp[2],vga);
     for a:=0 to 63 do fadefrom (temp,30);
     scene1;
     scene2;
     scene3;
     for a:=0 to 63 do fadeto (63,0,0,30);
end;

procedure theend;
begin
     cls (159,vga);
     square (0,0,319,199,0,vga);
     square (1,1,318,198,1,vga);
     square (2,2,317,197,3,vga);
     square (3,3,316,196,4,vga);
     square (4,4,315,195,5,vga);
     square (5,5,314,194,6,vga);
     square (6,6,313,193,7,vga);
     square (7,7,312,192,8,vga);
     square (8,8,311,191,9,vga);
     square (9,9,310,190,10,vga);
     square (10,10,309,189,11,vga);
     square (11,11,308,188,12,vga);
     square (12,12,307,187,12,vga);
     square (13,13,306,186,11,vga);
     square (14,14,305,185,10,vga);
     square (15,15,304,184,9,vga);
     square (16,16,303,183,8,vga);
     square (17,17,302,182,7,vga);
     square (18,18,301,181,6,vga);
     square (19,19,300,180,5,vga);
     square (20,20,299,179,4,vga);
     square (21,21,298,178,3,vga);
     square (22,22,297,177,2,vga);
     square (23,23,296,176,1,vga);

     putimage (135,90,abc[4],vga);
     putimage (155,90,abc[5],vga);
     putimage (165,90,abc[14],vga);
     putimage (175,90,abc[4],vga);

     for a:=0 to 63 do fadefrom (temp,30);
     for a:=0 to 30 do
         begin
              delay (30);
              getcolor (159,r,g,b);
              if r>0 then r:=r-1;
              if r<0 then r:=r+1;
              if g>0 then g:=g-1;
              if g<0 then g:=g+1;
              if b>0 then b:=b-1;
              if b<0 then b:=b+1;
              setcolor (159,r,g,b);
         end;
     for a:= 0 to 63 do
         begin
              setcolor (159,a,a,a);
              delay (30);
         end;

     for a:=0 to 63 do fadeto (63,63,63,30);

     cls (61,vga);
     for a:=0 to 16 do setcolor (a,4*a,4*a,4*a);
     for a:=0 to 99 do
         begin
              delay (10);
              square (a,a,319-a,199-a,0,vga);
         end;
     for a:=0 to 120 do putpixel (100+a,100,61,vga);
     for a:=0 to 59 do
         begin
              putpixel (100+a,100,0,vga);
              putpixel (220-a,100,0,vga);
              delay (15);
         end;
     for a:=0 to 15 do
         begin
              putpixel (160,100,a,vga);
              delay (30);
         end;
     delay (15);
     for a:=15 downto 0 do
         begin
              putpixel (160,100,a,vga);
              delay (30);
         end;
end;

begin
     loading;           {If hackers='none' then world:='better place'}
     start;             {can't you code your own stuff, you always   }
     loadfiles;
     intro;             {end up hacking someone elses suberb rotines }
     splat;             {i shall curse you with the bitchwitch bug:  }
     getimages;
     anvildown;
     credits01;         {may your feet be covered in snot and rare   }
     credits02;         {fungus! :()   You get the picture!          }
     theend;
     close;             {GO AWAY! GO PROGRAM YOUR OWN 2% ASM INTRO   }
end.
