Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. unit LRLSprites;
  2.  
  3. {$mode objfpc}
  4. {$i-}
  5.  
  6.  
  7. interface
  8.  
  9.  
  10. uses
  11.   SysUtils,
  12.   LRLRoutines;
  13.  
  14. {
  15.   all coordinates in standard style:
  16.   0          +
  17.   0 +---------->  x
  18.   |
  19.   |
  20.   |
  21.   |
  22.   + v
  23.  
  24.   y
  25. }
  26.  
  27. type
  28.   TLRLImage = packed record
  29.     Data: Pointer; { standard 256-colour image data }
  30.     Size: Word;    { size of image (for destruction) }
  31.   end;
  32.  
  33.   PLRLSprite = ^TLRLSprite;
  34.  
  35.   TLRLSprite = packed record
  36.     Image:      array[1..12] of TLRLImage; { moving image }
  37.     ImageCount: Byte; { how many images there }
  38.   end;
  39.  
  40.  
  41. type
  42.   TButton = packed record
  43.     Lit:           Boolean;
  44.     DarkIcon:      Pointer;
  45.     LightIcon:     Pointer;
  46.     DarkIconSize:  Word;
  47.     LightIconSize: Word;
  48.     x1, y1:        Integer;
  49.     x2, y2:        Integer;
  50.     Command:       Word;
  51.   end;
  52.  
  53.  
  54. var
  55.   ImageFile:       File;
  56.   LRLEnvironment:  array[1..20] of TLRLSprite;
  57.   LRLFigure:       array[1..4, 1..9] of TLRLSprite;
  58.   LRLDecoration:   array[1..1] of TLRLSprite;
  59.   LRLPalette:      Pointer;
  60.   LRLScreen:       Pointer;
  61.   LRLMenuPalette:  Pointer;
  62.   LRLLogo:         Pointer;
  63.   LRLFont:         Pointer;
  64.   LRLFontBuffer:   Pointer;
  65.   LRLMousePointer: Pointer;
  66.   LRLImagesFilePosition: longint;
  67.   LRLEditorButton: array[1..6] of TButton;
  68.  
  69.  
  70. procedure ImagesInitialize;
  71. procedure ImagesDeinitialize;
  72.  
  73.  
  74. implementation
  75.  
  76.  
  77. const
  78.   ImageFileName = 'LRL.IMG';
  79.   ImageFileHeader: ShortString = 'Lode Runner Live Images'#26;
  80.  
  81.   ERR_OPENFILE = 'Невозможно открыть файл картинок';
  82.   ERR_BADFILE  = 'Неверный или поврежденный файл картинок';
  83.  
  84.  
  85. procedure LoadImages;
  86. var
  87.   InBuffer: Pointer;
  88.   i, j, k, l, x, y: Word;
  89.   a, b, c:  Byte;
  90. begin
  91.   GetMem(InBuffer, $FFF0);
  92.  
  93.   AssignFile(ImageFile, ImageFileName);
  94.   Reset(ImageFile, 1);
  95.   if IOResult <> 0 then
  96.     raise Exception.Create(ERR_OPENFILE);
  97.  
  98.   BlockRead(ImageFile, InBuffer^, 24, k);
  99.   if (IOResult <> 0) or not DataIdentical(InBuffer^, ImageFileHeader[1], 24, 0, 0) then
  100.     raise Exception.Create(ERR_BADFILE);
  101.  
  102.   { load palette }
  103.   GetMem(LRLPalette, 768);
  104.   BlockRead(ImageFile, LRLPalette^, 768, k);
  105.  
  106.   { figures loading loop }
  107.   for i := 1 to 9 do
  108.   begin
  109.     BlockRead(ImageFile, a, 1, k);
  110.     LRLFigure[1, i].ImageCount := a;
  111.     for j := 1 to a do
  112.     begin
  113.       GetMem(LRLFigure[1, i].Image[j].Data, 104);
  114.       BlockRead(ImageFile, LRLFigure[1, i].Image[j].Data^, 104, k);
  115.       x := DataWordGet(LRLFigure[1, i].Image[j].Data^, 0);
  116.       y := DataWordGet(LRLFigure[1, i].Image[j].Data^, 2);
  117.       LRLFigure[1, i].Image[j].Size := x * y + 4;
  118.       for l := 2 to 4 do
  119.       begin
  120.         LRLFigure[l, i].Image[j].Size := LRLFigure[1, i].Image[j].Size;
  121.         LRLFigure[l, i].ImageCount := a;
  122.         GetMem(LRLFigure[l, i].Image[j].Data, LRLFigure[l, i].Image[j].Size);
  123.         DataMove(LRLFigure[1, i].Image[j].Data^, LRLFigure[l, i].Image[j].Data^, LRLFigure[l, i].Image[j].Size, 0, 0);
  124.         DataAdd(LRLFigure[l, i].Image[j].Data^, LRLFigure[l, i].Image[j].Size, (l - 1) shl 5, 4);
  125.       end;
  126.     end;
  127.   end;
  128.  
  129.   { decoration loading loop }
  130.   for i := 1 to 1 do
  131.   begin
  132.     BlockRead(ImageFile, a, 1, k);
  133.     LRLDecoration[i].ImageCount := a;
  134.     for j := 1 to a do
  135.     begin
  136.       GetMem(LRLDecoration[i].Image[j].Data, 104);
  137.       BlockRead(ImageFile, LRLDecoration[i].Image[j].Data^, 104, k);
  138.       x := DataWordGet(LRLDecoration[i].Image[j].Data^, 0);
  139.       y := DataWordGet(LRLDecoration[i].Image[j].Data^, 2);
  140.       LRLDecoration[i].Image[j].Size := x * y + 4;
  141.     end;
  142.   end;
  143.  
  144.   { environment loading loop }
  145.   for i := 1 to 9 do
  146.   begin
  147.     BlockRead(ImageFile, a, 1, k);
  148.     LRLEnvironment[i].ImageCount := a;
  149.     for j := 1 to a do
  150.     begin
  151.       GetMem(LRLEnvironment[i].Image[j].Data, 104);
  152.       BlockRead(ImageFile, LRLEnvironment[i].Image[j].Data^, 104, k);
  153.       x := DataWordGet(LRLEnvironment[i].Image[j].Data^, 0);
  154.       y := DataWordGet(LRLEnvironment[i].Image[j].Data^, 2);
  155.       LRLEnvironment[i].Image[j].Size := x * y + 4;
  156.     end;
  157.   end;
  158.  
  159.   y := 181;
  160.   x := 212;
  161.  
  162.   for i := 1 to 6 do
  163.   begin
  164.     if i = 4 then
  165.     begin
  166.       y := 191;
  167.       x := 212;
  168.     end;
  169.  
  170.     LRLEditorButton[i].x1  := x;
  171.     LRLEditorButton[i].y1  := y;
  172.     LRLEditorButton[i].x2  := x + 32;
  173.     LRLEditorButton[i].y2  := y + 9;
  174.     LRLEditorButton[i].Lit := False;
  175.     LRLEditorButton[i].Command := i;
  176.     LRLEditorButton[i].DarkIconSize := 292;
  177.     LRLEditorButton[i].LightIconSize := 292;
  178.  
  179.     GetMem(LRLEditorButton[i].DarkIcon, LRLEditorButton[i].DarkIconSize);
  180.     GetMem(LRLEditorButton[i].LightIcon, LRLEditorButton[i].LightIconSize);
  181.     BlockRead(ImageFile, LRLEditorButton[i].LightIcon^, 292, l);
  182.     BlockRead(ImageFile, LRLEditorButton[i].DarkIcon^, 292, l);
  183.  
  184.     Inc(x, 33);
  185.   end;
  186.  
  187.   { load font }
  188.   GetMem(LRLFont, 20455);
  189.   BlockRead(ImageFile, LRLFont^, 20455, k);
  190.  
  191.   { load Pointer }
  192.   GetMem(LRLMousePointer, 174);
  193.   BlockRead(ImageFile, LRLMousePointer^, 174, k);
  194.  
  195.   { load palette }
  196.   GetMem(LRLMenuPalette, 768);
  197.   BlockRead(ImageFile, LRLMenuPalette^, 768, k);
  198.  
  199.   { load logo }
  200.   GetMem(LRLLogo, 12524);
  201.   BlockRead(ImageFile, LRLLogo^, 12524, k);
  202.  
  203.   LRLImagesFilePosition := FilePos(ImageFile);
  204.   FreeMem(InBuffer, $FFF0);
  205. end;
  206.  
  207.  
  208. procedure ImagesInitialize;
  209. begin
  210.   LoadImages;
  211.   GetMem(LRLScreen, 64000);
  212.   GetMem(LRLFontBuffer, 32000);
  213. end;
  214.  
  215.  
  216. procedure ImagesDeinitialize;
  217. var
  218.   i, j, l: Integer;
  219. begin
  220.   FreeMem(LRLPalette, 768);
  221.  
  222.   for i := 1 to 9 do
  223.   for j := 1 to LRLFigure[1, i].ImageCount do
  224.   begin
  225.     FreeMem(LRLFigure[1, i].Image[j].Data, 104);
  226.     for l := 2 to 4 do
  227.       FreeMem(LRLFigure[l, i].Image[j].Data, LRLFigure[l, i].Image[j].Size);
  228.   end;
  229.  
  230.   for i := 1 to 1 do
  231.   for j := 1 to LRLDecoration[i].ImageCount do
  232.     FreeMem(LRLDecoration[i].Image[j].Data, 104);
  233.  
  234.   for i := 1 to 9 do
  235.   for j := 1 to LRLEnvironment[i].ImageCount do
  236.     FreeMem(LRLEnvironment[i].Image[j].Data, 104);
  237.  
  238.   for i := 1 to 6 do
  239.   begin
  240.     FreeMem(LRLEditorButton[i].DarkIcon, LRLEditorButton[i].DarkIconSize);
  241.     FreeMem(LRLEditorButton[i].LightIcon, LRLEditorButton[i].LightIconSize);
  242.   end;
  243.  
  244.   FreeMem(LRLFont, 20455);
  245.   FreeMem(LRLMousePointer, 174);
  246.   FreeMem(LRLMenuPalette, 768);
  247.   FreeMem(LRLLogo, 12524);
  248.   FreeMem(LRLScreen, 64000);
  249.   FreeMem(LRLFontBuffer, 32000);
  250.  
  251.   Close(ImageFile);
  252. end;
  253.  
  254.  
  255. end.
  256.