Advertisement
LBASIC

QBasic Gorillas - Source Code

Mar 19th, 2023 (edited)
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 31.10 KB | Source Code | 0 0
  1. '                         Q B a s i c   G o r i l l a s
  2.  
  3. '
  4.  
  5. '                      Copyright (C) IBM Corporation 1991
  6.  
  7. '
  8.  
  9. ' Your mission is to hit your opponent with the exploding banana
  10.  
  11. ' by varying the angle and power of your throw, taking into account
  12.  
  13. ' wind speed, gravity, and the city skyline.
  14.  
  15. '
  16.  
  17. ' Speed of this game is determined by the constant SPEEDCONST.  If the
  18.  
  19. ' program is too slow or too fast adjust the "CONST SPEEDCONST = 500" line
  20.  
  21. ' below.  The larger the number the faster the game will go.
  22.  
  23. '
  24.  
  25. ' To run this game, press Shift+F5.
  26.  
  27. '
  28.  
  29. ' To exit QBasic, press Alt, F, X.
  30.  
  31. '
  32.  
  33. ' To get help on a BASIC keyword, move the cursor to the keyword and press
  34.  
  35. ' F1 or click the right mouse button.
  36.  
  37. '
  38.  
  39.  
  40.  
  41. 'Set default data type to integer for faster game play
  42.  
  43. DEFINT A-Z
  44.  
  45.  
  46.  
  47. 'Sub Declarations
  48.  
  49. DECLARE SUB DoSun (Mouth)
  50.  
  51. DECLARE SUB SetScreen ()
  52.  
  53. DECLARE SUB EndGame ()
  54.  
  55. DECLARE SUB Center (Row, Text$)
  56.  
  57. DECLARE SUB Intro ()
  58.  
  59. DECLARE SUB SparklePause ()
  60.  
  61. DECLARE SUB GetInputs (Player1$, Player2$, NumGames)
  62.  
  63. DECLARE SUB PlayGame (Player1$, Player2$, NumGames)
  64.  
  65. DECLARE SUB DoExplosion (x#, y#)
  66.  
  67. DECLARE SUB MakeCityScape (BCoor() AS ANY)
  68.  
  69. DECLARE SUB PlaceGorillas (BCoor() AS ANY)
  70.  
  71. DECLARE SUB UpdateScores (Record(), PlayerNum, Results)
  72.  
  73. DECLARE SUB DrawGorilla (x, y, arms)
  74.  
  75. DECLARE SUB GorillaIntro (Player1$, Player2$)
  76.  
  77. DECLARE SUB Rest (t#)
  78.  
  79. DECLARE SUB VictoryDance (Player)
  80.  
  81. DECLARE SUB ClearGorillas ()
  82.  
  83. DECLARE SUB DrawBan (xc#, yc#, r, bc)
  84.  
  85. DECLARE FUNCTION Scl (n!)
  86.  
  87. DECLARE FUNCTION GetNum# (Row, Col)
  88.  
  89. DECLARE FUNCTION DoShot (PlayerNum, x, y)
  90.  
  91. DECLARE FUNCTION ExplodeGorilla (x#, y#)
  92.  
  93. DECLARE FUNCTION Getn# (Row, Col)
  94.  
  95. DECLARE FUNCTION PlotShot (StartX, StartY, Angle#, Velocity, PlayerNum)
  96.  
  97. DECLARE FUNCTION CalcDelay! ()
  98.  
  99.  
  100.  
  101. 'Make all arrays Dynamic
  102.  
  103. '$DYNAMIC
  104.  
  105.  
  106.  
  107.  
  108.  
  109. 'User-Defined TYPEs
  110.  
  111. TYPE XYPoint
  112.  
  113.   XCoor AS INTEGER
  114.  
  115.   YCoor AS INTEGER
  116.  
  117. END TYPE
  118.  
  119.  
  120.  
  121. 'Constants
  122.  
  123. CONST SPEEDCONST = 500
  124.  
  125. CONST TRUE = -1
  126.  
  127. CONST FALSE = NOT TRUE
  128.  
  129. CONST HITSELF = 1
  130.  
  131. CONST BACKATTR = 0
  132.  
  133. CONST OBJECTCOLOR = 1
  134.  
  135. CONST WINDOWCOLOR = 14
  136.  
  137. CONST SUNATTR = 3
  138.  
  139. CONST SUNHAPPY = FALSE
  140.  
  141. CONST SUNSHOCK = TRUE
  142.  
  143. CONST RIGHTUP = 1
  144.  
  145. CONST LEFTUP = 2
  146.  
  147. CONST ARMSDOWN = 3
  148.  
  149.  
  150.  
  151. 'Global Variables
  152.  
  153. DIM SHARED GorillaX(1 TO 2)  'Location of the two gorillas
  154.  
  155. DIM SHARED GorillaY(1 TO 2)
  156.  
  157. DIM SHARED LastBuilding
  158.  
  159.  
  160.  
  161. DIM SHARED pi#
  162.  
  163. DIM SHARED LBan&(x), RBan&(x), UBan&(x), DBan&(x) 'Graphical picture of banana
  164.  
  165. DIM SHARED GorD&(120)        'Graphical picture of Gorilla arms down
  166.  
  167. DIM SHARED GorL&(120)        'Gorilla left arm raised
  168.  
  169. DIM SHARED GorR&(120)        'Gorilla right arm raised
  170.  
  171.  
  172.  
  173. DIM SHARED gravity#
  174.  
  175. DIM SHARED Wind
  176.  
  177.  
  178.  
  179. 'Screen Mode Variables
  180.  
  181. DIM SHARED ScrHeight
  182.  
  183. DIM SHARED ScrWidth
  184.  
  185. DIM SHARED Mode
  186.  
  187. DIM SHARED MaxCol
  188.  
  189.  
  190.  
  191. 'Screen Color Variables
  192.  
  193. DIM SHARED ExplosionColor
  194.  
  195. DIM SHARED SunColor
  196.  
  197. DIM SHARED BackColor
  198.  
  199. DIM SHARED SunHit
  200.  
  201.  
  202.  
  203. DIM SHARED SunHt
  204.  
  205. DIM SHARED GHeight
  206.  
  207. DIM SHARED MachSpeed AS SINGLE
  208.  
  209.  
  210.  
  211.   DEF FnRan (x) = INT(RND(1) * x) + 1
  212.  
  213.   DEF SEG = 0                         ' Set NumLock to ON
  214.  
  215.   KeyFlags = PEEK(1047)
  216.  
  217.   IF (KeyFlags AND 32) = 0 THEN
  218.  
  219.     POKE 1047, KeyFlags OR 32
  220.  
  221.   END IF
  222.  
  223.   DEF SEG
  224.  
  225.  
  226.  
  227.   GOSUB InitVars
  228.  
  229.   Intro
  230.  
  231. spam:
  232.  
  233.   GetInputs Name1$, Name2$, NumGames
  234.  
  235.   GorillaIntro Name1$, Name2$
  236.  
  237.   PlayGame Name1$, Name2$, NumGames
  238.  
  239.  
  240.  
  241. LOCATE 11, 24
  242.  
  243. COLOR 5
  244.  
  245. PRINT "Would you like to play again?"
  246.  
  247. COLOR 7
  248.  
  249. a = 1
  250.  
  251. DO
  252.  
  253. again$ = INKEY$
  254.  
  255. LOOP UNTIL (again$ = "y") OR (again$ = "n")
  256.  
  257. CLS
  258.  
  259. IF again$ = "y" THEN GOTO spam
  260.  
  261.  
  262.  
  263.  
  264.  
  265.   DEF SEG = 0                         ' Restore NumLock state
  266.  
  267.   POKE 1047, KeyFlags
  268.  
  269.   DEF SEG
  270.  
  271. END
  272.  
  273.  
  274.  
  275.  
  276.  
  277. CGABanana:
  278.  
  279.   'BananaLeft
  280.  
  281.   DATA 327686, -252645316, 60
  282.  
  283.   'BananaDown
  284.  
  285.   DATA 196618, -1057030081, 49344
  286.  
  287.   'BananaUp
  288.  
  289.   DATA 196618, -1056980800, 63
  290.  
  291.   'BananaRight
  292.  
  293.   DATA 327686,  1010580720, 240
  294.  
  295.  
  296.  
  297. EGABanana:
  298.  
  299.   'BananaLeft
  300.  
  301.   DATA 458758,202116096,471604224,943208448,943208448,943208448,471604224,202116096,0
  302.  
  303.   'BananaDown
  304.  
  305.   DATA 262153, -2134835200, -2134802239, -2130771968, -2130738945,8323072, 8323199, 4063232, 4063294
  306.  
  307.   'BananaUp
  308.  
  309.   DATA 262153, 4063232, 4063294, 8323072, 8323199, -2130771968, -2130738945, -2134835200,-2134802239
  310.  
  311.   'BananaRight
  312.  
  313.   DATA 458758, -1061109760, -522133504, 1886416896, 1886416896, 1886416896,-522133504,-1061109760,0
  314.  
  315.  
  316.  
  317. InitVars:
  318.  
  319.   pi# = 4 * ATN(1#)
  320.  
  321.  
  322.  
  323.   'This is a clever way to pick the best graphics mode available
  324.  
  325.   ON ERROR GOTO ScreenModeError
  326.  
  327.   Mode = 9
  328.  
  329.   SCREEN Mode
  330.  
  331.   ON ERROR GOTO PaletteError
  332.  
  333.   IF Mode = 9 THEN PALETTE 4, 0   'Check for 64K EGA
  334.  
  335.   ON ERROR GOTO 0
  336.  
  337.  
  338.  
  339.   MachSpeed = CalcDelay
  340.  
  341.  
  342.  
  343.   IF Mode = 9 THEN
  344.  
  345.     ScrWidth = 640
  346.  
  347.     ScrHeight = 350
  348.  
  349.     GHeight = 25
  350.  
  351.     RESTORE EGABanana
  352.  
  353.     REDIM LBan&(8), RBan&(8), UBan&(8), DBan&(8)
  354.  
  355.  
  356.  
  357.     FOR i = 0 TO 8
  358.  
  359.       READ LBan&(i)
  360.  
  361.     NEXT i
  362.  
  363.  
  364.  
  365.     FOR i = 0 TO 8
  366.  
  367.       READ DBan&(i)
  368.  
  369.     NEXT i
  370.  
  371.  
  372.  
  373.     FOR i = 0 TO 8
  374.  
  375.       READ UBan&(i)
  376.  
  377.     NEXT i
  378.  
  379.  
  380.  
  381.     FOR i = 0 TO 8
  382.  
  383.       READ RBan&(i)
  384.  
  385.     NEXT i
  386.  
  387.  
  388.  
  389.     SunHt = 39
  390.  
  391.  
  392.  
  393.   ELSE
  394.  
  395.  
  396.  
  397.     ScrWidth = 320
  398.  
  399.     ScrHeight = 200
  400.  
  401.     GHeight = 12
  402.  
  403.     RESTORE CGABanana
  404.  
  405.     REDIM LBan&(2), RBan&(2), UBan&(2), DBan&(2)
  406.  
  407.     REDIM GorL&(20), GorD&(20), GorR&(20)
  408.  
  409.  
  410.  
  411.     FOR i = 0 TO 2
  412.  
  413.       READ LBan&(i)
  414.  
  415.     NEXT i
  416.  
  417.     FOR i = 0 TO 2
  418.  
  419.       READ DBan&(i)
  420.  
  421.     NEXT i
  422.  
  423.     FOR i = 0 TO 2
  424.  
  425.       READ UBan&(i)
  426.  
  427.     NEXT i
  428.  
  429.     FOR i = 0 TO 2
  430.  
  431.       READ RBan&(i)
  432.  
  433.     NEXT i
  434.  
  435.  
  436.  
  437.     MachSpeed = MachSpeed * 1.3
  438.  
  439.     SunHt = 20
  440.  
  441.   END IF
  442.  
  443. RETURN
  444.  
  445.  
  446.  
  447. ScreenModeError:
  448.  
  449.   IF Mode = 1 THEN
  450.  
  451.     CLS
  452.  
  453.     LOCATE 10, 5
  454.  
  455.     PRINT "Sorry, you must have CGA, EGA color, or VGA graphics to play GORILLA.BAS"
  456.  
  457.     END
  458.  
  459.   ELSE
  460.  
  461.     Mode = 1
  462.  
  463.     RESUME
  464.  
  465.   END IF
  466.  
  467.  
  468.  
  469. PaletteError:
  470.  
  471.   Mode = 1            '64K EGA cards will run in CGA mode.
  472.  
  473.   RESUME NEXT
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483. REM $STATIC
  484.  
  485. 'CalcDelay:
  486.  
  487. '  Checks speed of the machine.
  488.  
  489. FUNCTION CalcDelay!
  490.  
  491.  
  492.  
  493.   s! = TIMER
  494.  
  495.   DO
  496.  
  497.     i! = i! + 1
  498.  
  499.   LOOP UNTIL TIMER - s! >= .5
  500.  
  501.   CalcDelay! = i!
  502.  
  503.  
  504.  
  505. END FUNCTION
  506.  
  507.  
  508.  
  509. ' Center:
  510.  
  511. '   Centers and prints a text string on a given row
  512.  
  513. ' Parameters:
  514.  
  515. '   Row - screen row number
  516.  
  517. '   Text$ - text to be printed
  518.  
  519. '
  520.  
  521. SUB Center (Row, Text$)
  522.  
  523.   Col = MaxCol \ 2
  524.  
  525.   LOCATE Row, Col - (LEN(Text$) / 2 + .5)
  526.  
  527.   PRINT Text$;
  528.  
  529. END SUB
  530.  
  531.  
  532.  
  533. ' DoExplosion:
  534.  
  535. '   Produces explosion when a shot is fired
  536.  
  537. ' Parameters:
  538.  
  539. '   X#, Y# - location of explosion
  540.  
  541. '
  542.  
  543. SUB DoExplosion (x#, y#)
  544.  
  545.  
  546.  
  547.   PLAY "MBO0L32EFGEFDC"
  548.  
  549.   Radius = ScrHeight / 50
  550.  
  551.   IF Mode = 9 THEN Inc# = .5 ELSE Inc# = .41
  552.  
  553.   FOR c# = 0 TO Radius STEP Inc#
  554.  
  555.     CIRCLE (x#, y#), c#, ExplosionColor
  556.  
  557.   NEXT c#
  558.  
  559.   FOR c# = Radius TO 0 STEP (-1 * Inc#)
  560.  
  561.     CIRCLE (x#, y#), c#, BACKATTR
  562.  
  563.     FOR i = 1 TO 100
  564.  
  565.     NEXT i
  566.  
  567.     Rest .005
  568.  
  569.   NEXT c#
  570.  
  571. END SUB
  572.  
  573.  
  574.  
  575. ' DoShot:
  576.  
  577. '   Controls banana shots by accepting player input and plotting
  578.  
  579. '   shot angle
  580.  
  581. ' Parameters:
  582.  
  583. '   PlayerNum - Player
  584.  
  585. '   x, y - Player's gorilla position
  586.  
  587. '
  588.  
  589. FUNCTION DoShot (PlayerNum, x, y)
  590.  
  591.  
  592.  
  593.   'Input shot
  594.  
  595.   IF PlayerNum = 1 THEN
  596.  
  597.     LocateCol = 1
  598.  
  599.   ELSE
  600.  
  601.     IF Mode = 9 THEN
  602.  
  603.       LocateCol = 66
  604.  
  605.     ELSE
  606.  
  607.       LocateCol = 26
  608.  
  609.     END IF
  610.  
  611.   END IF
  612.  
  613.  
  614.  
  615.   LOCATE 2, LocateCol
  616.  
  617.   PRINT "Angle:";
  618.  
  619.   Angle# = GetNum#(2, LocateCol + 7)
  620.  
  621.  
  622.  
  623.   LOCATE 3, LocateCol
  624.  
  625.   PRINT "Velocity:";
  626.  
  627.   Velocity = GetNum#(3, LocateCol + 10)
  628.  
  629.  
  630.  
  631.   IF PlayerNum = 2 THEN
  632.  
  633.     Angle# = 180 - Angle#
  634.  
  635.   END IF
  636.  
  637.  
  638.  
  639.   'Erase input
  640.  
  641.   FOR i = 1 TO 4
  642.  
  643.     LOCATE i, 1
  644.  
  645.     PRINT SPACE$(30 \ (80 \ MaxCol));
  646.  
  647.     LOCATE i, (50 \ (80 \ MaxCol))
  648.  
  649.     PRINT SPACE$(30 \ (80 \ MaxCol));
  650.  
  651.   NEXT
  652.  
  653.  
  654.  
  655.   SunHit = FALSE
  656.  
  657.   PlayerHit = PlotShot(x, y, Angle#, Velocity, PlayerNum)
  658.  
  659.   IF PlayerHit = 0 THEN
  660.  
  661.     DoShot = FALSE
  662.  
  663.   ELSE
  664.  
  665.     DoShot = TRUE
  666.  
  667.     IF PlayerHit = PlayerNum THEN PlayerNum = 3 - PlayerNum
  668.  
  669.     VictoryDance PlayerNum
  670.  
  671.   END IF
  672.  
  673.  
  674.  
  675. END FUNCTION
  676.  
  677.  
  678.  
  679. ' DoSun:
  680.  
  681. '   Draws the sun at the top of the screen.
  682.  
  683. ' Parameters:
  684.  
  685. '   Mouth - If TRUE draws "O" mouth else draws a smile mouth.
  686.  
  687. '
  688.  
  689. SUB DoSun (Mouth)
  690.  
  691.  
  692.  
  693.   'set position of sun
  694.  
  695.   x = ScrWidth \ 2: y = Scl(25)
  696.  
  697.  
  698.  
  699.   'clear old sun
  700.  
  701.   LINE (x - Scl(22), y - Scl(18))-(x + Scl(22), y + Scl(18)), BACKATTR, BF
  702.  
  703.  
  704.  
  705.   'draw new sun:
  706.  
  707.   'body
  708.  
  709.   CIRCLE (x, y), Scl(12), SUNATTR
  710.  
  711.   PAINT (x, y), SUNATTR
  712.  
  713.  
  714.  
  715.   'rays
  716.  
  717.   LINE (x - Scl(20), y)-(x + Scl(20), y), SUNATTR
  718.  
  719.   LINE (x, y - Scl(15))-(x, y + Scl(15)), SUNATTR
  720.  
  721.  
  722.  
  723.   LINE (x - Scl(15), y - Scl(10))-(x + Scl(15), y + Scl(10)), SUNATTR
  724.  
  725.   LINE (x - Scl(15), y + Scl(10))-(x + Scl(15), y - Scl(10)), SUNATTR
  726.  
  727.  
  728.  
  729.   LINE (x - Scl(8), y - Scl(13))-(x + Scl(8), y + Scl(13)), SUNATTR
  730.  
  731.   LINE (x - Scl(8), y + Scl(13))-(x + Scl(8), y - Scl(13)), SUNATTR
  732.  
  733.  
  734.  
  735.   LINE (x - Scl(18), y - Scl(5))-(x + Scl(18), y + Scl(5)), SUNATTR
  736.  
  737.   LINE (x - Scl(18), y + Scl(5))-(x + Scl(18), y - Scl(5)), SUNATTR
  738.  
  739.  
  740.  
  741.   'mouth
  742.  
  743.   IF Mouth THEN  'draw "o" mouth
  744.  
  745.     CIRCLE (x, y + Scl(5)), Scl(2.9), 0
  746.  
  747.     PAINT (x, y + Scl(5)), 0, 0
  748.  
  749.   ELSE           'draw smile
  750.  
  751.     CIRCLE (x, y), Scl(8), 0, (210 * pi# / 180), (330 * pi# / 180)
  752.  
  753.   END IF
  754.  
  755.  
  756.  
  757.   'eyes
  758.  
  759.   CIRCLE (x - 3, y - 2), 1, 0
  760.  
  761.   CIRCLE (x + 3, y - 2), 1, 0
  762.  
  763.   PSET (x - 3, y - 2), 0
  764.  
  765.   PSET (x + 3, y - 2), 0
  766.  
  767.  
  768.  
  769. END SUB
  770.  
  771.  
  772.  
  773. 'DrawBan:
  774.  
  775. '  Draws the banana
  776.  
  777. 'Parameters:
  778.  
  779. '  xc# - Horizontal Coordinate
  780.  
  781. '  yc# - Vertical Coordinate
  782.  
  783. '  r - rotation position (0-3). (  \_/  ) /-\
  784.  
  785. '  bc - if TRUE then DrawBan draws the banana ELSE it erases the banana
  786.  
  787. SUB DrawBan (xc#, yc#, r, bc)
  788.  
  789.  
  790.  
  791. SELECT CASE r
  792.  
  793.   CASE 0
  794.  
  795.     IF bc THEN PUT (xc#, yc#), LBan&, PSET ELSE PUT (xc#, yc#), LBan&, XOR
  796.  
  797.   CASE 1
  798.  
  799.     IF bc THEN PUT (xc#, yc#), UBan&, PSET ELSE PUT (xc#, yc#), UBan&, XOR
  800.  
  801.   CASE 2
  802.  
  803.     IF bc THEN PUT (xc#, yc#), DBan&, PSET ELSE PUT (xc#, yc#), DBan&, XOR
  804.  
  805.   CASE 3
  806.  
  807.     IF bc THEN PUT (xc#, yc#), RBan&, PSET ELSE PUT (xc#, yc#), RBan&, XOR
  808.  
  809. END SELECT
  810.  
  811.  
  812.  
  813. END SUB
  814.  
  815.  
  816.  
  817. 'DrawGorilla:
  818.  
  819. '  Draws the Gorilla in either CGA or EGA mode
  820.  
  821. '  and saves the graphics data in an array.
  822.  
  823. 'Parameters:
  824.  
  825. '  x - x coordinate of gorilla
  826.  
  827. '  y - y coordinate of the gorilla
  828.  
  829. '  arms - either Left up, Right up, or both down
  830.  
  831. SUB DrawGorilla (x, y, arms)
  832.  
  833.   DIM i AS SINGLE   ' Local index must be single precision
  834.  
  835.  
  836.  
  837.   'draw head
  838.  
  839.   LINE (x - Scl(4), y)-(x + Scl(2.9), y + Scl(6)), OBJECTCOLOR, BF
  840.  
  841.   LINE (x - Scl(5), y + Scl(2))-(x + Scl(4), y + Scl(4)), OBJECTCOLOR, BF
  842.  
  843.  
  844.  
  845.   'draw eyes/brow
  846.  
  847.   LINE (x - Scl(3), y + Scl(2))-(x + Scl(2), y + Scl(2)), 0
  848.  
  849.  
  850.  
  851.   'draw nose if ega
  852.  
  853.   IF Mode = 9 THEN
  854.  
  855.     FOR i = -2 TO -1
  856.  
  857.       PSET (x + i, y + 4), 0
  858.  
  859.       PSET (x + i + 3, y + 4), 0
  860.  
  861.     NEXT i
  862.  
  863.   END IF
  864.  
  865.  
  866.  
  867.   'neck
  868.  
  869.   LINE (x - Scl(3), y + Scl(7))-(x + Scl(2), y + Scl(7)), OBJECTCOLOR
  870.  
  871.  
  872.  
  873.   'body
  874.  
  875.   LINE (x - Scl(8), y + Scl(8))-(x + Scl(6.9), y + Scl(14)), OBJECTCOLOR, BF
  876.  
  877.   LINE (x - Scl(6), y + Scl(15))-(x + Scl(4.9), y + Scl(20)), OBJECTCOLOR, BF
  878.  
  879.  
  880.  
  881.   'legs
  882.  
  883.   FOR i = 0 TO 4
  884.  
  885.     CIRCLE (x + Scl(i), y + Scl(25)), Scl(10), OBJECTCOLOR, 3 * pi# / 4, 9 * pi# / 8
  886.  
  887.     CIRCLE (x + Scl(-6) + Scl(i - .1), y + Scl(25)), Scl(10), OBJECTCOLOR, 15 * pi# / 8, pi# / 4
  888.  
  889.   NEXT
  890.  
  891.  
  892.  
  893.   'chest
  894.  
  895.   CIRCLE (x - Scl(4.9), y + Scl(10)), Scl(4.9), 0, 3 * pi# / 2, 0
  896.  
  897.   CIRCLE (x + Scl(4.9), y + Scl(10)), Scl(4.9), 0, pi#, 3 * pi# / 2
  898.  
  899.  
  900.  
  901.   FOR i = -5 TO -1
  902.  
  903.     SELECT CASE arms
  904.  
  905.       CASE 1
  906.  
  907.         'Right arm up
  908.  
  909.         CIRCLE (x + Scl(i - .1), y + Scl(14)), Scl(9), OBJECTCOLOR, 3 * pi# / 4, 5 * pi# / 4
  910.  
  911.         CIRCLE (x + Scl(4.9) + Scl(i), y + Scl(4)), Scl(9), OBJECTCOLOR, 7 * pi# / 4, pi# / 4
  912.  
  913.         GET (x - Scl(15), y - Scl(1))-(x + Scl(14), y + Scl(28)), GorR&
  914.  
  915.       CASE 2
  916.  
  917.         'Left arm up
  918.  
  919.         CIRCLE (x + Scl(i - .1), y + Scl(4)), Scl(9), OBJECTCOLOR, 3 * pi# / 4, 5 * pi# / 4
  920.  
  921.         CIRCLE (x + Scl(4.9) + Scl(i), y + Scl(14)), Scl(9), OBJECTCOLOR, 7 * pi# / 4, pi# / 4
  922.  
  923.         GET (x - Scl(15), y - Scl(1))-(x + Scl(14), y + Scl(28)), GorL&
  924.  
  925.       CASE 3
  926.  
  927.         'Both arms down
  928.  
  929.         CIRCLE (x + Scl(i - .1), y + Scl(14)), Scl(9), OBJECTCOLOR, 3 * pi# / 4, 5 * pi# / 4
  930.  
  931.         CIRCLE (x + Scl(4.9) + Scl(i), y + Scl(14)), Scl(9), OBJECTCOLOR, 7 * pi# / 4, pi# / 4
  932.  
  933.         GET (x - Scl(15), y - Scl(1))-(x + Scl(14), y + Scl(28)), GorD&
  934.  
  935.     END SELECT
  936.  
  937.   NEXT i
  938.  
  939. END SUB
  940.  
  941.  
  942.  
  943. 'ExplodeGorilla:
  944.  
  945. '  Causes gorilla explosion when a direct hit occurs
  946.  
  947. 'Parameters:
  948.  
  949. '  X#, Y# - shot location
  950.  
  951. FUNCTION ExplodeGorilla (x#, y#)
  952.  
  953.   YAdj = Scl(12)
  954.  
  955.   XAdj = Scl(5)
  956.  
  957.   SclX# = ScrWidth / 320
  958.  
  959.   SclY# = ScrHeight / 200
  960.  
  961.   IF x# < ScrWidth / 2 THEN PlayerHit = 1 ELSE PlayerHit = 2
  962.  
  963.   PLAY "MBO0L16EFGEFDC"
  964.  
  965.  
  966.  
  967.   FOR i = 1 TO 8 * SclX#
  968.  
  969.     CIRCLE (GorillaX(PlayerHit) + 3.5 * SclX# + XAdj, GorillaY(PlayerHit) + 7 * SclY# + YAdj), i, ExplosionColor, , , -1.57
  970.  
  971.     LINE (GorillaX(PlayerHit) + 7 * SclX#, GorillaY(PlayerHit) + 9 * SclY# - i)-(GorillaX(PlayerHit), GorillaY(PlayerHit) + 9 * SclY# - i), ExplosionColor
  972.  
  973.   NEXT i
  974.  
  975.  
  976.  
  977.   FOR i = 1 TO 16 * SclX#
  978.  
  979.     IF i < (8 * SclX#) THEN CIRCLE (GorillaX(PlayerHit) + 3.5 * SclX# + XAdj, GorillaY(PlayerHit) + 7 * SclY# + YAdj), (8 * SclX# + 1) - i, BACKATTR, , , -1.57
  980.  
  981.     CIRCLE (GorillaX(PlayerHit) + 3.5 * SclX# + XAdj, GorillaY(PlayerHit) + YAdj), i, i MOD 2 + 1, , , -1.57
  982.  
  983.   NEXT i
  984.  
  985.  
  986.  
  987.   FOR i = 24 * SclX# TO 1 STEP -1
  988.  
  989.     CIRCLE (GorillaX(PlayerHit) + 3.5 * SclX# + XAdj, GorillaY(PlayerHit) + YAdj), i, BACKATTR, , , -1.57
  990.  
  991.     FOR Count = 1 TO 200
  992.  
  993.     NEXT
  994.  
  995.   NEXT i
  996.  
  997.  
  998.  
  999.   ExplodeGorilla = PlayerHit
  1000.  
  1001. END FUNCTION
  1002.  
  1003.  
  1004.  
  1005. 'GetInputs:
  1006.  
  1007. '  Gets user inputs at beginning of game
  1008.  
  1009. 'Parameters:
  1010.  
  1011. '  Player1$, Player2$ - player names
  1012.  
  1013. '  NumGames - number of games to play
  1014.  
  1015. SUB GetInputs (Player1$, Player2$, NumGames)
  1016.  
  1017.   COLOR 7, 0
  1018.  
  1019.   CLS
  1020.  
  1021.  
  1022.  
  1023.   LOCATE 8, 15
  1024.  
  1025.   LINE INPUT "Name of Player 1 (Default = 'Player 1'): "; Player1$
  1026.  
  1027.   IF Player1$ = "" THEN
  1028.  
  1029.     Player1$ = "Player 1"
  1030.  
  1031.   ELSE
  1032.  
  1033.     Player1$ = LEFT$(Player1$, 10)
  1034.  
  1035.   END IF
  1036.  
  1037.  
  1038.  
  1039.   LOCATE 10, 15
  1040.  
  1041.   LINE INPUT "Name of Player 2 (Default = 'Player 2'): "; Player2$
  1042.  
  1043.   IF Player2$ = "" THEN
  1044.  
  1045.     Player2$ = "Player 2"
  1046.  
  1047.   ELSE
  1048.  
  1049.     Player2$ = LEFT$(Player2$, 10)
  1050.  
  1051.   END IF
  1052.  
  1053.  
  1054.  
  1055.   DO
  1056.  
  1057.     LOCATE 12, 56: PRINT SPACE$(25);
  1058.  
  1059.     LOCATE 12, 13
  1060.  
  1061.     INPUT "Play to how many total points (Default = 3)"; game$
  1062.  
  1063.     NumGames = VAL(LEFT$(game$, 2))
  1064.  
  1065.   LOOP UNTIL NumGames > 0 AND LEN(game$) < 3 OR LEN(game$) = 0
  1066.  
  1067.   IF NumGames = 0 THEN NumGames = 3
  1068.  
  1069.  
  1070.  
  1071.   DO
  1072.  
  1073.     LOCATE 14, 53: PRINT SPACE$(28);
  1074.  
  1075.     LOCATE 14, 17
  1076.  
  1077.     INPUT "Gravity in Meters/Sec (Earth = 9.8)"; grav$
  1078.  
  1079.     gravity# = VAL(grav$)
  1080.  
  1081.   LOOP UNTIL gravity# > 0 OR LEN(grav$) = 0
  1082.  
  1083.   IF gravity# = 0 THEN gravity# = 9.8
  1084.  
  1085. END SUB
  1086.  
  1087.  
  1088.  
  1089. 'GetNum:
  1090.  
  1091. '  Gets valid numeric input from user
  1092.  
  1093. 'Parameters:
  1094.  
  1095. '  Row, Col - location to echo input
  1096.  
  1097. FUNCTION GetNum# (Row, Col)
  1098.  
  1099.   Result$ = ""
  1100.  
  1101.   Done = FALSE
  1102.  
  1103.   WHILE INKEY$ <> "": WEND   'Clear keyboard buffer
  1104.  
  1105.  
  1106.  
  1107.   DO WHILE NOT Done
  1108.  
  1109.  
  1110.  
  1111.     LOCATE Row, Col
  1112.  
  1113.     PRINT Result$; CHR$(95); "    ";
  1114.  
  1115.  
  1116.  
  1117.     Kbd$ = INKEY$
  1118.  
  1119.     SELECT CASE Kbd$
  1120.  
  1121.       CASE "0" TO "9"
  1122.  
  1123.         Result$ = Result$ + Kbd$
  1124.  
  1125.       CASE "."
  1126.  
  1127.         IF INSTR(Result$, ".") = 0 THEN
  1128.  
  1129.           Result$ = Result$ + Kbd$
  1130.  
  1131.         END IF
  1132.  
  1133.       CASE CHR$(13)
  1134.  
  1135.         IF VAL(Result$) > 360 THEN
  1136.  
  1137.           Result$ = ""
  1138.  
  1139.         ELSE
  1140.  
  1141.           Done = TRUE
  1142.  
  1143.         END IF
  1144.  
  1145.       CASE CHR$(8)
  1146.  
  1147.         IF LEN(Result$) > 0 THEN
  1148.  
  1149.           Result$ = LEFT$(Result$, LEN(Result$) - 1)
  1150.  
  1151.         END IF
  1152.  
  1153.       CASE ELSE
  1154.  
  1155.         IF LEN(Kbd$) > 0 THEN
  1156.  
  1157.           BEEP
  1158.  
  1159.         END IF
  1160.  
  1161.       END SELECT
  1162.  
  1163.   LOOP
  1164.  
  1165.  
  1166.  
  1167.   LOCATE Row, Col
  1168.  
  1169.   PRINT Result$; " ";
  1170.  
  1171.  
  1172.  
  1173.   GetNum# = VAL(Result$)
  1174.  
  1175. END FUNCTION
  1176.  
  1177.  
  1178.  
  1179. 'GorillaIntro:
  1180.  
  1181. '  Displays gorillas on screen for the first time
  1182.  
  1183. '  allows the graphical data to be put into an array
  1184.  
  1185. 'Parameters:
  1186.  
  1187. '  Player1$, Player2$ - The names of the players
  1188.  
  1189. '
  1190.  
  1191. SUB GorillaIntro (Player1$, Player2$)
  1192.  
  1193.   LOCATE 16, 34: PRINT "--------------"
  1194.  
  1195.   LOCATE 18, 34: PRINT "V = View Intro"
  1196.  
  1197.   LOCATE 19, 34: PRINT "P = Play Game"
  1198.  
  1199.   LOCATE 21, 35: PRINT "Your Choice?"
  1200.  
  1201.  
  1202.  
  1203.   DO WHILE Char$ = ""
  1204.  
  1205.     Char$ = INKEY$
  1206.  
  1207.   LOOP
  1208.  
  1209.  
  1210.  
  1211.   IF Mode = 1 THEN
  1212.  
  1213.     x = 125
  1214.  
  1215.     y = 100
  1216.  
  1217.   ELSE
  1218.  
  1219.     x = 278
  1220.  
  1221.     y = 175
  1222.  
  1223.   END IF
  1224.  
  1225.  
  1226.  
  1227.   SCREEN Mode
  1228.  
  1229.   SetScreen
  1230.  
  1231.  
  1232.  
  1233.   IF Mode = 1 THEN Center 5, "Please wait while gorillas are drawn."
  1234.  
  1235.  
  1236.  
  1237.   VIEW PRINT 9 TO 24
  1238.  
  1239.  
  1240.  
  1241.   IF Mode = 9 THEN PALETTE OBJECTCOLOR, BackColor
  1242.  
  1243.  
  1244.  
  1245.   DrawGorilla x, y, ARMSDOWN
  1246.  
  1247.   CLS 2
  1248.  
  1249.   DrawGorilla x, y, LEFTUP
  1250.  
  1251.   CLS 2
  1252.  
  1253.   DrawGorilla x, y, RIGHTUP
  1254.  
  1255.   CLS 2
  1256.  
  1257.  
  1258.  
  1259.   VIEW PRINT 1 TO 25
  1260.  
  1261.   IF Mode = 9 THEN PALETTE OBJECTCOLOR, 46
  1262.  
  1263.  
  1264.  
  1265.   IF UCASE$(Char$) = "V" THEN
  1266.  
  1267.     Center 2, "Q B A S I C   G O R I L L A S"
  1268.  
  1269.     Center 5, "             STARRING:               "
  1270.  
  1271.     P$ = Player1$ + " AND " + Player2$
  1272.  
  1273.     Center 7, P$
  1274.  
  1275.  
  1276.  
  1277.     PUT (x - 13, y), GorD&, PSET
  1278.  
  1279.     PUT (x + 47, y), GorD&, PSET
  1280.  
  1281.     Rest 1
  1282.  
  1283.  
  1284.  
  1285.     PUT (x - 13, y), GorL&, PSET
  1286.  
  1287.     PUT (x + 47, y), GorR&, PSET
  1288.  
  1289.     PLAY "t120o1l16b9n0baan0bn0bn0baaan0b9n0baan0b"
  1290.  
  1291.     Rest .3
  1292.  
  1293.  
  1294.  
  1295.     PUT (x - 13, y), GorR&, PSET
  1296.  
  1297.     PUT (x + 47, y), GorL&, PSET
  1298.  
  1299.     PLAY "o2l16e-9n0e-d-d-n0e-n0e-n0e-d-d-d-n0e-9n0e-d-d-n0e-"
  1300.  
  1301.     Rest .3
  1302.  
  1303.  
  1304.  
  1305.     PUT (x - 13, y), GorL&, PSET
  1306.  
  1307.     PUT (x + 47, y), GorR&, PSET
  1308.  
  1309.     PLAY "o2l16g-9n0g-een0g-n0g-n0g-eeen0g-9n0g-een0g-"
  1310.  
  1311.     Rest .3
  1312.  
  1313.  
  1314.  
  1315.     PUT (x - 13, y), GorR&, PSET
  1316.  
  1317.     PUT (x + 47, y), GorL&, PSET
  1318.  
  1319.     PLAY "o2l16b9n0baan0g-n0g-n0g-eeen0o1b9n0baan0b"
  1320.  
  1321.     Rest .3
  1322.  
  1323.  
  1324.  
  1325.     FOR i = 1 TO 4
  1326.  
  1327.       PUT (x - 13, y), GorL&, PSET
  1328.  
  1329.       PUT (x + 47, y), GorR&, PSET
  1330.  
  1331.       PLAY "T160O0L32EFGEFDC"
  1332.  
  1333.       Rest .1
  1334.  
  1335.       PUT (x - 13, y), GorR&, PSET
  1336.  
  1337.       PUT (x + 47, y), GorL&, PSET
  1338.  
  1339.       PLAY "T160O0L32EFGEFDC"
  1340.  
  1341.       Rest .1
  1342.  
  1343.     NEXT
  1344.  
  1345.   END IF
  1346.  
  1347. END SUB
  1348.  
  1349.  
  1350.  
  1351. 'Intro:
  1352.  
  1353. '  Displays game introduction
  1354.  
  1355. SUB Intro
  1356.  
  1357.  
  1358.  
  1359.   SCREEN 0
  1360.  
  1361.   WIDTH 80, 25
  1362.  
  1363.   MaxCol = 80
  1364.  
  1365.   COLOR 15, 0
  1366.  
  1367.   CLS
  1368.  
  1369.  
  1370.  
  1371.   Center 4, "Q B a s i c    G O R I L L A S"
  1372.  
  1373.   COLOR 7
  1374.  
  1375.   Center 6, "Copyright (C) IBM Corporation 1991"
  1376.  
  1377.   Center 8, "Your mission is to hit your opponent with the exploding"
  1378.  
  1379.   Center 9, "banana by varying the angle and power of your throw, taking"
  1380.  
  1381.   Center 10, "into account wind speed, gravity, and the city skyline."
  1382.  
  1383.   Center 11, "The wind speed is shown by a directional arrow at the bottom"
  1384.  
  1385.   Center 12, "of the playing field, its length relative to its strength."
  1386.  
  1387.   Center 24, "Press any key to continue"
  1388.  
  1389.  
  1390.  
  1391.   PLAY "MBT160O1L8CDEDCDL4ECC"
  1392.  
  1393.   SparklePause
  1394.  
  1395.   IF Mode = 1 THEN MaxCol = 40
  1396.  
  1397. END SUB
  1398.  
  1399.  
  1400.  
  1401. 'MakeCityScape:
  1402.  
  1403. '  Creates random skyline for game
  1404.  
  1405. 'Parameters:
  1406.  
  1407. '  BCoor() - a user-defined type array which stores the coordinates of
  1408.  
  1409. '  the upper left corner of each building.
  1410.  
  1411. SUB MakeCityScape (BCoor() AS XYPoint)
  1412.  
  1413.  
  1414.  
  1415.   x = 2
  1416.  
  1417.  
  1418.  
  1419.   'Set the sloping trend of the city scape. NewHt is new building height
  1420.  
  1421.   Slope = FnRan(6)
  1422.  
  1423.   SELECT CASE Slope
  1424.  
  1425.     CASE 1: NewHt = 15                 'Upward slope
  1426.  
  1427.     CASE 2: NewHt = 130                'Downward slope
  1428.  
  1429.     CASE 3 TO 5: NewHt = 15            '"V" slope - most common
  1430.  
  1431.     CASE 6: NewHt = 130                'Inverted "V" slope
  1432.  
  1433.   END SELECT
  1434.  
  1435.  
  1436.  
  1437.   IF Mode = 9 THEN
  1438.  
  1439.     BottomLine = 335                   'Bottom of building
  1440.  
  1441.     HtInc = 10                         'Increase value for new height
  1442.  
  1443.     DefBWidth = 37                     'Default building height
  1444.  
  1445.     RandomHeight = 120                 'Random height difference
  1446.  
  1447.     WWidth = 3                         'Window width
  1448.  
  1449.     WHeight = 6                        'Window height
  1450.  
  1451.     WDifV = 15                         'Counter for window spacing - vertical
  1452.  
  1453.     WDifh = 10                         'Counter for window spacing - horizontal
  1454.  
  1455.   ELSE
  1456.  
  1457.     BottomLine = 190
  1458.  
  1459.     HtInc = 6
  1460.  
  1461.     NewHt = NewHt * 20 \ 35            'Adjust for CGA
  1462.  
  1463.     DefBWidth = 18
  1464.  
  1465.     RandomHeight = 54
  1466.  
  1467.     WWidth = 1
  1468.  
  1469.     WHeight = 2
  1470.  
  1471.     WDifV = 5
  1472.  
  1473.     WDifh = 4
  1474.  
  1475.   END IF
  1476.  
  1477.  
  1478.  
  1479.   CurBuilding = 1
  1480.  
  1481.   DO
  1482.  
  1483.  
  1484.  
  1485.     SELECT CASE Slope
  1486.  
  1487.       CASE 1
  1488.  
  1489.         NewHt = NewHt + HtInc
  1490.  
  1491.       CASE 2
  1492.  
  1493.         NewHt = NewHt - HtInc
  1494.  
  1495.       CASE 3 TO 5
  1496.  
  1497.         IF x > ScrWidth \ 2 THEN
  1498.  
  1499.           NewHt = NewHt - 2 * HtInc
  1500.  
  1501.         ELSE
  1502.  
  1503.           NewHt = NewHt + 2 * HtInc
  1504.  
  1505.         END IF
  1506.  
  1507.       CASE 4
  1508.  
  1509.         IF x > ScrWidth \ 2 THEN
  1510.  
  1511.           NewHt = NewHt + 2 * HtInc
  1512.  
  1513.         ELSE
  1514.  
  1515.           NewHt = NewHt - 2 * HtInc
  1516.  
  1517.         END IF
  1518.  
  1519.     END SELECT
  1520.  
  1521.  
  1522.  
  1523.     'Set width of building and check to see if it would go off the screen
  1524.  
  1525.     BWidth = FnRan(DefBWidth) + DefBWidth
  1526.  
  1527.     IF x + BWidth > ScrWidth THEN BWidth = ScrWidth - x - 2
  1528.  
  1529.  
  1530.  
  1531.     'Set height of building and check to see if it goes below screen
  1532.  
  1533.     BHeight = FnRan(RandomHeight) + NewHt
  1534.  
  1535.     IF BHeight < HtInc THEN BHeight = HtInc
  1536.  
  1537.  
  1538.  
  1539.     'Check to see if Building is too high
  1540.  
  1541.     IF BottomLine - BHeight <= MaxHeight + GHeight THEN BHeight = MaxHeight + GHeight - 5
  1542.  
  1543.  
  1544.  
  1545.     'Set the coordinates of the building into the array
  1546.  
  1547.     BCoor(CurBuilding).XCoor = x
  1548.  
  1549.     BCoor(CurBuilding).YCoor = BottomLine - BHeight
  1550.  
  1551.  
  1552.  
  1553.     IF Mode = 9 THEN BuildingColor = FnRan(3) + 4 ELSE BuildingColor = 2
  1554.  
  1555.  
  1556.  
  1557.     'Draw the building, outline first, then filled
  1558.  
  1559.     LINE (x - 1, BottomLine + 1)-(x + BWidth + 1, BottomLine - BHeight - 1), BACKGROUND, B
  1560.  
  1561.     LINE (x, BottomLine)-(x + BWidth, BottomLine - BHeight), BuildingColor, BF
  1562.  
  1563.  
  1564.  
  1565.     'Draw the windows
  1566.  
  1567.     c = x + 3
  1568.  
  1569.     DO
  1570.  
  1571.       FOR i = BHeight - 3 TO 7 STEP -WDifV
  1572.  
  1573.         IF Mode <> 9 THEN
  1574.  
  1575.           WinColr = (FnRan(2) - 2) * -3
  1576.  
  1577.         ELSEIF FnRan(4) = 1 THEN
  1578.  
  1579.           WinColr = 8
  1580.  
  1581.         ELSE
  1582.  
  1583.           WinColr = WINDOWCOLOR
  1584.  
  1585.         END IF
  1586.  
  1587.         LINE (c, BottomLine - i)-(c + WWidth, BottomLine - i + WHeight), WinColr, BF
  1588.  
  1589.       NEXT
  1590.  
  1591.       c = c + WDifh
  1592.  
  1593.     LOOP UNTIL c >= x + BWidth - 3
  1594.  
  1595.  
  1596.  
  1597.     x = x + BWidth + 2
  1598.  
  1599.  
  1600.  
  1601.     CurBuilding = CurBuilding + 1
  1602.  
  1603.  
  1604.  
  1605.   LOOP UNTIL x > ScrWidth - HtInc
  1606.  
  1607.  
  1608.  
  1609.   LastBuilding = CurBuilding - 1
  1610.  
  1611.  
  1612.  
  1613.   'Set Wind speed
  1614.  
  1615.   Wind = FnRan(10) - 5
  1616.  
  1617.   IF FnRan(3) = 1 THEN
  1618.  
  1619.     IF Wind > 0 THEN
  1620.  
  1621.       Wind = Wind + FnRan(10)
  1622.  
  1623.     ELSE
  1624.  
  1625.       Wind = Wind - FnRan(10)
  1626.  
  1627.     END IF
  1628.  
  1629.   END IF
  1630.  
  1631.  
  1632.  
  1633.   'Draw Wind speed arrow
  1634.  
  1635.   IF Wind <> 0 THEN
  1636.  
  1637.     WindLine = Wind * 3 * (ScrWidth \ 320)
  1638.  
  1639.     LINE (ScrWidth \ 2, ScrHeight - 5)-(ScrWidth \ 2 + WindLine, ScrHeight - 5), ExplosionColor
  1640.  
  1641.     IF Wind > 0 THEN ArrowDir = -2 ELSE ArrowDir = 2
  1642.  
  1643.     LINE (ScrWidth / 2 + WindLine, ScrHeight - 5)-(ScrWidth / 2 + WindLine + ArrowDir, ScrHeight - 5 - 2), ExplosionColor
  1644.  
  1645.     LINE (ScrWidth / 2 + WindLine, ScrHeight - 5)-(ScrWidth / 2 + WindLine + ArrowDir, ScrHeight - 5 + 2), ExplosionColor
  1646.  
  1647.   END IF
  1648.  
  1649. END SUB
  1650.  
  1651.  
  1652.  
  1653. 'PlaceGorillas:
  1654.  
  1655. '  PUTs the Gorillas on top of the buildings.  Must have drawn
  1656.  
  1657. '  Gorillas first.
  1658.  
  1659. 'Parameters:
  1660.  
  1661. '  BCoor() - user-defined TYPE array which stores upper left coordinates
  1662.  
  1663. '  of each building.
  1664.  
  1665. SUB PlaceGorillas (BCoor() AS XYPoint)
  1666.  
  1667.  
  1668.  
  1669.   IF Mode = 9 THEN
  1670.  
  1671.     XAdj = 14
  1672.  
  1673.     YAdj = 30
  1674.  
  1675.   ELSE
  1676.  
  1677.     XAdj = 7
  1678.  
  1679.     YAdj = 16
  1680.  
  1681.   END IF
  1682.  
  1683.   SclX# = ScrWidth / 320
  1684.  
  1685.   SclY# = ScrHeight / 200
  1686.  
  1687.  
  1688.  
  1689.   'Place gorillas on second or third building from edge
  1690.  
  1691.   FOR i = 1 TO 2
  1692.  
  1693.     IF i = 1 THEN BNum = FnRan(2) + 1 ELSE BNum = LastBuilding - FnRan(2)
  1694.  
  1695.  
  1696.  
  1697.     BWidth = BCoor(BNum + 1).XCoor - BCoor(BNum).XCoor
  1698.  
  1699.     GorillaX(i) = BCoor(BNum).XCoor + BWidth / 2 - XAdj
  1700.  
  1701.     GorillaY(i) = BCoor(BNum).YCoor - YAdj
  1702.  
  1703.     PUT (GorillaX(i), GorillaY(i)), GorD&, PSET
  1704.  
  1705.   NEXT i
  1706.  
  1707.  
  1708.  
  1709. END SUB
  1710.  
  1711.  
  1712.  
  1713. 'PlayGame:
  1714.  
  1715. '  Main game play routine
  1716.  
  1717. 'Parameters:
  1718.  
  1719. '  Player1$, Player2$ - player names
  1720.  
  1721. '  NumGames - number of games to play
  1722.  
  1723. SUB PlayGame (Player1$, Player2$, NumGames)
  1724.  
  1725.   DIM BCoor(0 TO 30) AS XYPoint
  1726.  
  1727.   DIM TotalWins(1 TO 2)
  1728.  
  1729.  
  1730.  
  1731.   J = 1
  1732.  
  1733.  
  1734.  
  1735.   FOR i = 1 TO NumGames
  1736.  
  1737.  
  1738.  
  1739.     CLS
  1740.  
  1741.     RANDOMIZE (TIMER)
  1742.  
  1743.     CALL MakeCityScape(BCoor())
  1744.  
  1745.     CALL PlaceGorillas(BCoor())
  1746.  
  1747.     DoSun SUNHAPPY
  1748.  
  1749.     Hit = FALSE
  1750.  
  1751.     DO WHILE Hit = FALSE
  1752.  
  1753.       J = 1 - J
  1754.  
  1755.       LOCATE 1, 1
  1756.  
  1757.       PRINT Player1$
  1758.  
  1759.       LOCATE 1, (MaxCol - 1 - LEN(Player2$))
  1760.  
  1761.       PRINT Player2$
  1762.  
  1763.       Center 23, LTRIM$(STR$(TotalWins(1))) + ">Score<" + LTRIM$(STR$(TotalWins(2)))
  1764.  
  1765.       Tosser = J + 1: Tossee = 3 - J
  1766.  
  1767.  
  1768.  
  1769.       'Plot the shot.  Hit is true if Gorilla gets hit.
  1770.  
  1771.       Hit = DoShot(Tosser, GorillaX(Tosser), GorillaY(Tosser))
  1772.  
  1773.  
  1774.  
  1775.       'Reset the sun, if it got hit
  1776.  
  1777.       IF SunHit THEN DoSun SUNHAPPY
  1778.  
  1779.  
  1780.  
  1781.       IF Hit = TRUE THEN CALL UpdateScores(TotalWins(), Tosser, Hit)
  1782.  
  1783.     LOOP
  1784.  
  1785.     SLEEP 1
  1786.  
  1787.   NEXT i
  1788.  
  1789.  
  1790.  
  1791.   SCREEN 0
  1792.  
  1793.   WIDTH 80, 25
  1794.  
  1795.   COLOR 7, 0
  1796.  
  1797.   MaxCol = 80
  1798.  
  1799.   CLS
  1800.  
  1801.  
  1802.  
  1803.   Center 8, "GAME OVER!"
  1804.  
  1805.   Center 10, "Score:"
  1806.  
  1807.   LOCATE 11, 30: PRINT Player1$; TAB(50); TotalWins(1)
  1808.  
  1809.   LOCATE 12, 30: PRINT Player2$; TAB(50); TotalWins(2)
  1810.  
  1811.   Center 24, "Press any key to continue"
  1812.  
  1813.    SparklePause
  1814.  
  1815.   COLOR 7, 0
  1816.  
  1817.   CLS
  1818.  
  1819. END SUB
  1820.  
  1821.  
  1822.  
  1823. '  Plots banana shot across the screen
  1824.  
  1825. 'Parameters:
  1826.  
  1827. '  StartX, StartY - starting shot location
  1828.  
  1829. '  Angle - shot angle
  1830.  
  1831. '  Velocity - shot velocity
  1832.  
  1833. '  PlayerNum - the banana thrower
  1834.  
  1835. FUNCTION PlotShot (StartX, StartY, Angle#, Velocity, PlayerNum)
  1836.  
  1837.  
  1838.  
  1839.   Angle# = Angle# / 180 * pi#  'Convert degree angle to radians
  1840.  
  1841.   Radius = Mode MOD 7
  1842.  
  1843.  
  1844.  
  1845.   InitXVel# = COS(Angle#) * Velocity
  1846.  
  1847.   InitYVel# = SIN(Angle#) * Velocity
  1848.  
  1849.  
  1850.  
  1851.   oldx# = StartX
  1852.  
  1853.   oldy# = StartY
  1854.  
  1855.  
  1856.  
  1857.   'draw gorilla toss
  1858.  
  1859.   IF PlayerNum = 1 THEN
  1860.  
  1861.     PUT (StartX, StartY), GorL&, PSET
  1862.  
  1863.   ELSE
  1864.  
  1865.     PUT (StartX, StartY), GorR&, PSET
  1866.  
  1867.   END IF
  1868.  
  1869.  
  1870.  
  1871.   'throw sound
  1872.  
  1873.   PLAY "MBo0L32A-L64CL16BL64A+"
  1874.  
  1875.   Rest .1
  1876.  
  1877.  
  1878.  
  1879.   'redraw gorilla
  1880.  
  1881.   PUT (StartX, StartY), GorD&, PSET
  1882.  
  1883.  
  1884.  
  1885.   adjust = Scl(4)                   'For scaling CGA
  1886.  
  1887.  
  1888.  
  1889.   xedge = Scl(9) * (2 - PlayerNum)  'Find leading edge of banana for check
  1890.  
  1891.  
  1892.  
  1893.   Impact = FALSE
  1894.  
  1895.   ShotInSun = FALSE
  1896.  
  1897.   OnScreen = TRUE
  1898.  
  1899.   PlayerHit = 0
  1900.  
  1901.   NeedErase = FALSE
  1902.  
  1903.  
  1904.  
  1905.   StartXPos = StartX
  1906.  
  1907.   StartYPos = StartY - adjust - 3
  1908.  
  1909.  
  1910.  
  1911.   IF PlayerNum = 2 THEN
  1912.  
  1913.     StartXPos = StartXPos + Scl(25)
  1914.  
  1915.     direction = Scl(4)
  1916.  
  1917.   ELSE
  1918.  
  1919.     direction = Scl(-4)
  1920.  
  1921.   END IF
  1922.  
  1923.  
  1924.  
  1925.   IF Velocity < 2 THEN              'Shot too slow - hit self
  1926.  
  1927.     x# = StartX
  1928.  
  1929.     y# = StartY
  1930.  
  1931.     pointval = OBJECTCOLOR
  1932.  
  1933.   END IF
  1934.  
  1935.  
  1936.  
  1937.   DO WHILE (NOT Impact) AND OnScreen
  1938.  
  1939.  
  1940.  
  1941.   Rest .02
  1942.  
  1943.  
  1944.  
  1945.   'Erase old banana, if necessary
  1946.  
  1947.   IF NeedErase THEN
  1948.  
  1949.     NeedErase = FALSE
  1950.  
  1951.     CALL DrawBan(oldx#, oldy#, oldrot, FALSE)
  1952.  
  1953.   END IF
  1954.  
  1955.  
  1956.  
  1957.   x# = StartXPos + (InitXVel# * t#) + (.5 * (Wind / 5) * t# ^ 2)
  1958.  
  1959.   y# = StartYPos + ((-1 * (InitYVel# * t#)) + (.5 * gravity# * t# ^ 2)) * (ScrHeight / 350)
  1960.  
  1961.  
  1962.  
  1963.   IF (x# >= ScrWidth - Scl(10)) OR (x# <= 3) OR (y# >= ScrHeight - 3) THEN
  1964.  
  1965.     OnScreen = FALSE
  1966.  
  1967.   END IF
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.   IF OnScreen AND y# > 0 THEN
  1974.  
  1975.  
  1976.  
  1977.     'check it
  1978.  
  1979.     LookY = 0
  1980.  
  1981.     LookX = Scl(8 * (2 - PlayerNum))
  1982.  
  1983.     DO
  1984.  
  1985.       pointval = POINT(x# + LookX, y# + LookY)
  1986.  
  1987.       IF pointval = 0 THEN
  1988.  
  1989.         Impact = FALSE
  1990.  
  1991.         IF ShotInSun = TRUE THEN
  1992.  
  1993.           IF ABS(ScrWidth \ 2 - x#) > Scl(20) OR y# > SunHt THEN ShotInSun = FALSE
  1994.  
  1995.         END IF
  1996.  
  1997.       ELSEIF pointval = SUNATTR AND y# < SunHt THEN
  1998.  
  1999.         IF NOT SunHit THEN DoSun SUNSHOCK
  2000.  
  2001.         SunHit = TRUE
  2002.  
  2003.         ShotInSun = TRUE
  2004.  
  2005.       ELSE
  2006.  
  2007.         Impact = TRUE
  2008.  
  2009.       END IF
  2010.  
  2011.       LookX = LookX + direction
  2012.  
  2013.       LookY = LookY + Scl(6)
  2014.  
  2015.     LOOP UNTIL Impact OR LookX <> Scl(4)
  2016.  
  2017.  
  2018.  
  2019.     IF NOT ShotInSun AND NOT Impact THEN
  2020.  
  2021.       'plot it
  2022.  
  2023.       rot = (t# * 10) MOD 4
  2024.  
  2025.       CALL DrawBan(x#, y#, rot, TRUE)
  2026.  
  2027.       NeedErase = TRUE
  2028.  
  2029.     END IF
  2030.  
  2031.  
  2032.  
  2033.     oldx# = x#
  2034.  
  2035.     oldy# = y#
  2036.  
  2037.     oldrot = rot
  2038.  
  2039.  
  2040.  
  2041.   END IF
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.   t# = t# + .1
  2048.  
  2049.  
  2050.  
  2051.   LOOP
  2052.  
  2053.  
  2054.  
  2055.   IF pointval <> OBJECTCOLOR AND Impact THEN
  2056.  
  2057.     CALL DoExplosion(x# + adjust, y# + adjust)
  2058.  
  2059.   ELSEIF pointval = OBJECTCOLOR THEN
  2060.  
  2061.     PlayerHit = ExplodeGorilla(x#, y#)
  2062.  
  2063.   END IF
  2064.  
  2065.  
  2066.  
  2067.   PlotShot = PlayerHit
  2068.  
  2069.  
  2070.  
  2071. END FUNCTION
  2072.  
  2073.  
  2074.  
  2075. 'Rest:
  2076.  
  2077. '  pauses the program
  2078.  
  2079. SUB Rest (t#)
  2080.  
  2081.   s# = TIMER
  2082.  
  2083.   t2# = MachSpeed * t# / SPEEDCONST
  2084.  
  2085.   DO
  2086.  
  2087.   LOOP UNTIL TIMER - s# > t2#
  2088.  
  2089. END SUB
  2090.  
  2091.  
  2092.  
  2093. 'Scl:
  2094.  
  2095. '  Pass the number in to scaling for cga.  If the number is a decimal, then we
  2096.  
  2097. '  want to scale down for cga or scale up for ega.  This allows a full range
  2098.  
  2099. '  of numbers to be generated for scaling.
  2100.  
  2101. '  (i.e. for 3 to get scaled to 1, pass in 2.9)
  2102.  
  2103. FUNCTION Scl (n!)
  2104.  
  2105.  
  2106.  
  2107.   IF n! <> INT(n!) THEN
  2108.  
  2109.       IF Mode = 1 THEN n! = n! - 1
  2110.  
  2111.   END IF
  2112.  
  2113.   IF Mode = 1 THEN
  2114.  
  2115.       Scl = CINT(n! / 2 + .1)
  2116.  
  2117.   ELSE
  2118.  
  2119.       Scl = CINT(n!)
  2120.  
  2121.   END IF
  2122.  
  2123.  
  2124.  
  2125. END FUNCTION
  2126.  
  2127.  
  2128.  
  2129. 'SetScreen:
  2130.  
  2131. '  Sets the appropriate color statements
  2132.  
  2133. SUB SetScreen
  2134.  
  2135.  
  2136.  
  2137.   IF Mode = 9 THEN
  2138.  
  2139.     ExplosionColor = 2
  2140.  
  2141.     BackColor = 1
  2142.  
  2143.     PALETTE 0, 1
  2144.  
  2145.     PALETTE 1, 46
  2146.  
  2147.     PALETTE 2, 44
  2148.  
  2149.     PALETTE 3, 54
  2150.  
  2151.     PALETTE 5, 7
  2152.  
  2153.     PALETTE 6, 4
  2154.  
  2155.     PALETTE 7, 3
  2156.  
  2157.     PALETTE 9, 63       'Display Color
  2158.  
  2159.   ELSE
  2160.  
  2161.     ExplosionColor = 2
  2162.  
  2163.     BackColor = 0
  2164.  
  2165.     COLOR BackColor, 2
  2166.  
  2167.  
  2168.  
  2169.   END IF
  2170.  
  2171.  
  2172.  
  2173. END SUB
  2174.  
  2175.  
  2176.  
  2177. 'SparklePause:
  2178.  
  2179. '  Creates flashing border for intro and game over screens
  2180.  
  2181. SUB SparklePause
  2182.  
  2183.  
  2184.  
  2185.   COLOR 4, 0
  2186.  
  2187.   a$ = "*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    "
  2188.  
  2189.   WHILE INKEY$ <> "": WEND 'Clear keyboard buffer
  2190.  
  2191.  
  2192.  
  2193.   WHILE INKEY$ = ""
  2194.  
  2195.     FOR a = 1 TO 5
  2196.  
  2197.       LOCATE 1, 1                             'print horizontal sparkles
  2198.  
  2199.       PRINT MID$(a$, a, 80);
  2200.  
  2201.       LOCATE 22, 1
  2202.  
  2203.       PRINT MID$(a$, 6 - a, 80);
  2204.  
  2205.  
  2206.  
  2207.       FOR b = 2 TO 21                         'Print Vertical sparkles
  2208.  
  2209.         c = (a + b) MOD 5
  2210.  
  2211.         IF c = 1 THEN
  2212.  
  2213.           LOCATE b, 80
  2214.  
  2215.           PRINT "*";
  2216.  
  2217.           LOCATE 23 - b, 1
  2218.  
  2219.           PRINT "*";
  2220.  
  2221.         ELSE
  2222.  
  2223.           LOCATE b, 80
  2224.  
  2225.           PRINT " ";
  2226.  
  2227.           LOCATE 23 - b, 1
  2228.  
  2229.           PRINT " ";
  2230.  
  2231.         END IF
  2232.  
  2233.       NEXT b
  2234.  
  2235.     NEXT a
  2236.  
  2237.   WEND
  2238.  
  2239. END SUB
  2240.  
  2241.  
  2242.  
  2243. 'UpdateScores:
  2244.  
  2245. '  Updates players' scores
  2246.  
  2247. 'Parameters:
  2248.  
  2249. '  Record - players' scores
  2250.  
  2251. '  PlayerNum - player
  2252.  
  2253. '  Results - results of player's shot
  2254.  
  2255. SUB UpdateScores (Record(), PlayerNum, Results)
  2256.  
  2257.   IF Results = HITSELF THEN
  2258.  
  2259.     Record(ABS(PlayerNum - 3)) = Record(ABS(PlayerNum - 3)) + 1
  2260.  
  2261.   ELSE
  2262.  
  2263.     Record(PlayerNum) = Record(PlayerNum) + 1
  2264.  
  2265.   END IF
  2266.  
  2267. END SUB
  2268.  
  2269.  
  2270.  
  2271. 'VictoryDance:
  2272.  
  2273. '  gorilla dances after he has eliminated his opponent
  2274.  
  2275. 'Parameters:
  2276.  
  2277. '  Player - which gorilla is dancing
  2278.  
  2279. SUB VictoryDance (Player)
  2280.  
  2281.  
  2282.  
  2283.   FOR i# = 1 TO 4
  2284.  
  2285.     PUT (GorillaX(Player), GorillaY(Player)), GorL&, PSET
  2286.  
  2287.     PLAY "MFO0L32EFGEFDC"
  2288.  
  2289.     Rest .2
  2290.  
  2291.     PUT (GorillaX(Player), GorillaY(Player)), GorR&, PSET
  2292.  
  2293.     PLAY "MFO0L32EFGEFDC"
  2294.  
  2295.     Rest .2
  2296.  
  2297.   NEXT
  2298.  
  2299. END SUB
  2300.  
Tags: qbasic gorilla
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement