' Q B a s i c G o r i l l a s'' Copyright (C) Microsoft Corporation 1990'' Your mission is to hit your opponent with the exploding banana' by varying the angle and power of your throw, taking into account' wind speed, gravity, and the city skyline.'' Speed of this game is determined by the constant SPEEDCONST. If the' program is too slow or too fast adjust the "CONST SPEEDCONST = 500" line' below. The larger the number the faster the game will go.'' To run this game, press Shift+F5.'' To exit QBasic, press Alt, F, X.'' To get help on a BASIC keyword, move the cursor to the keyword and press' F1 or click the right mouse button.''Set default data type to integer for faster game playDEFINT A-Z'Sub DeclarationsDECLARE SUB DoSun (Mouth)DECLARE SUB SetScreen ()DECLARE SUB EndGame ()DECLARE SUB Center (Row, Text$)DECLARE SUB Intro ()DECLARE SUB SparklePause ()DECLARE SUB GetInputs (Player1$, Player2$, NumGames)DECLARE SUB PlayGame (Player1$, Player2$, NumGames)DECLARE SUB DoExplosion (x#, y#)DECLARE SUB MakeCityScape (BCoor() AS ANY)DECLARE SUB PlaceGorillas (BCoor() AS ANY)DECLARE SUB UpdateScores (Record(), PlayerNum, Results)DECLARE SUB DrawGorilla (x, y, arms)DECLARE SUB GorillaIntro (Player1$, Player2$)DECLARE SUB Rest (t#)DECLARE SUB VictoryDance (Player)DECLARE SUB ClearGorillas ()DECLARE SUB DrawBan (xc#, yc#, r, bc)DECLARE FUNCTION Scl (n!)DECLARE FUNCTION GetNum# (Row, Col)DECLARE FUNCTION DoShot (PlayerNum, x, y)DECLARE FUNCTION ExplodeGorilla (x#, y#)DECLARE FUNCTION Getn# (Row, Col)DECLARE FUNCTION PlotShot (StartX, StartY, Angle#, Velocity, PlayerNum)DECLARE FUNCTION CalcDelay! ()'Make all arrays Dynamic'$DYNAMIC'User-Defined TYPEsTYPE XYPointXCoor AS INTEGERYCoor AS INTEGEREND TYPE'ConstantsCONST SPEEDCONST = 500CONST TRUE = -1CONST FALSE = NOT TRUECONST HITSELF = 1CONST BACKATTR = 0CONST OBJECTCOLOR = 1CONST WINDOWCOLOR = 14CONST SUNATTR = 3CONST SUNHAPPY = FALSECONST SUNSHOCK = TRUECONST RIGHTUP = 1CONST LEFTUP = 2CONST ARMSDOWN = 3'Global VariablesDIM SHARED GorillaX(1 TO 2) 'Location of the two gorillasDIM SHARED GorillaY(1 TO 2)DIM SHARED LastBuildingDIM SHARED pi#DIM SHARED LBan&(x), RBan&(x), UBan&(x), DBan&(x) 'Graphical picture of bananaDIM SHARED GorD&(120) 'Graphical picture of Gorilla arms downDIM SHARED GorL&(120) 'Gorilla left arm raisedDIM SHARED GorR&(120) 'Gorilla right arm raisedDIM SHARED gravity#DIM SHARED Wind'Screen Mode VariablesDIM SHARED ScrHeightDIM SHARED ScrWidthDIM SHARED ModeDIM SHARED MaxCol'Screen Color VariablesDIM SHARED ExplosionColorDIM SHARED SunColorDIM SHARED BackColorDIM SHARED SunHitDIM SHARED SunHtDIM SHARED GHeightDIM SHARED MachSpeed AS SINGLEDEF FnRan (x) = INT(RND(1) * x) + 1DEF SEG = 0 ' Set NumLock to ONKeyFlags = PEEK(1047)IF (KeyFlags AND 32) = 0 THENPOKE 1047, KeyFlags OR 32END IFDEF SEGGOSUB InitVarsIntroGetInputs Name1$, Name2$, NumGamesGorillaIntro Name1$, Name2$PlayGame Name1$, Name2$, NumGamesDEF SEG = 0 ' Restore NumLock statePOKE 1047, KeyFlagsDEF SEGENDCGABanana:'BananaLeftDATA 327686, -252645316, 60'BananaDownDATA 196618, -1057030081, 49344'BananaUpDATA 196618, -1056980800, 63'BananaRightDATA 327686, 1010580720, 240EGABanana:'BananaLeftDATA 458758,202116096,471604224,943208448,943208448,943208448,471604224,202116096,0'BananaDownDATA 262153, -2134835200, -2134802239, -2130771968, -2130738945,8323072, 8323199, 4063232, 4063294'BananaUpDATA 262153, 4063232, 4063294, 8323072, 8323199, -2130771968, -2130738945, -2134835200,-2134802239'BananaRightDATA 458758, -1061109760, -522133504, 1886416896, 1886416896, 1886416896,-522133504,-1061109760,0InitVars:pi# = 4 * ATN(1#)'This is a clever way to pick the best graphics mode availableON ERROR GOTO ScreenModeErrorMode = 9SCREEN ModeON ERROR GOTO PaletteErrorIF Mode = 9 THEN PALETTE 4, 0 'Check for 64K EGAON ERROR GOTO 0MachSpeed = CalcDelayIF Mode = 9 THENScrWidth = 640ScrHeight = 350GHeight = 25RESTORE EGABananaREDIM LBan&(8), RBan&(8), UBan&(8), DBan&(8)FOR i = 0 TO 8READ LBan&(i)NEXT iFOR i = 0 TO 8READ DBan&(i)NEXT iFOR i = 0 TO 8READ UBan&(i)NEXT iFOR i = 0 TO 8READ RBan&(i)NEXT iSunHt = 39ELSEScrWidth = 320ScrHeight = 200GHeight = 12RESTORE CGABananaREDIM LBan&(2), RBan&(2), UBan&(2), DBan&(2)REDIM GorL&(20), GorD&(20), GorR&(20)FOR i = 0 TO 2READ LBan&(i)NEXT iFOR i = 0 TO 2READ DBan&(i)NEXT iFOR i = 0 TO 2READ UBan&(i)NEXT iFOR i = 0 TO 2READ RBan&(i)NEXT iMachSpeed = MachSpeed * 1.3SunHt = 20END IFRETURNScreenModeError:IF Mode = 1 THENCLSLOCATE 10, 5PRINT "Sorry, you must have CGA, EGA color, or VGA graphics to play GORILLA.BAS"ENDELSEMode = 1RESUMEEND IFPaletteError:Mode = 1 '64K EGA cards will run in CGA mode.RESUME NEXTREM $STATIC'CalcDelay:' Checks speed of the machine.FUNCTION CalcDelay!s! = TIMERDOi! = i! + 1LOOP UNTIL TIMER - s! >= .5CalcDelay! = i!END FUNCTION' Center:' Centers and prints a text string on a given row' Parameters:' Row - screen row number' Text$ - text to be printed'SUB Center (Row, Text$)Col = MaxCol \ 2LOCATE Row, Col - (LEN(Text$) / 2 + .5)PRINT Text$;END SUB' DoExplosion:' Produces explosion when a shot is fired' Parameters:' X#, Y# - location of explosion'SUB DoExplosion (x#, y#)PLAY "MBO0L32EFGEFDC"Radius = ScrHeight / 50IF Mode = 9 THEN Inc# = .5 ELSE Inc# = .41FOR c# = 0 TO Radius STEP Inc#CIRCLE (x#, y#), c#, ExplosionColorNEXT c#FOR c# = Radius TO 0 STEP (-1 * Inc#)CIRCLE (x#, y#), c#, BACKATTRFOR i = 1 TO 100NEXT iRest .005NEXT c#END SUB' DoShot:' Controls banana shots by accepting player input and plotting' shot angle' Parameters:' PlayerNum - Player' x, y - Player's gorilla position'FUNCTION DoShot (PlayerNum, x, y)'Input shotIF PlayerNum = 1 THENLocateCol = 1ELSEIF Mode = 9 THENLocateCol = 66ELSELocateCol = 26END IFEND IFLOCATE 2, LocateColPRINT "Angle:";Angle# = GetNum#(2, LocateCol + 7)LOCATE 3, LocateColPRINT "Velocity:";Velocity = GetNum#(3, LocateCol + 10)IF PlayerNum = 2 THENAngle# = 180 - Angle#END IF'Erase inputFOR i = 1 TO 4LOCATE i, 1PRINT SPACE$(30 \ (80 \ MaxCol));LOCATE i, (50 \ (80 \ MaxCol))PRINT SPACE$(30 \ (80 \ MaxCol));NEXTSunHit = FALSEPlayerHit = PlotShot(x, y, Angle#, Velocity, PlayerNum)IF PlayerHit = 0 THENDoShot = FALSEELSEDoShot = TRUEIF PlayerHit = PlayerNum THEN PlayerNum = 3 - PlayerNumVictoryDance PlayerNumEND IFEND FUNCTION' DoSun:' Draws the sun at the top of the screen.' Parameters:' Mouth - If TRUE draws "O" mouth else draws a smile mouth.'SUB DoSun (Mouth)'set position of sunx = ScrWidth \ 2: y = Scl(25)'clear old sunLINE (x - Scl(22), y - Scl(18))-(x + Scl(22), y + Scl(18)), BACKATTR, BF'draw new sun:'bodyCIRCLE (x, y), Scl(12), SUNATTRPAINT (x, y), SUNATTR'raysLINE (x - Scl(20), y)-(x + Scl(20), y), SUNATTRLINE (x, y - Scl(15))-(x, y + Scl(15)), SUNATTRLINE (x - Scl(15), y - Scl(10))-(x + Scl(15), y + Scl(10)), SUNATTRLINE (x - Scl(15), y + Scl(10))-(x + Scl(15), y - Scl(10)), SUNATTRLINE (x - Scl(8), y - Scl(13))-(x + Scl(8), y + Scl(13)), SUNATTRLINE (x - Scl(8), y + Scl(13))-(x + Scl(8), y - Scl(13)), SUNATTRLINE (x - Scl(18), y - Scl(5))-(x + Scl(18), y + Scl(5)), SUNATTRLINE (x - Scl(18), y + Scl(5))-(x + Scl(18), y - Scl(5)), SUNATTR'mouthIF Mouth THEN 'draw "o" mouthCIRCLE (x, y + Scl(5)), Scl(2.9), 0PAINT (x, y + Scl(5)), 0, 0ELSE 'draw smileCIRCLE (x, y), Scl(8), 0, (210 * pi# / 180), (330 * pi# / 180)END IF'eyesCIRCLE (x - 3, y - 2), 1, 0CIRCLE (x + 3, y - 2), 1, 0PSET (x - 3, y - 2), 0PSET (x + 3, y - 2), 0END SUB'DrawBan:' Draws the banana'Parameters:' xc# - Horizontal Coordinate' yc# - Vertical Coordinate' r - rotation position (0-3). ( \_/ ) /-\' bc - if TRUE then DrawBan draws the banana ELSE it erases the bananaSUB DrawBan (xc#, yc#, r, bc)SELECT CASE rCASE 0IF bc THEN PUT (xc#, yc#), LBan&, PSET ELSE PUT (xc#, yc#), LBan&, XORCASE 1IF bc THEN PUT (xc#, yc#), UBan&, PSET ELSE PUT (xc#, yc#), UBan&, XORCASE 2IF bc THEN PUT (xc#, yc#), DBan&, PSET ELSE PUT (xc#, yc#), DBan&, XORCASE 3IF bc THEN PUT (xc#, yc#), RBan&, PSET ELSE PUT (xc#, yc#), RBan&, XOREND SELECTEND SUB'DrawGorilla:' Draws the Gorilla in either CGA or EGA mode' and saves the graphics data in an array.'Parameters:' x - x coordinate of gorilla' y - y coordinate of the gorilla' arms - either Left up, Right up, or both downSUB DrawGorilla (x, y, arms)DIM i AS SINGLE ' Local index must be single precision'draw headLINE (x - Scl(4), y)-(x + Scl(2.9), y + Scl(6)), OBJECTCOLOR, BFLINE (x - Scl(5), y + Scl(2))-(x + Scl(4), y + Scl(4)), OBJECTCOLOR, BF'draw eyes/browLINE (x - Scl(3), y + Scl(2))-(x + Scl(2), y + Scl(2)), 0'draw nose if egaIF Mode = 9 THENFOR i = -2 TO -1PSET (x + i, y + 4), 0PSET (x + i + 3, y + 4), 0NEXT iEND IF'neckLINE (x - Scl(3), y + Scl(7))-(x + Scl(2), y + Scl(7)), OBJECTCOLOR'bodyLINE (x - Scl(8), y + Scl(8))-(x + Scl(6.9), y + Scl(14)), OBJECTCOLOR, BFLINE (x - Scl(6), y + Scl(15))-(x + Scl(4.9), y + Scl(20)), OBJECTCOLOR, BF'legsFOR i = 0 TO 4CIRCLE (x + Scl(i), y + Scl(25)), Scl(10), OBJECTCOLOR, 3 * pi# / 4, 9 * pi# / 8CIRCLE (x + Scl(-6) + Scl(i - .1), y + Scl(25)), Scl(10), OBJECTCOLOR, 15 * pi# / 8, pi# / 4NEXT'chestCIRCLE (x - Scl(4.9), y + Scl(10)), Scl(4.9), 0, 3 * pi# / 2, 0CIRCLE (x + Scl(4.9), y + Scl(10)), Scl(4.9), 0, pi#, 3 * pi# / 2FOR i = -5 TO -1SELECT CASE armsCASE 1'Right arm upCIRCLE (x + Scl(i - .1), y + Scl(14)), Scl(9), OBJECTCOLOR, 3 * pi# / 4, 5 * pi# / 4CIRCLE (x + Scl(4.9) + Scl(i), y + Scl(4)), Scl(9), OBJECTCOLOR, 7 * pi# / 4, pi# / 4GET (x - Scl(15), y - Scl(1))-(x + Scl(14), y + Scl(28)), GorR&CASE 2'Left arm upCIRCLE (x + Scl(i - .1), y + Scl(4)), Scl(9), OBJECTCOLOR, 3 * pi# / 4, 5 * pi# / 4CIRCLE (x + Scl(4.9) + Scl(i), y + Scl(14)), Scl(9), OBJECTCOLOR, 7 * pi# / 4, pi# / 4GET (x - Scl(15), y - Scl(1))-(x + Scl(14), y + Scl(28)), GorL&CASE 3'Both arms downCIRCLE (x + Scl(i - .1), y + Scl(14)), Scl(9), OBJECTCOLOR, 3 * pi# / 4, 5 * pi# / 4CIRCLE (x + Scl(4.9) + Scl(i), y + Scl(14)), Scl(9), OBJECTCOLOR, 7 * pi# / 4, pi# / 4GET (x - Scl(15), y - Scl(1))-(x + Scl(14), y + Scl(28)), GorD&END SELECTNEXT iEND SUB'ExplodeGorilla:' Causes gorilla explosion when a direct hit occurs'Parameters:' X#, Y# - shot locationFUNCTION ExplodeGorilla (x#, y#)YAdj = Scl(12)XAdj = Scl(5)SclX# = ScrWidth / 320SclY# = ScrHeight / 200IF x# < ScrWidth / 2 THEN PlayerHit = 1 ELSE PlayerHit = 2PLAY "MBO0L16EFGEFDC"FOR i = 1 TO 8 * SclX#CIRCLE (GorillaX(PlayerHit) + 3.5 * SclX# + XAdj, GorillaY(PlayerHit) + 7 * SclY# + YAdj), i, ExplosionColor, , , -1.57LINE (GorillaX(PlayerHit) + 7 * SclX#, GorillaY(PlayerHit) + 9 * SclY# - i)-(GorillaX(PlayerHit), GorillaY(PlayerHit) + 9 * SclY# - i), ExplosionColorNEXT iFOR i = 1 TO 16 * SclX#IF i < (8 * SclX#) THEN CIRCLE (GorillaX(PlayerHit) + 3.5 * SclX# + XAdj, GorillaY(PlayerHit) + 7 * SclY# + YAdj), (8 * SclX# + 1) - i, BACKATTR, , , -1.57CIRCLE (GorillaX(PlayerHit) + 3.5 * SclX# + XAdj, GorillaY(PlayerHit) + YAdj), i, i MOD 2 + 1, , , -1.57NEXT iFOR i = 24 * SclX# TO 1 STEP -1CIRCLE (GorillaX(PlayerHit) + 3.5 * SclX# + XAdj, GorillaY(PlayerHit) + YAdj), i, BACKATTR, , , -1.57FOR Count = 1 TO 200NEXTNEXT iExplodeGorilla = PlayerHitEND FUNCTION'GetInputs:' Gets user inputs at beginning of game'Parameters:' Player1$, Player2$ - player names' NumGames - number of games to playSUB GetInputs (Player1$, Player2$, NumGames)COLOR 7, 0CLSLOCATE 8, 15LINE INPUT "Name of Player 1 (Default = 'Player 1'): "; Player1$IF Player1$ = "" THENPlayer1$ = "Player 1"ELSEPlayer1$ = LEFT$(Player1$, 10)END IFLOCATE 10, 15LINE INPUT "Name of Player 2 (Default = 'Player 2'): "; Player2$IF Player2$ = "" THENPlayer2$ = "Player 2"ELSEPlayer2$ = LEFT$(Player2$, 10)END IFDOLOCATE 12, 56: PRINT SPACE$(25);LOCATE 12, 13INPUT "Play to how many total points (Default = 3)"; game$NumGames = VAL(LEFT$(game$, 2))LOOP UNTIL NumGames > 0 AND LEN(game$) < 3 OR LEN(game$) = 0IF NumGames = 0 THEN NumGames = 3DOLOCATE 14, 53: PRINT SPACE$(28);LOCATE 14, 17INPUT "Gravity in Meters/Sec (Earth = 9.8)"; grav$gravity# = VAL(grav$)LOOP UNTIL gravity# > 0 OR LEN(grav$) = 0IF gravity# = 0 THEN gravity# = 9.8END SUB'GetNum:' Gets valid numeric input from user'Parameters:' Row, Col - location to echo inputFUNCTION GetNum# (Row, Col)Result$ = ""Done = FALSEWHILE INKEY$ <> "": WEND 'Clear keyboard bufferDO WHILE NOT DoneLOCATE Row, ColPRINT Result$; CHR$(95); " ";Kbd$ = INKEY$SELECT CASE Kbd$CASE "0" TO "9"Result$ = Result$ + Kbd$CASE "."IF INSTR(Result$, ".") = 0 THENResult$ = Result$ + Kbd$END IFCASE CHR$(13)IF VAL(Result$) > 360 THENResult$ = ""ELSEDone = TRUEEND IFCASE CHR$(8)IF LEN(Result$) > 0 THENResult$ = LEFT$(Result$, LEN(Result$) - 1)END IFCASE ELSEIF LEN(Kbd$) > 0 THENBEEPEND IFEND SELECTLOOPLOCATE Row, ColPRINT Result$; " ";GetNum# = VAL(Result$)END FUNCTION'GorillaIntro:' Displays gorillas on screen for the first time' allows the graphical data to be put into an array'Parameters:' Player1$, Player2$ - The names of the players'SUB GorillaIntro (Player1$, Player2$)LOCATE 16, 34: PRINT "--------------"LOCATE 18, 34: PRINT "V = View Intro"LOCATE 19, 34: PRINT "P = Play Game"LOCATE 21, 35: PRINT "Your Choice?"DO WHILE Char$ = ""Char$ = INKEY$LOOPIF Mode = 1 THENx = 125y = 100ELSEx = 278y = 175END IFSCREEN ModeSetScreenIF Mode = 1 THEN Center 5, "Please wait while gorillas are drawn."VIEW PRINT 9 TO 24IF Mode = 9 THEN PALETTE OBJECTCOLOR, BackColorDrawGorilla x, y, ARMSDOWNCLS 2DrawGorilla x, y, LEFTUPCLS 2DrawGorilla x, y, RIGHTUPCLS 2VIEW PRINT 1 TO 25IF Mode = 9 THEN PALETTE OBJECTCOLOR, 46IF UCASE$(Char$) = "V" THENCenter 2, "Q B A S I C G O R I L L A S"Center 5, " STARRING: "P$ = Player1$ + " AND " + Player2$Center 7, P$PUT (x - 13, y), GorD&, PSETPUT (x + 47, y), GorD&, PSETRest 1PUT (x - 13, y), GorL&, PSETPUT (x + 47, y), GorR&, PSETPLAY "t120o1l16b9n0baan0bn0bn0baaan0b9n0baan0b"Rest .3PUT (x - 13, y), GorR&, PSETPUT (x + 47, y), GorL&, PSETPLAY "o2l16e-9n0e-d-d-n0e-n0e-n0e-d-d-d-n0e-9n0e-d-d-n0e-"Rest .3PUT (x - 13, y), GorL&, PSETPUT (x + 47, y), GorR&, PSETPLAY "o2l16g-9n0g-een0g-n0g-n0g-eeen0g-9n0g-een0g-"Rest .3PUT (x - 13, y), GorR&, PSETPUT (x + 47, y), GorL&, PSETPLAY "o2l16b9n0baan0g-n0g-n0g-eeen0o1b9n0baan0b"Rest .3FOR i = 1 TO 4PUT (x - 13, y), GorL&, PSETPUT (x + 47, y), GorR&, PSETPLAY "T160O0L32EFGEFDC"Rest .1PUT (x - 13, y), GorR&, PSETPUT (x + 47, y), GorL&, PSETPLAY "T160O0L32EFGEFDC"Rest .1NEXTEND IFEND SUB'Intro:' Displays game introductionSUB IntroSCREEN 0WIDTH 80, 25MaxCol = 80COLOR 15, 0CLSCenter 4, "Q B a s i c G O R I L L A S"COLOR 7Center 6, "Copyright (C) Microsoft Corporation 1990"Center 8, "Your mission is to hit your opponent with the exploding"Center 9, "banana by varying the angle and power of your throw, taking"Center 10, "into account wind speed, gravity, and the city skyline."Center 11, "The wind speed is shown by a directional arrow at the bottom"Center 12, "of the playing field, its length relative to its strength."Center 24, "Press any key to continue"PLAY "MBT160O1L8CDEDCDL4ECC"SparklePauseIF Mode = 1 THEN MaxCol = 40END SUB'MakeCityScape:' Creates random skyline for game'Parameters:' BCoor() - a user-defined type array which stores the coordinates of' the upper left corner of each building.SUB MakeCityScape (BCoor() AS XYPoint)x = 2'Set the sloping trend of the city scape. NewHt is new building heightSlope = FnRan(6)SELECT CASE SlopeCASE 1: NewHt = 15 'Upward slopeCASE 2: NewHt = 130 'Downward slopeCASE 3 TO 5: NewHt = 15 '"V" slope - most commonCASE 6: NewHt = 130 'Inverted "V" slopeEND SELECTIF Mode = 9 THENBottomLine = 335 'Bottom of buildingHtInc = 10 'Increase value for new heightDefBWidth = 37 'Default building heightRandomHeight = 120 'Random height differenceWWidth = 3 'Window widthWHeight = 6 'Window heightWDifV = 15 'Counter for window spacing - verticalWDifh = 10 'Counter for window spacing - horizontalELSEBottomLine = 190HtInc = 6NewHt = NewHt * 20 \ 35 'Adjust for CGADefBWidth = 18RandomHeight = 54WWidth = 1WHeight = 2WDifV = 5WDifh = 4END IFCurBuilding = 1DOSELECT CASE SlopeCASE 1NewHt = NewHt + HtIncCASE 2NewHt = NewHt - HtIncCASE 3 TO 5IF x > ScrWidth \ 2 THENNewHt = NewHt - 2 * HtIncELSENewHt = NewHt + 2 * HtIncEND IFCASE 4IF x > ScrWidth \ 2 THENNewHt = NewHt + 2 * HtIncELSENewHt = NewHt - 2 * HtIncEND IFEND SELECT'Set width of building and check to see if it would go off the screenBWidth = FnRan(DefBWidth) + DefBWidthIF x + BWidth > ScrWidth THEN BWidth = ScrWidth - x - 2'Set height of building and check to see if it goes below screenBHeight = FnRan(RandomHeight) + NewHtIF BHeight < HtInc THEN BHeight = HtInc'Check to see if Building is too highIF BottomLine - BHeight <= MaxHeight + GHeight THEN BHeight = MaxHeight + GHeight - 5'Set the coordinates of the building into the arrayBCoor(CurBuilding).XCoor = xBCoor(CurBuilding).YCoor = BottomLine - BHeightIF Mode = 9 THEN BuildingColor = FnRan(3) + 4 ELSE BuildingColor = 2'Draw the building, outline first, then filledLINE (x - 1, BottomLine + 1)-(x + BWidth + 1, BottomLine - BHeight - 1), BACKGROUND, BLINE (x, BottomLine)-(x + BWidth, BottomLine - BHeight), BuildingColor, BF'Draw the windowsc = x + 3DOFOR i = BHeight - 3 TO 7 STEP -WDifVIF Mode <> 9 THENWinColr = (FnRan(2) - 2) * -3ELSEIF FnRan(4) = 1 THENWinColr = 8ELSEWinColr = WINDOWCOLOREND IFLINE (c, BottomLine - i)-(c + WWidth, BottomLine - i + WHeight), WinColr, BFNEXTc = c + WDifhLOOP UNTIL c >= x + BWidth - 3x = x + BWidth + 2CurBuilding = CurBuilding + 1LOOP UNTIL x > ScrWidth - HtIncLastBuilding = CurBuilding - 1'Set Wind speedWind = FnRan(10) - 5IF FnRan(3) = 1 THENIF Wind > 0 THENWind = Wind + FnRan(10)ELSEWind = Wind - FnRan(10)END IFEND IF'Draw Wind speed arrowIF Wind <> 0 THENWindLine = Wind * 3 * (ScrWidth \ 320)LINE (ScrWidth \ 2, ScrHeight - 5)-(ScrWidth \ 2 + WindLine, ScrHeight - 5), ExplosionColorIF Wind > 0 THEN ArrowDir = -2 ELSE ArrowDir = 2LINE (ScrWidth / 2 + WindLine, ScrHeight - 5)-(ScrWidth / 2 + WindLine + ArrowDir, ScrHeight - 5 - 2), ExplosionColorLINE (ScrWidth / 2 + WindLine, ScrHeight - 5)-(ScrWidth / 2 + WindLine + ArrowDir, ScrHeight - 5 + 2), ExplosionColorEND IFEND SUB'PlaceGorillas:' PUTs the Gorillas on top of the buildings. Must have drawn' Gorillas first.'Parameters:' BCoor() - user-defined TYPE array which stores upper left coordinates' of each building.SUB PlaceGorillas (BCoor() AS XYPoint)IF Mode = 9 THENXAdj = 14YAdj = 30ELSEXAdj = 7YAdj = 16END IFSclX# = ScrWidth / 320SclY# = ScrHeight / 200'Place gorillas on second or third building from edgeFOR i = 1 TO 2IF i = 1 THEN BNum = FnRan(2) + 1 ELSE BNum = LastBuilding - FnRan(2)BWidth = BCoor(BNum + 1).XCoor - BCoor(BNum).XCoorGorillaX(i) = BCoor(BNum).XCoor + BWidth / 2 - XAdjGorillaY(i) = BCoor(BNum).YCoor - YAdjPUT (GorillaX(i), GorillaY(i)), GorD&, PSETNEXT iEND SUB'PlayGame:' Main game play routine'Parameters:' Player1$, Player2$ - player names' NumGames - number of games to playSUB PlayGame (Player1$, Player2$, NumGames)DIM BCoor(0 TO 30) AS XYPointDIM TotalWins(1 TO 2)J = 1FOR i = 1 TO NumGamesCLSRANDOMIZE (TIMER)CALL MakeCityScape(BCoor())CALL PlaceGorillas(BCoor())DoSun SUNHAPPYHit = FALSEDO WHILE Hit = FALSEJ = 1 - JLOCATE 1, 1PRINT Player1$LOCATE 1, (MaxCol - 1 - LEN(Player2$))PRINT Player2$Center 23, LTRIM$(STR$(TotalWins(1))) + ">Score<" + LTRIM$(STR$(TotalWins(2)))Tosser = J + 1: Tossee = 3 - J'Plot the shot. Hit is true if Gorilla gets hit.Hit = DoShot(Tosser, GorillaX(Tosser), GorillaY(Tosser))'Reset the sun, if it got hitIF SunHit THEN DoSun SUNHAPPYIF Hit = TRUE THEN CALL UpdateScores(TotalWins(), Tosser, Hit)LOOPSLEEP 1NEXT iSCREEN 0WIDTH 80, 25COLOR 7, 0MaxCol = 80CLSCenter 8, "GAME OVER!"Center 10, "Score:"LOCATE 11, 30: PRINT Player1$; TAB(50); TotalWins(1)LOCATE 12, 30: PRINT Player2$; TAB(50); TotalWins(2)Center 24, "Press any key to continue"SparklePauseCOLOR 7, 0CLSEND SUB'PlayGame:' Plots banana shot across the screen'Parameters:' StartX, StartY - starting shot location' Angle - shot angle' Velocity - shot velocity' PlayerNum - the banana throwerFUNCTION PlotShot (StartX, StartY, Angle#, Velocity, PlayerNum)Angle# = Angle# / 180 * pi# 'Convert degree angle to radiansRadius = Mode MOD 7InitXVel# = COS(Angle#) * VelocityInitYVel# = SIN(Angle#) * Velocityoldx# = StartXoldy# = StartY'draw gorilla tossIF PlayerNum = 1 THENPUT (StartX, StartY), GorL&, PSETELSEPUT (StartX, StartY), GorR&, PSETEND IF'throw soundPLAY "MBo0L32A-L64CL16BL64A+"Rest .1'redraw gorillaPUT (StartX, StartY), GorD&, PSETadjust = Scl(4) 'For scaling CGAxedge = Scl(9) * (2 - PlayerNum) 'Find leading edge of banana for checkImpact = FALSEShotInSun = FALSEOnScreen = TRUEPlayerHit = 0NeedErase = FALSEStartXPos = StartXStartYPos = StartY - adjust - 3IF PlayerNum = 2 THENStartXPos = StartXPos + Scl(25)direction = Scl(4)ELSEdirection = Scl(-4)END IFIF Velocity < 2 THEN 'Shot too slow - hit selfx# = StartXy# = StartYpointval = OBJECTCOLOREND IFDO WHILE (NOT Impact) AND OnScreenRest .02'Erase old banana, if necessaryIF NeedErase THENNeedErase = FALSECALL DrawBan(oldx#, oldy#, oldrot, FALSE)END IFx# = StartXPos + (InitXVel# * t#) + (.5 * (Wind / 5) * t# ^ 2)y# = StartYPos + ((-1 * (InitYVel# * t#)) + (.5 * gravity# * t# ^ 2)) * (ScrHeight / 350)IF (x# >= ScrWidth - Scl(10)) OR (x# <= 3) OR (y# >= ScrHeight - 3) THENOnScreen = FALSEEND IFIF OnScreen AND y# > 0 THEN'check itLookY = 0LookX = Scl(8 * (2 - PlayerNum))DOpointval = POINT(x# + LookX, y# + LookY)IF pointval = 0 THENImpact = FALSEIF ShotInSun = TRUE THENIF ABS(ScrWidth \ 2 - x#) > Scl(20) OR y# > SunHt THEN ShotInSun = FALSEEND IFELSEIF pointval = SUNATTR AND y# < SunHt THENIF NOT SunHit THEN DoSun SUNSHOCKSunHit = TRUEShotInSun = TRUEELSEImpact = TRUEEND IFLookX = LookX + directionLookY = LookY + Scl(6)LOOP UNTIL Impact OR LookX <> Scl(4)IF NOT ShotInSun AND NOT Impact THEN'plot itrot = (t# * 10) MOD 4CALL DrawBan(x#, y#, rot, TRUE)NeedErase = TRUEEND IFoldx# = x#oldy# = y#oldrot = rotEND IFt# = t# + .1LOOPIF pointval <> OBJECTCOLOR AND Impact THENCALL DoExplosion(x# + adjust, y# + adjust)ELSEIF pointval = OBJECTCOLOR THENPlayerHit = ExplodeGorilla(x#, y#)END IFPlotShot = PlayerHitEND FUNCTION'Rest:' pauses the programSUB Rest (t#)s# = TIMERt2# = MachSpeed * t# / SPEEDCONSTDOLOOP UNTIL TIMER - s# > t2#END SUB'Scl:' Pass the number in to scaling for cga. If the number is a decimal, then we' want to scale down for cga or scale up for ega. This allows a full range' of numbers to be generated for scaling.' (i.e. for 3 to get scaled to 1, pass in 2.9)FUNCTION Scl (n!)IF n! <> INT(n!) THENIF Mode = 1 THEN n! = n! - 1END IFIF Mode = 1 THENScl = CINT(n! / 2 + .1)ELSEScl = CINT(n!)END IFEND FUNCTION'SetScreen:' Sets the appropriate color statementsSUB SetScreenIF Mode = 9 THENExplosionColor = 2BackColor = 1PALETTE 0, 1PALETTE 1, 46PALETTE 2, 44PALETTE 3, 54PALETTE 5, 7PALETTE 6, 4PALETTE 7, 3PALETTE 9, 63 'Display ColorELSEExplosionColor = 2BackColor = 0COLOR BackColor, 2END IFEND SUB'SparklePause:' Creates flashing border for intro and game over screensSUB SparklePauseCOLOR 4, 0A$ = "* * * * * * * * * * * * * * * * * "WHILE INKEY$ <> "": WEND 'Clear keyboard bufferWHILE INKEY$ = ""FOR A = 1 TO 5LOCATE 1, 1 'print horizontal sparklesPRINT MID$(A$, A, 80);LOCATE 22, 1PRINT MID$(A$, 6 - A, 80);FOR b = 2 TO 21 'Print Vertical sparklesc = (A + b) MOD 5IF c = 1 THENLOCATE b, 80PRINT "*";LOCATE 23 - b, 1PRINT "*";ELSELOCATE b, 80PRINT " ";LOCATE 23 - b, 1PRINT " ";END IFNEXT bNEXT AWENDEND SUB'UpdateScores:' Updates players' scores'Parameters:' Record - players' scores' PlayerNum - player' Results - results of player's shotSUB UpdateScores (Record(), PlayerNum, Results)IF Results = HITSELF THENRecord(ABS(PlayerNum - 3)) = Record(ABS(PlayerNum - 3)) + 1ELSERecord(PlayerNum) = Record(PlayerNum) + 1END IFEND SUB'VictoryDance:' gorilla dances after he has eliminated his opponent'Parameters:' Player - which gorilla is dancingSUB VictoryDance (Player)FOR i# = 1 TO 4PUT (GorillaX(Player), GorillaY(Player)), GorL&, PSETPLAY "MFO0L32EFGEFDC"Rest .2PUT (GorillaX(Player), GorillaY(Player)), GorR&, PSETPLAY "MFO0L32EFGEFDC"Rest .2NEXTEND SUB
QBasic Örnekler, QBasic Dökümanlar, QBasic Uygulamaları QBasic Kodlar, QBasic Dersler,QBasic Programlar, QBasic Ders Notları, QBasic Download, QBasic İndir
Efsanevi Goril Oyunu
Kaydol:
Kayıt Yorumları
(
Atom
)
Hiç yorum yok :
Yorum Gönder