home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FGFISH20.ZIP / FISHTANK.BAS < prev    next >
BASIC Source File  |  1995-02-12  |  10KB  |  354 lines

  1. '***********************************************************************
  2. '
  3. ' FISHTANK.BAS -- 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 FGgetimage 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 FGclpimage and FGflpimage. The
  11. ' fish are clipped at the edge of the screen. Page 1 is then copied to
  12. ' page 0 using FGcopypage. This process is repeated in a loop.
  13. '
  14. ' To compile this program and link it with Fastgraph version 4.0:
  15. '
  16. '    BC /O FISHTANK;                    (QuickBASIC 4.5)
  17. '    LINK FISHTANK,,NUL,FGQB;
  18. '
  19. '    BC /Fs /O FISHTANK;                (BASIC PDS 7.x)
  20. '    LINK FISHTANK,,NUL,FGQBX;
  21. '
  22. '    BC /O FISHTANK;                    (Visual Basic for DOS)
  23. '    LINK FISHTANK,,NUL,FGVBDOS;
  24. '
  25. ' This program also can be linked with Fastgraph/Light version 4.0 if
  26. ' you replace the FGxxx library references with FGLxxx.
  27. '
  28. ' For more examples of animation using Fastgraph, or for an evaluation
  29. ' copy of Fastgraph/Light, call DDBBS at (702) 796-7134. For Fastgraph
  30. ' voice support, call Ted Gruber Software at (702) 735-1980.
  31. '
  32. '***********************************************************************
  33.  
  34. REM $INCLUDE: 'fastgraf.bi'
  35.  
  36. DEFINT A-Z
  37.  
  38. DECLARE SUB GetFish ()
  39. DECLARE SUB GoFish  ()
  40. DECLARE SUB PutFish (FishNum,X,Y,FishDir)
  41.  
  42. DECLARE FUNCTION MIN (Value1,Value2)
  43. DECLARE FUNCTION MAX (Value1,Value2)
  44.  
  45. ' *** number of fish ***
  46.  
  47. CONST NFISH = 11
  48.  
  49. ' *** fish bitmaps ***
  50.  
  51. DIM SHARED Fishes AS STRING*5356
  52. DIM SHARED MapOffset(6), MapSize(6)
  53.  
  54. ' *** palette values ***
  55.  
  56. DATA 0,1,2,3,4,5,6,7,16,0,18,19,20,21,22,23
  57.  
  58. ' *** arrays containing locations and size of the fish ***
  59.  
  60. DIM SHARED FishX1(6), FishY1(6), FishWidth(6), FishHeight(6)
  61.  
  62. '************************************************************************
  63. '*                                                                      *
  64. '*                                 main                                 *
  65. '*                                                                      *
  66. '************************************************************************
  67.  
  68. REM make sure the system supports video mode 13 with 4 pages
  69.  
  70. IF FGtestmode(13,4) = 0 THEN
  71.    PRINT
  72.    PRINT "This program requires an EGA or VGA card"
  73.    PRINT "with at least 128k. If an EGA card is"
  74.    PRINT "present, it must be the active adapter."
  75.    STOP
  76. END IF
  77.  
  78. REM initialize the video environment
  79.  
  80. OldMode = FGgetmode
  81. FGsetmode 13
  82. FOR PaletteNumber = 0 TO 15
  83.    READ PaletteValue
  84.    FGpalette PaletteNumber, PaletteValue
  85. NEXT
  86. RANDOMIZE TIMER
  87.  
  88. REM get the coral background from a file and put it on page 2
  89.  
  90. FGsetpage 2
  91. FGmove 0, 199
  92. Status = FGshowppr("CORAL.PPR"+CHR$(0),320)
  93.  
  94. REM copy the background from page 2 to page 0, the visual page
  95.  
  96. FGcopypage 2, 0
  97.  
  98. REM get the fish
  99.  
  100. GetFish
  101.  
  102. REM make the fish go
  103.  
  104. GoFish
  105.  
  106. REM restore the original video state
  107.  
  108. FGsetmode OldMode
  109. FGreset
  110.  
  111. END
  112.  
  113. '************************************************************************
  114. '*                                                                      *
  115. '*             GetFish -- fill up the fish bitmap arrays                *
  116. '*                                                                      *
  117. '************************************************************************
  118.  
  119. SUB GetFish
  120.  
  121. DIM Temp AS STRING*1224
  122.  
  123. REM location of fish (x and y)
  124. DATA   0, 64,128,200,  0, 80
  125. DATA 199,199,199,199,150,150
  126.  
  127. REM size of fish (width and height)
  128. DATA  28, 27, 34, 28, 31, 34
  129. DATA  25, 38, 26, 30, 22, 36
  130.  
  131. REM fill up the fish location arrays
  132.  
  133. FOR FishNum = 0 TO 5
  134.    READ FishX1(FishNum)
  135. NEXT
  136. FOR FishNum = 0 TO 5
  137.    READ FishY1(FishNum)
  138. NEXT
  139. FOR FishNum = 0 TO 5
  140.    READ FishWidth(FishNum)
  141. NEXT
  142. FOR FishNum = 0 TO 5
  143.    READ FishHeight(FishNum)
  144. NEXT
  145.  
  146. REM get the fish from a file and put them on page 1
  147.  
  148. FGsetpage 1
  149. FGmove 0, 199
  150. Status = FGshowppr("FISH.PPR"+CHR$(0),320)
  151.  
  152. REM build the fish bitmaps
  153.  
  154. TotalSize = 1
  155. FOR FishNum = 0 TO 5
  156.    Size = FishWidth(FishNum) * FishHeight(FishNum)
  157.    Offset = TotalSize
  158.    TotalSize = TotalSize + Size
  159.    FGmove FishX1(FishNum), FishY1(FishNum)
  160.    FGgetimage Temp, FishWidth(FishNum), FishHeight(FishNum)
  161.    MID$(Fishes,Offset,Size) = Temp
  162.    MapOffset(FishNum) = Offset
  163.    MapSize(FishNum) = Size
  164. NEXT
  165.  
  166. END SUB
  167.  
  168. '************************************************************************
  169. '*                                                                      *
  170. '*             GoFish -- make the fish swim around                      *
  171. '*                                                                      *
  172. '************************************************************************
  173.  
  174. SUB GoFish
  175.  
  176. REM There are 11 fish total, and 6 different kinds of fish. These
  177. REM arrays keep track of what kind of fish each fish is, and how each
  178. REM fish moves:
  179.  
  180. REM Fish()   -- which fish bitmap applies to this fish?
  181. REM X()      -- starting x coordinate
  182. REM Y()      -- starting y coordinate
  183.  
  184. REM Xmin()   -- how far left (off screen) the fish can go
  185. REM Xmax()   -- how far right (off screen) the fish can go
  186. REM Xinc()   -- how fast the fish goes left and right
  187. REM Dir()    -- starting direction for each fish
  188.  
  189. REM Ymin()   -- how far up this fish can go
  190. REM Ymax()   -- how far down this fish can go
  191. REM Yinc()   -- how fast the fish moves up or down
  192. REM Yturn()  -- how long fish can go in the vertical direction
  193. REM             before stopping or turning around
  194. REM Ycount() -- counter to compare to yturn
  195.  
  196. DIM  Fish(NFISH), X(NFISH), Y(NFISH)
  197. DATA    1,   1,   2,   3,   3,   0,   0,   5,   4,   2,   3
  198. DATA -100,-150,-450,-140,-200, 520, 620,-800, 800, 800,-300
  199. DATA   40,  60, 150,  80,  70, 190, 180, 100,  30, 130,  92
  200.  
  201. DIM  Xmin(NFISH), Xmax(NFISH), Xinc(NFISH), Dir(NFISH)
  202. DATA -300,-300,-800,-200,-200,-200,-300,-900,-900,-900,-400
  203. DATA  600, 600,1100,1000,1000, 750, 800,1200,1400,1200, 900
  204. DATA    2,   2,   8,   5,   5,  -3,  -3,   7,  -8,  -9,   6
  205. DATA    0,   0,   0,   0,   0,   1,   1,   0,   1,   1,   0
  206.  
  207. DIM  Ymin(NFISH), Ymax(NFISH), Yturn(NFISH), Ycount(NFISH), Yinc(NFISH)
  208. DATA   40,  60, 120,  70,  60, 160, 160,  80,  30, 110,  72
  209. DATA   80, 100, 170, 110, 100, 199, 199, 120,  70, 150, 122
  210. DATA   50,  30,  10,  30,  20,  10,  10,  10,  30,   20, 10
  211.  
  212. DIM KeyCode AS STRING*1
  213. DIM AuxCode AS STRING*1
  214.  
  215. REM fill the arrays that control the fish movement
  216.  
  217. FOR I = 0 TO NFISH-1
  218.    READ Fish(I)
  219. NEXT
  220. FOR I = 0 TO NFISH-1
  221.    READ X(I)
  222. NEXT
  223. FOR I = 0 TO NFISH-1
  224.    READ Y(I)
  225. NEXT
  226. FOR I = 0 TO NFISH-1
  227.    READ Xmin(I)
  228. NEXT
  229. FOR I = 0 TO NFISH-1
  230.    READ Xmax(I)
  231. NEXT
  232. FOR I = 0 TO NFISH-1
  233.    READ Xinc(I)
  234. NEXT
  235. FOR I = 0 TO NFISH-1
  236.    READ Dir(I)
  237. NEXT
  238. FOR I = 0 TO NFISH-1
  239.    READ Ymin(I)
  240. NEXT
  241. FOR I = 0 TO NFISH-1
  242.    READ Ymax(I)
  243. NEXT
  244. FOR I = 0 TO NFISH-1
  245.    READ Yturn(I)
  246.    Ycount(I) = 0
  247.    Yinc(I) = 0
  248. NEXT
  249.  
  250. REM make the fish swim around
  251.  
  252. DO
  253.    ' copy the background from page 2 to page 1
  254.  
  255.    FGcopypage 2, 1
  256.  
  257.    ' put all the fish on the background
  258.  
  259.    FOR I = 0 TO NFISH-1
  260.  
  261.       FGsetpage 1
  262.       Ycount(I) = Ycount(I) + 1
  263.       IF Ycount(I) > Yturn(I) THEN
  264.          Ycount(I) = 0
  265.          Yinc(I) = (RND * 32767) MOD 3 - 1
  266.       END IF
  267.       Y(I) = Y(I) + Yinc(I)
  268.       Y(I) = MIN(Ymax(I),MAX(Y(I),Ymin(I)))
  269.  
  270.       IF X(I) >= 0 AND X(I) < 320 THEN
  271.          PutFish Fish(I), X(I), Y(I), Dir(I)
  272.       ELSEIF X(I) < 0 AND X(I) > -72 THEN
  273.          FGtransfer 0, 71, 0, 199, 104, 199, 1, 3
  274.          FGsetpage 3
  275.          PutFish Fish(I), X(I)+104, Y(I), Dir(I)
  276.          FGtransfer 104, 175, 0, 199, 0, 199, 3, 1
  277.       END IF
  278.       X(I) = X(I) + Xinc(I)
  279.       IF X(I) <= Xmin(I) OR X(I) >= Xmax(I) THEN
  280.          Xinc(I) = -Xinc(I)
  281.          Dir(I) = 1 - Dir(I)
  282.       END IF
  283.    NEXT
  284.  
  285.    ' copy page 1 to page 0
  286.  
  287.    FGsetpage 0
  288.    FGcopypage 1, 0
  289.  
  290.    ' intercept a keystroke, if it is escape exit the program
  291.  
  292.    FGintkey KeyCode, AuxCode
  293.  
  294. LOOP UNTIL KeyCode = CHR$(27)
  295.  
  296. END SUB
  297.  
  298. '************************************************************************
  299. '*                                                                      *
  300. '*       PutFish -- draw one of the six fish anywhere you want          *
  301. '*                                                                      *
  302. '************************************************************************
  303.  
  304. SUB PutFish(FishNum,X,Y,FishDir)
  305.  
  306. REM move to position where the fish will appear
  307.  
  308. FGmove X, Y
  309.  
  310. REM draw a left- or right-facing fish, depending on FishDir
  311.  
  312. Offset = MapOffset(FishNum)
  313. Size = MapSize(FishNum)
  314.  
  315. IF FishDir = 0 THEN
  316.    FGflpimage MID$(Fishes,Offset,Size), FishWidth(FishNum), FishHeight(FishNum)
  317. ELSE
  318.    FGclpimage MID$(Fishes,Offset,Size), FishWidth(FishNum), FishHeight(FishNum)
  319. END IF
  320.  
  321. END SUB
  322.  
  323. '************************************************************************
  324. '*                                                                      *
  325. '*            min -- determine the smaller of two integer values        *
  326. '*                                                                      *
  327. '************************************************************************
  328.  
  329. FUNCTION MIN (Value1, Value2)
  330.  
  331. IF Value1 <= Value2 THEN
  332.   MIN = Value1
  333. ELSE
  334.   MIN = Value2
  335. END IF
  336.  
  337. END FUNCTION
  338.  
  339. '************************************************************************
  340. '*                                                                      *
  341. '*            max -- determine the larger of two integer values         *
  342. '*                                                                      *
  343. '************************************************************************
  344.  
  345. FUNCTION MAX (Value1, Value2)
  346.  
  347. IF Value1 >= Value2 THEN
  348.   MAX = Value1
  349. ELSE
  350.   MAX = Value2
  351. END IF
  352.  
  353. END FUNCTION
  354.