home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FGFISH20.ZIP / FISHTANK.PAS < prev   
Pascal/Delphi Source File  |  1995-02-12  |  10KB  |  342 lines

  1. {***********************************************************************
  2.  
  3. FISHTANK.PAS -- This program demonstrates multi-object non-destructive
  4. animation. The coral background is displayed on page 2 and copied to
  5. page 0, the visual page. A packed pixel run file containing the 6 fish
  6. is displayed on page 1, and then fg_getimage is used to load the fish
  7. into the fish bitmaps.
  8.  
  9. To make the fish move, the background is copied to page 1 and the fish
  10. are put over the background using fg_clpimage and fg_flpimage. The
  11. fish are clipped at the edge of the screen. Page 1 is then copied to
  12. page 0 using fg_copypage. This process is repeated in a loop.
  13.  
  14. To compile this program and link it with Fastgraph or Fastgraph/Light
  15. 4.0:
  16.  
  17.    TPC FISHTANK
  18.  
  19. For more examples of animation using Fastgraph, or for an evaluation
  20. copy of Fastgraph/Light, call DDBBS at (702) 796-7134. For Fastgraph
  21. voice support, call Ted Gruber Software at (702) 735-1980.
  22.  
  23. ***********************************************************************}
  24.  
  25. program fishtank;
  26. uses fgmain, fgbitmap, fgmisc, fgpr;
  27.  
  28. var
  29.  
  30.   old_mode : integer;
  31.   status   : integer;
  32.  
  33.   { fish bitmaps }
  34.  
  35.   fish1 : array[0..699]  of byte;
  36.   fish2 : array[0..1025] of byte;
  37.   fish3 : array[0..883]  of byte;
  38.   fish4 : array[0..839]  of byte;
  39.   fish5 : array[0..681]  of byte;
  40.   fish6 : array[0..1223] of byte;
  41.  
  42. const
  43.  
  44.   { palette values }
  45.  
  46.   colors : array[0..15] of integer = (0,1,2,3,4,5,6,7,16,0,18,19,20,21,22,23);
  47.  
  48.   { number of fish }
  49.  
  50.   NFISH = 11;
  51.  
  52.   { location of fish x & y }
  53.  
  54.   fish_x1 : array[0..5] of integer = (0,   64,128,200,  0, 80);
  55.   fish_y1 : array[0..5] of integer = (199,199,199,199,150,150);
  56.  
  57.   { size of fish (width and height) }
  58.  
  59.   width   : array[0..5] of integer = ( 28, 27, 34, 28, 31, 34);
  60.   height  : array[0..5] of integer = ( 25, 38, 26, 30, 22, 36);
  61.  
  62.   { for convenience, an array of pointers to fish bitmaps }
  63.  
  64.   fishes : array[0..5] of ^byte = (@fish1,@fish2,@fish3,@fish4,@fish5,@fish6);
  65.  
  66. {
  67. ************************************************************************
  68. *                                                                      *
  69. *            min -- determine the smaller of two integer values        *
  70. *                                                                      *
  71. ************************************************************************
  72. }
  73.  
  74. function min (value1, value2 : integer) : integer;
  75.  
  76. begin
  77.  
  78.   if (value1 <= value2) then
  79.     min := value1
  80.   else
  81.     min := value2;
  82.  
  83. end;
  84.  
  85. {
  86. ************************************************************************
  87. *                                                                      *
  88. *            max -- determine the larger of two integer values         *
  89. *                                                                      *
  90. ************************************************************************
  91. }
  92.  
  93. function max (value1, value2 : integer) : integer;
  94.  
  95. begin
  96.  
  97.   if (value1 >= value2) then
  98.     max := value1
  99.   else
  100.     max := value2;
  101.  
  102. end;
  103.  
  104. {
  105. ************************************************************************
  106. *                                                                      *
  107. *            get_fish -- fill up the fish bitmap arrays                *
  108. *                                                                      *
  109. ************************************************************************
  110. }
  111.  
  112. procedure get_fish;
  113.  
  114. var
  115.  
  116.   fish_num : integer;
  117.  
  118. begin
  119.  
  120.   { read the fish from a packed pixel run file and display them on page 1 }
  121.  
  122.   fg_setpage(1);
  123.   fg_move(0,199);
  124.   status := fg_showppr('FISH.PPR'+chr(0),320);
  125.  
  126.   { build the fish bitmaps }
  127.  
  128.   for fish_num := 0 to 5 do
  129.   begin
  130.     fg_move(fish_x1[fish_num],fish_y1[fish_num]);
  131.     fg_getimage(fishes[fish_num]^,width[fish_num],height[fish_num]);
  132.   end;
  133.  
  134. end;
  135.  
  136. {
  137. ************************************************************************
  138. *                                                                      *
  139. *      put_fish -- draw one of the six fish anywhere you want          *
  140. *                                                                      *
  141. ************************************************************************
  142. }
  143.  
  144. procedure put_fish (fish_num, x, y, fish_dir : integer);
  145.  
  146. begin
  147.  
  148.   { move to position where the fish will appear }
  149.  
  150.   fg_move(x,y);
  151.  
  152.   { draw a left- or right-facing fish, depending on fish_dir }
  153.  
  154.   if (fish_dir = 0) then
  155.     fg_flpimage(fishes[fish_num]^,width[fish_num],height[fish_num])
  156.   else
  157.     fg_clpimage(fishes[fish_num]^,width[fish_num],height[fish_num]);
  158.  
  159. end;
  160.  
  161. {
  162. ************************************************************************
  163. *                                                                      *
  164. *             go_fish -- make the fish swim around                     *
  165. *                                                                      *
  166. ************************************************************************
  167. }
  168.  
  169. procedure go_fish;
  170.  
  171. type
  172.  
  173.   fish_array = array[0..NFISH-1] of integer;
  174.  
  175. const
  176. {
  177. *   There are 11 fish total, and 6 different kinds of fish. These
  178. *   arrays keep track of what kind of fish each fish is, and how each
  179. *   fish moves:
  180. *
  181. *   fish()   -- which fish bitmap applies to this fish?
  182. *   x()      -- starting x coordinate
  183. *   y()      -- starting y coordinate
  184. *
  185. *   xmin()   -- how far left (off screen) the fish can go
  186. *   xmax()   -- how far right (off screen) the fish can go
  187. *   xinc()   -- how fast the fish goes left and right
  188. *   dir()    -- starting direction for each fish
  189. *
  190. *   ymin()   -- how far up this fish can go
  191. *   ymax()   -- how far down this fish can go
  192. *   yinc()   -- how fast the fish moves up or down
  193. *   yturn()  -- how long fish can go in the vertical direction
  194. *               before stopping or turning around
  195. *   ycount() -- counter to compare to yturn
  196. }
  197.  
  198.   fish   : fish_array =
  199.                 (   1,   1,   2,   3,   3,   0,   0,   5,   4,   2,   3);
  200.   x      : fish_array =
  201.                 (-100,-150,-450,-140,-200, 520, 620,-800, 800, 800,-300);
  202.   y      : fish_array =
  203.                 (  40,  60, 150,  80,  70, 190, 180, 100,  30, 130,  92);
  204.  
  205.   xmin   : fish_array =
  206.                 (-300,-300,-800,-200,-200,-200,-300,-900,-900,-900,-400);
  207.   xmax   : fish_array =
  208.                 ( 600, 600,1100,1000,1000, 750, 800,1200,1400,1200, 900);
  209.   xinc   : fish_array =
  210.                 (   2,   2,   8,   5,   5,  -3,  -3,   7,  -8,  -9,   6);
  211.   dir    : fish_array =
  212.                 (   0,   0,   0,   0,   0,   1,   1,   0,   1,   1,   0);
  213.  
  214.   ymin   : fish_array =
  215.                 (  40,  60, 120,  70,  60, 160, 160,  80,  30, 110,  72);
  216.   ymax   : fish_array =
  217.                 (  80, 100, 170, 110, 100, 199, 199, 120,  70, 150, 122);
  218.   yturn  : fish_array =
  219.                 (  50,  30,  10,  30,  20,  10,  10,  10,  30,   20, 10);
  220.   ycount : fish_array =
  221.                 (   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0);
  222.   yinc   : fish_array =
  223.                 (   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0);
  224.  
  225. var
  226.  
  227.   i : integer;
  228.   key, aux : byte;
  229.  
  230. begin
  231.  
  232.   { make the fish swim around }
  233.  
  234.   repeat
  235.   begin
  236.  
  237.     { copy the background from page 2 to page 1 }
  238.  
  239.     fg_copypage(2,1);
  240.  
  241.     { put all the fish on the background }
  242.  
  243.     for i := 0 to NFISH-1 do
  244.     begin
  245.       fg_setpage(1);
  246.       inc(ycount[i]);
  247.       if (ycount[i] > yturn[i]) then
  248.       begin
  249.          ycount[i] := 0;
  250.          yinc[i] := random(3) - 1;
  251.       end;
  252.       inc(y[i],yinc[i]);
  253.       y[i] := min(ymax[i],max(y[i],ymin[i]));
  254.  
  255.       if (x[i] >= 0) and (x[i] < 320) then
  256.         put_fish(fish[i],x[i],y[i],dir[i])
  257.       else if (x[i] < 0) and (x[i] > -72) then
  258.       begin
  259.         fg_transfer(0,71,0,199,104,199,1,3);
  260.         fg_setpage(3);
  261.         put_fish(fish[i],x[i]+104,y[i],dir[i]);
  262.         fg_transfer(104,175,0,199,0,199,3,1);
  263.       end;
  264.       inc(x[i],xinc[i]);
  265.       if (x[i] <= xmin[i]) or (x[i] >= xmax[i]) then
  266.       begin
  267.         xinc[i] := -xinc[i];
  268.         dir[i] := 1 - dir[i];
  269.       end;
  270.     end;
  271.  
  272.     { copy page 1 to page 0 }
  273.  
  274.     fg_setpage(0);
  275.     fg_copypage(1,0);
  276.  
  277.     { intercept a keystroke, if it is escape exit the program }
  278.  
  279.     fg_intkey(key,aux);
  280.  
  281.   end;
  282.   until (key = 27);
  283.  
  284. end;
  285.  
  286. {
  287. ************************************************************************
  288. *                                                                      *
  289. *                                 main                                 *
  290. *                                                                      *
  291. ************************************************************************
  292. }
  293.  
  294. begin
  295.  
  296.   { in case we're compiling for protected mode }
  297.  
  298.   fg_initpm;
  299.  
  300.   { make sure the system supports video mode 13 with 4 pages }
  301.  
  302.   if (fg_testmode(13,4) = 0) then
  303.   begin
  304.     writeln;
  305.     writeln('This program requires an EGA or VGA card');
  306.     writeln('with at least 128k. If an EGA card is');
  307.     writeln('present, it must be the active adapter.');
  308.     halt;
  309.   end;
  310.  
  311.   { initialize the video environment }
  312.  
  313.   old_mode := fg_getmode;
  314.   fg_setmode(13);
  315.   fg_palettes(colors);
  316.   randomize;
  317.  
  318.   { get the coral background from a file and put it on page 2 }
  319.  
  320.   fg_setpage(2);
  321.   fg_move(0,199);
  322.   status := fg_showppr('CORAL.PPR'+chr(0),320);
  323.  
  324.   { copy the background from page 2 to page 0, the visual page }
  325.  
  326.   fg_copypage(2,0);
  327.  
  328.   { get the fish }
  329.  
  330.   get_fish;
  331.  
  332.   { make the fish go }
  333.  
  334.   go_fish;
  335.  
  336.   { restore the original video state }
  337.  
  338.   fg_setmode(old_mode);
  339.   fg_reset;
  340.  
  341. end.
  342.