home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / QBLOCKS / QBLOCKS.BAS next >
BASIC Source File  |  1993-12-01  |  54KB  |  1,179 lines

  1. '                                QBLOCKS.BAS
  2. '
  3. ' Press Page Down for information on running and modifying QBlocks.
  4. '
  5. ' To run this game, press Shift+F5.
  6. '
  7. ' To exit this program, press ALT, F, X.
  8. '
  9. ' To get help on a BASIC keyword, move the cursor to the keyword and press
  10. ' F1 or click the right mouse button.
  11. '
  12. '                             Suggested Changes
  13. '                             -----------------
  14. '
  15. ' There are many ways that you can modify this BASIC game.  The CONST
  16. ' statements below these comments and the DATA statements at the end
  17. ' of this screen can be modified to change the following:
  18. '
  19. '    Block shapes
  20. '    Block rotation
  21. '    Number of different block shapes
  22. '    Score needed to advance to next level
  23. '    Width of the game well
  24. '    Height of the game well
  25. '    Songs played during game
  26. '
  27. ' On the right side of each CONST statement, there is a comment that tells
  28. ' you what it does and how big or small you can set the value.  Above the
  29. ' DATA statements, there are comments that tell you the format of the
  30. ' information stored there.
  31. '
  32. ' On your own, you can also add exciting sound and visual effects or make any
  33. ' other changes that your imagination can dream up.  By reading the
  34. ' Learn BASIC Now book, you'll learn the techniques that will enable you
  35. ' to fully customize this game and to create games of your own.
  36. '
  37. ' If the game won't run after you have changed it, you can exit without
  38. ' saving your changes by pressing Alt, F, X and choosing NO.
  39. '
  40. ' If you do want to save your changes, press Alt, F, A and enter a filename
  41. ' for saving your version of the program.  Before you save your changes,
  42. ' however, you should make sure they work by running the program and
  43. ' verifying that your changes produce the desired results.  Also, always
  44. ' be sure to keep a backup of the original program.
  45. '
  46. DEFINT A-Z
  47.  
  48. ' Here are the BASIC CONST statements you can change.  The comments tell
  49. ' you the range that each CONST value can be changed, or any limitations.
  50. CONST WELLWIDTH = 10        ' Width of playing field (well).   Range 5 to 13.
  51. CONST WELLHEIGHT = 21       ' Height of playing field.  Range 4 to 21.
  52. CONST NUMSTYLES = 7         ' Number of unique shapes.  Range 1 to 20.  Make sure you read the notes above the DATA statements at the end of the main program before you change this number!
  53. CONST WINGAME = 1000000     ' Points required to win the game.  Range 200 to 9000000.
  54. CONST NEXTLEVEL = 300       ' Helps determine when the game advances to the next level.  (Each cleared level gives player 100 points) Range 100 to 2000.
  55. CONST BASESCORE = 1000      ' Number of points needed to advance to first level.
  56. CONST ROTATEDIR = 1         ' Control rotation of blocks. Can be 1 for clockwise, or 3 for counterclockwise.
  57. ' The following sound constants are used by the PLAY command to
  58. ' produce music during the game.  To change the sounds you hear, change
  59. ' these constants.  Refer to the online help for PLAY for the correct format.
  60. ' To completely remove sound from the game set the constants equal to null.
  61. ' For example:  PLAYINTRO = ""
  62. CONST PLAYCLEARROW = "MBT255L16O4CDEGO6C"         ' Tune played when a row is cleared.  Range unlimited.
  63. CONST PLAYINTRO = "MBT170O1L8CO2CO1CDCA-A-FGFA-F" ' Song played at game start.  Range unlimited.
  64. CONST PLAYGAMEOVER = "MBT255L16O6CO4GEDC"         ' Song when the game is lost.  Range unlimited.
  65. CONST PLAYNEWBLOCK = "MBT160L28N20L24N5"          ' Song when a new block is dropped.  Range unlimited.
  66. CONST PLAYWINGAME = "T255L16O6CO4GEDCCDEFGO6CEG"  ' Song when game is won.  Range unlimited.
  67.  
  68. ' The following CONST statements should not be changed like the ones above
  69. ' because the program relies on them being this value.
  70. CONST FALSE = 0             ' 0 means FALSE.
  71. CONST TRUE = NOT FALSE      ' Anything but 0 can be thought of as TRUE.
  72. CONST SPACEBAR = 32         ' ASCII value for space character. Drops the shape.
  73. CONST DOWNARROW = 80        ' Down arrow key.  Drops the shape.
  74. CONST RIGHTARROW = 77       ' Right arrow key.  Moves the shape right.
  75. CONST UPARROW = 72          ' Up arrow key.  Rotates the shape.
  76. CONST LEFTARROW = 75        ' Left arrow key.  Moves the shape left.
  77. CONST DOWNARROW2 = 50       ' 2 key.  Drops the shape.
  78. CONST RIGHTARROW2 = 54      ' 6 key.  Moves the shape right.
  79. CONST UPARROW2 = 56         ' 8 key.  Rotates the shape.
  80. CONST LEFTARROW2 = 52       ' 4 key.  Moves the shape left.
  81. CONST UPARROW3 = 53         ' 5 key.  Rotates the shape.
  82. CONST QUIT = "Q"            ' Q key.  Quits the game.
  83. CONST PAUSE = "P"           ' P key.  Pauses the game.
  84. CONST XMATRIX = 3           ' Width of the matrix that forms each falling unit.  See the discussions in Suggested Changes #2 and #3.
  85. CONST YMATRIX = 1           ' Depth of the matrix that forms each falling unit.
  86. CONST BYTESPERBLOCK = 76    ' Number of bytes required to store one block in Screen mode 7.
  87. CONST BLOCKVOLUME = (XMATRIX + 1) * (YMATRIX + 1)   ' Number of blocks in each shape.
  88. CONST ELEMENTSPERBLOCK = BLOCKVOLUME * BYTESPERBLOCK \ 2    ' Number of INTEGER array elements needed to store an image of a shape.
  89. CONST XSIZE = 13            ' Width, in pixels, of each block.  QBlocks assumes that the entire screen is 25 blocks wide.  Since the screen is 320 pixels wide, each block is approximately 13 pixels wide.
  90. CONST YSIZE = 8             ' Height, in pixels, of each block.  Again, QBlocks assumes that screen is 25 blocks high.  At 200 pixels down, each block is exactly 8 pixels high.
  91. CONST XOFFSET = 10          ' X position, in blocks, of the well.
  92. CONST YOFFSET = 2           ' Y position, in blocks, of the well.
  93. CONST WELLX = XSIZE * XOFFSET   ' X position, in pixels, of the start of the well.
  94. CONST WELLY = YSIZE * YOFFSET   ' Y position.
  95. CONST TILTVALUE = 9999000   ' Points required for QBlocks to tilt.
  96. CONST WELLCOLOR7 = 0        ' Well color for SCREEN 7.
  97. CONST WELLCOLOR1 = 0        ' Well color for SCREEN 1.
  98. CONST BORDERCOLOR1 = 8      ' Border color for SCREEN 1.
  99. CONST BORDERCOLOR7 = 15     ' Border color for SCREEN 7.
  100.  
  101. TYPE BlockType              ' Block datatype.
  102.     X AS INTEGER            ' Horizontal location within the well.
  103.     Y AS INTEGER            ' Vertical location within the well.
  104.     Style AS INTEGER        ' Define shape (and color, indirectly).
  105.     Rotation AS INTEGER     ' 4 possible values (0 to 3).
  106. END TYPE
  107.  
  108. ' SUB and FUNCTION declarations
  109. DECLARE FUNCTION CheckFit ()
  110. DECLARE FUNCTION GameOver ()
  111. DECLARE SUB AddBlockToWell ()
  112. DECLARE SUB CheckForFullRows ()
  113. DECLARE SUB Center (M$, Row)
  114. DECLARE SUB DeleteChunk (Highest%, Lowest%)
  115. DECLARE SUB DisplayIntro ()
  116. DECLARE SUB DisplayGameTitle ()
  117. DECLARE SUB DisplayChanges ()
  118. DECLARE SUB DrawBlock (X, Y, FillColor)
  119. DECLARE SUB InitScreen ()
  120. DECLARE SUB MakeInfoBox ()
  121. DECLARE SUB NewBlock ()
  122. DECLARE SUB PerformGame ()
  123. DECLARE SUB RedrawControls ()
  124. DECLARE SUB Show (b AS BlockType)
  125. DECLARE SUB UpdateScoring ()
  126. DECLARE SUB PutBlock (b AS BlockType)
  127. DECLARE SUB DrawAllShapes ()
  128. DECLARE SUB DrawPattern (Patttern)
  129. DECLARE SUB DrawPlayingField ()
  130.  
  131. ' DIM SHARED indicates that a variable is available to all subprograms.
  132. ' Without this statement, a variable used in one subprogram cannot be
  133. ' used by another subprogram or the main program.
  134. DIM SHARED Level AS INTEGER                                         ' Difficulty level.  0 is slowest, 9 is fastest.
  135. DIM SHARED WellBlocks(WELLWIDTH, WELLHEIGHT) AS INTEGER             ' 2 dimensional array to hold the falling shapes that have stopped falling and become part of the well.
  136. DIM SHARED CurBlock AS BlockType                                    ' The falling shape.
  137. DIM SHARED BlockShape(0 TO XMATRIX, 0 TO YMATRIX, 1 TO NUMSTYLES)   ' Holds the data required to make each shape.  Values determined by the DATA statements at the end of this window.
  138. DIM SHARED PrevScore AS LONG                                        ' Holds the previous level for scoring purposes.
  139. DIM SHARED Score AS LONG                                            ' Score.
  140. DIM SHARED ScreenWidth AS INTEGER                                   ' Width of the screen, in character-sized units.
  141. DIM SHARED ScreenMode AS INTEGER                                    ' Value of the graphics screen mode used.
  142. DIM SHARED WellColor AS INTEGER                                     ' Color inside the well.
  143. DIM SHARED BorderColor AS INTEGER                                   ' Color of well border and text.
  144. DIM SHARED OldBlock AS BlockType                                    ' An image of the last CurBlock.  Used to erase falling units when they move.
  145. DIM SHARED TargetTime AS SINGLE                                     ' Time to move the shape down again.
  146. DIM SHARED GameTiltScore AS LONG                                    ' Holds the value that this game will tilt at.
  147. DIM SHARED Temp(11175)  AS INTEGER                                  ' Used by several GET and PUT statements to store temporary screen images.
  148. DIM SHARED BlockColor(1 TO NUMSTYLES) AS INTEGER                    ' Block color array
  149. DIM SHARED BlockImage((NUMSTYLES * 4 + 3) * ELEMENTSPERBLOCK) AS INTEGER    ' Holds the binary image of each rotation of each shape for the PutBlock subprogram to use.
  150. DIM KeyFlags AS INTEGER                                             ' Internal state of the keyboard flags when game starts.  Hold the state so it can be restored when the games ends.
  151. DIM BadMode AS INTEGER                                              ' Store the status of a valid screen mode.
  152.  
  153.  
  154. ON ERROR GOTO ScreenError               ' Set up a place to jump to if an error occurs in the program.
  155. BadMode = FALSE
  156. ScreenMode = 7
  157. SCREEN ScreenMode                       ' Attempt to go into SCREEN 7 (EGA screen).
  158. IF BadMode = TRUE THEN                  ' If this attempt failed.
  159.     ScreenMode = 1
  160.     BadMode = FALSE
  161.     SCREEN ScreenMode                   ' Attempt to go into SCREEN 1 (CGA screen).
  162. END IF
  163. ON ERROR GOTO 0                         ' Turn off error handling.
  164.  
  165. IF BadMode = TRUE THEN                  ' If no graphics adapter.
  166.     CLS
  167.     LOCATE 10, 12: PRINT "CGA, EGA Color, or VGA graphics required to run QBLOCKS.BAS"
  168. ELSE
  169.     RANDOMIZE TIMER                     ' Create a new sequence of random numbers based on the clock.
  170.     DisplayIntro                        ' Show the opening screen.
  171.  
  172.     DEF SEG = 0                         ' Set the current segment to the low memory area.
  173.     KeyFlags = PEEK(1047)               ' Read the location that holds the keyboard flag.
  174.     IF (KeyFlags AND 32) = 0 THEN       ' If the NUM LOCK key is off
  175.         POKE 1047, KeyFlays OR 32       ' set the NUM LOCK key to on.
  176.     END IF
  177.     DEF SEG                             ' Restore the default segment.
  178.     
  179.     ' Read the pattern for each QBlocks shape.
  180.     FOR i = 1 TO NUMSTYLES                  ' Loop for the each shape
  181.         FOR j = 0 TO YMATRIX                ' and for the Y and X dimensions of
  182.             FOR k = 0 TO XMATRIX            ' each shape.
  183.                 READ BlockShape(k, j, i)    ' Actually read the data.
  184.             NEXT k
  185.         NEXT j
  186.     NEXT i
  187.     DrawAllShapes                       ' Draw all shapes in all four rotations.
  188.     PerformGame                         ' Play the game until the player quits.
  189.     DisplayChanges                      ' Show the suggested changes.
  190.    
  191.     DEF SEG = 0                         ' Set the current segment back to low memory where the keyboard flags are.
  192.     POKE 1047, KeyFlags AND 233         ' Set the NUM LOCK key back to where it was at the game start.
  193.     DEF SEG                             ' Restore the current segment back to BASIC's data group area.
  194.  
  195.     IF ScreenMode = 7 THEN PALETTE      ' Restore the default color palette if SCREEN 7 was used.
  196.  
  197. END IF
  198.  
  199. END                                     ' End of the main program code.
  200.  
  201.  
  202. ' The DATA statements below define the block shapes used in the game.
  203. ' Each shape contains 8 blocks (4 x 2).  A "1" means that there
  204. ' is a block in that space; "0" means that the block is blank.  The pattern
  205. ' for Style 1, for example, creates a shape that is 4 blocks wide.
  206. ' To change an existing block's shape, change a "0" to a "1" or a "1" to
  207. ' a "0".  To add new shapes, insert new DATA statements with the same format
  208. ' as those below, after the last group of DATA statements (style 7).  Be sure
  209. ' to change the NUMSTYLES constant at the beginning of this program to reflect
  210. ' the new number of block shapes for the game.
  211. ' IMPORTANT! Creating a completely blank block will cause QBlocks to fail.
  212.  
  213. ' Data for Style 1: Long
  214. DATA 1,1,1,1
  215. DATA 0,0,0,0
  216.  
  217. ' Data for Style 2: L Right
  218. DATA 1,1,1,0
  219. DATA 0,0,1,0
  220.  
  221. ' Data for Style 3: L Left
  222. DATA 0,1,1,1
  223. DATA 0,1,0,0
  224.  
  225. ' Data for Style 4: Z Right
  226. DATA 1,1,0,0
  227. DATA 0,1,1,0
  228.  
  229. ' Data for Style 5: Z Left
  230. DATA 0,1,1,0
  231. DATA 1,1,0,0
  232.  
  233. ' Data for Style 6: T
  234. DATA 1,1,1,0
  235. DATA 0,1,0,0
  236.  
  237. ' Data for Style 7: Square
  238. DATA 0,1,1,0
  239. DATA 0,1,1,0
  240.  
  241.  
  242. ScreenError:                            ' QBlocks uses this error handler to determine the highest available video mode.
  243.     BadMode = TRUE
  244.     RESUME NEXT
  245.  
  246. '----------------------------------------------------------------------------
  247. ' AddBlockToWell
  248. '
  249. '    After a shape stops falling, put it into the WellBlocks array
  250. '    so later falling shapes know where to stop.
  251. '
  252. '           PARAMETERS:    None.
  253. '----------------------------------------------------------------------------
  254. SUB AddBlockToWell
  255.    
  256.     FOR i = 0 TO XMATRIX                                    ' Loop through all elements in the array.
  257.         FOR j = 0 TO YMATRIX
  258.             IF BlockShape(i, j, CurBlock.Style) = 1 THEN    ' If there is a block in that space.
  259.                 SELECT CASE CurBlock.Rotation               ' Use the Rotation to determine how the blocks should map into the WellBlocks array.
  260.                     CASE 0              ' No rotation.
  261.                         WellBlocks(CurBlock.X + i, CurBlock.Y + j) = CurBlock.Style
  262.                     CASE 1              ' Rotated 90 degrees clockwise.
  263.                         WellBlocks(CurBlock.X - j + 2, CurBlock.Y + i - 1) = CurBlock.Style
  264.                     CASE 2              ' Rotated 180 degrees.
  265.                         WellBlocks(CurBlock.X - i + 3, CurBlock.Y - j + 1) = CurBlock.Style
  266.                     CASE 3               ' Rotated 270 degrees clockwise.
  267.                         WellBlocks(CurBlock.X + j + 1, CurBlock.Y - i + 2) = CurBlock.Style
  268.                 END SELECT
  269.             END IF
  270.         NEXT j
  271.     NEXT i
  272. END SUB
  273.  
  274. '----------------------------------------------------------------------------
  275. ' Center
  276. '
  277. '    Centers a string of text on a specified row.
  278. '
  279. '           PARAMETERS:    Text$ - Text to display on the screen.
  280. '                          Row   - Row on the screen where the text$ is
  281. '                                  displayed.
  282. '----------------------------------------------------------------------------
  283. SUB Center (text$, Row)
  284.  
  285.   LOCATE Row, (ScreenWidth - LEN(text$)) \ 2 + 1
  286.   PRINT text$;
  287.  
  288. END SUB
  289.  
  290. '----------------------------------------------------------------------------
  291. ' CheckFit
  292. '
  293. '    Checks to see if the shape will fit into its new position.
  294. '    Returns TRUE if it fits and FALSE if it does not fit.
  295. '
  296. '           PARAMETERS:    None
  297. '
  298. '----------------------------------------------------------------------------
  299. FUNCTION CheckFit
  300.  
  301.     CheckFit = TRUE                     ' Assume the shape will fit.
  302.    
  303.     FOR i = 0 TO XMATRIX                ' Loop through all the blocks in the
  304.         FOR j = 0 TO YMATRIX            ' shape and see if any would
  305.                                         ' overlap blocks already in the well.
  306.             IF BlockShape(i, j, CurBlock.Style) = 1 THEN    ' 1 means that space, within the falling shape, is filled with a block.
  307.                 SELECT CASE CurBlock.Rotation               ' Base the check on the rotation of the shape.
  308.                     CASE 0                         ' No rotation.
  309.                         NewX = CurBlock.X + i
  310.                         NewY = CurBlock.Y + j
  311.                     CASE 1                         ' Rotated 90 degrees clockwise, or 270 degrees counterclockwise.
  312.                         NewX = CurBlock.X - j + 2
  313.                         NewY = CurBlock.Y + i - 1
  314.                     CASE 2                         ' Rotated 180 degrees.
  315.                         NewX = CurBlock.X - i + 3
  316.                         NewY = CurBlock.Y - j + 1
  317.                     CASE 3                         ' Rotated 270 degrees clockwise, or 90 degrees counterclockwise.
  318.                         NewX = CurBlock.X + j + 1
  319.                         NewY = CurBlock.Y - i + 2
  320.                 END SELECT
  321.  
  322.                 ' Set CheckFit to false if the block would be out of the well.
  323.                 IF (NewX > WELLWIDTH - 1 OR NewX < 0 OR NewY > WELLHEIGHT - 1 OR NewY < 0) THEN
  324.                     CheckFit = FALSE
  325.                     EXIT FUNCTION
  326.  
  327.                 ' Otherwise, set CheckFit to false if the block overlaps
  328.                 ' an existing block.
  329.                 ELSEIF WellBlocks(NewX, NewY) THEN
  330.                     CheckFit = FALSE
  331.                     EXIT FUNCTION
  332.                 END IF
  333.  
  334.             END IF
  335.         NEXT j
  336.     NEXT i
  337.  
  338. END FUNCTION
  339.  
  340. '----------------------------------------------------------------------------
  341. ' CheckForFullRows
  342. '
  343. '    Checks for filled rows.  If a row is filled, delete it and move
  344. '    the blocks above down to fill the deleted row.
  345. '
  346. '           PARAMETERS:   None
  347. '----------------------------------------------------------------------------
  348. SUB CheckForFullRows
  349.  
  350.     DIM RowsToDelete(WELLHEIGHT)    ' Temporary array to track rows that should be deleted.
  351.     NumRowsToDelete = 0
  352.     i = WELLHEIGHT                  ' Begin scanning from the bottom up.
  353.     DO
  354.         DeleteRow = TRUE            ' Assume the row should be deleted.
  355.         j = 0
  356.         DO                          ' Scan within each row for blocks.
  357.             DeleteRow = DeleteRow * SGN(WellBlocks(j, i)) ' If any position is blank, DeleteRow is 0 (FALSE).
  358.             j = j + 1
  359.         LOOP WHILE DeleteRow = TRUE AND j < WELLWIDTH
  360.        
  361.         IF DeleteRow = TRUE THEN
  362.             ' Walk up the rows and copy them down in the WellBlocks array.
  363.             NumRowsToDelete = NumRowsToDelete + 1   ' Number of rows to delete.
  364.             RowsToDelete(i - NumDeleted) = TRUE     ' Mark the rows to be deleted, compensating for rows that have already been deleted below it.
  365.             NumDeleted = NumDeleted + 1             ' Compensates for rows that have been deleted already.
  366.            
  367.             ' Logically delete the row by moving all WellBlocks values down.
  368.             FOR Row = i TO 1 STEP -1
  369.                 FOR Col = 0 TO WELLWIDTH
  370.                     WellBlocks(Col, Row) = WellBlocks(Col, Row - 1)
  371.                 NEXT Col
  372.             NEXT Row
  373.         ELSE                        ' This row will not be deleted.
  374.             i = i - 1
  375.         END IF
  376.     LOOP WHILE i >= 1                ' Stop looping when the top of the well is reached.
  377.            
  378.     IF NumRowsToDelete > 0 THEN
  379.         Score = Score + 100 * NumRowsToDelete  ' Give 100 points for every row.
  380.        
  381.         ' Set Highest and Lowest such that any deleted row will initially set them.
  382.         Highest = -1
  383.         Lowest = 100
  384.        
  385.         ' Find where the highest and lowest rows to delete are.
  386.         FOR i = WELLHEIGHT TO 1 STEP -1
  387.             IF RowsToDelete(i) = TRUE THEN
  388.                 IF i > Highest THEN Highest = i
  389.                 IF i < Lowest THEN Lowest = i
  390.             END IF
  391.         NEXT i
  392.         
  393.         IF (Highest - Lowest) + 1 = NumRowsToDelete THEN    ' Only one contiguous group of rows to delete.
  394.             DeleteChunk Highest, Lowest
  395.         ELSE                                                ' Two groups of rows to delete.
  396.             ' Begin at Lowest and scan down for a row NOT to be deleted.
  397.             ' Then delete everything from Lowest to the row not to be deleted.
  398.             i = Lowest
  399.             DO WHILE i <= Highest
  400.                 IF RowsToDelete(i) = FALSE THEN
  401.                     DeleteChunk i - 1, Lowest
  402.                     EXIT DO
  403.                 ELSE
  404.                     i = i + 1
  405.                 END IF
  406.             LOOP
  407.            
  408.             ' Now look for the second group and delete those rows.
  409.             Lowest = i
  410.             DO WHILE RowsToDelete(Lowest) = FALSE
  411.                 Lowest = Lowest + 1
  412.             LOOP
  413.             DeleteChunk Highest, Lowest
  414.        
  415.         END IF
  416.     END IF
  417.  
  418. END SUB
  419.  
  420. '----------------------------------------------------------------------------
  421. ' DeleteChunk
  422. '
  423. '    Deletes a group of one or more rows.
  424. '
  425. '           PARAMETERS:    Highest - Highest row to delete (physically lowest
  426. '                                    on screen).
  427. '                          Lowest  - Lowest row to delete (physically highest
  428. '                                    on screen).
  429. '----------------------------------------------------------------------------
  430. SUB DeleteChunk (Highest, Lowest)
  431.    
  432.     ' GET the image of the row to delete.                              
  433.     GET (WELLX, Lowest * YSIZE + WELLY)-(WELLX + WELLWIDTH * XSIZE, (Highest + 1) * YSIZE + WELLY - 1), Temp
  434.     PLAY PLAYCLEARROW
  435.    
  436.     ' Flash the rows 3 times.
  437.     FOR Flash = 1 TO 3
  438.         PUT (WELLX, Lowest * YSIZE + WELLY), Temp, PRESET
  439.         DelayTime! = TIMER + .02
  440.         DO WHILE TIMER < DelayTime!: LOOP
  441.         PUT (WELLX, Lowest * YSIZE + WELLY), Temp, PSET
  442.         DelayTime! = TIMER + .02
  443.         DO WHILE TIMER < DelayTime!: LOOP
  444.     NEXT Flash
  445.    
  446.     ' Move all the rows above the deleted ones down.
  447.     GET (WELLX, WELLY)-(WELLX + WELLWIDTH * XSIZE, Lowest * YSIZE + WELLY), Temp
  448.     PUT (WELLX, (Highest - Lowest + 1) * YSIZE + WELLY), Temp, PSET
  449.     'Erase the area above the block which just moved down.
  450.     LINE (WELLX, WELLY)-(WELLX + WELLWIDTH * XSIZE, WELLY + (Highest - Lowest + 1) * YSIZE), WellColor, BF
  451. END SUB
  452.  
  453. '----------------------------------------------------------------------------
  454. ' DisplayChanges
  455. '
  456. '    Displays list of changes that the player can easily make.
  457. '
  458. '           PARAMETERS:   None
  459. '----------------------------------------------------------------------------
  460. SUB DisplayChanges
  461.  
  462.     DisplayGameTitle                            ' Print game title.
  463.     
  464.     COLOR 7
  465.     Center "The following game characteristics can be easily changed from", 5
  466.     Center "within the QuickBASIC Interpreter.  To change the values of  ", 6
  467.     Center "these characteristics, locate the corresponding CONST or DATA", 7
  468.     Center "statements in the source code and change their values, then  ", 8
  469.     Center "restart the program (press Shift + F5).                      ", 9
  470.  
  471.     COLOR 15
  472.     Center "Block shapes                         ", 11
  473.     Center "Block rotation                       ", 12
  474.     Center "Number of different block shapes     ", 13
  475.     Center "Score needed to advance to next level", 14
  476.     Center "Width of the game well               ", 15
  477.     Center "Height of the game well              ", 16
  478.     Center "Songs played during game             ", 17
  479.  
  480.     COLOR 7
  481.     Center "The CONST statements and instructions on changing them are   ", 19
  482.     Center "located at the beginning of the main program.                ", 20
  483.  
  484.     DO WHILE INKEY$ = "": LOOP                  ' Wait for any key to be pressed.
  485.     CLS                                         ' Clear screen.
  486.  
  487. END SUB
  488.  
  489. '----------------------------------------------------------------------------
  490. ' DisplayGameTitle
  491. '
  492. '    Displays title of the game.
  493. '
  494. '           PARAMETERS:    None.
  495. '----------------------------------------------------------------------------
  496. SUB DisplayGameTitle
  497.  
  498.     SCREEN 0
  499.     WIDTH 80, 25                                  ' Set width to 80, height to 25.
  500.     COLOR 4, 0                                    ' Set colors for red on black.
  501.     CLS                                           ' Clear the screen.
  502.     ScreenWidth = 80                              ' Set screen width variable to match current width.
  503.  
  504.     ' Draw outline around screen with extended ASCII characters.
  505.     LOCATE 1, 2
  506.     PRINT CHR$(201); STRING$(76, 205); CHR$(187);
  507.     FOR i% = 2 TO 24
  508.         LOCATE i%, 2
  509.         PRINT CHR$(186); TAB(79); CHR$(186);
  510.     NEXT i%
  511.     LOCATE 25, 2
  512.     PRINT CHR$(200); STRING$(76, 205); CHR$(188);
  513.  
  514.     'Print game title centered at top of screen
  515.     COLOR 0, 4
  516.     Center "      Microsoft      ", 1
  517.     Center "    Q B L O C K S    ", 2
  518.     Center "   Press any key to continue   ", 25  ' Center prompt on line 25.
  519.     COLOR 7, 0
  520.  
  521. END SUB
  522.  
  523. '----------------------------------------------------------------------------
  524. ' DisplayIntro
  525. '
  526. '    Explains the object of the game and how to play.
  527. '
  528. '           PARAMETERS:   None
  529. '----------------------------------------------------------------------------
  530. SUB DisplayIntro
  531.     
  532.     CLS
  533.     DisplayGameTitle
  534.    
  535.     Center "QBlocks challenges you to keep the well from filling.  Do this by", 5
  536.     Center "completely filling rows with blocks, making the rows disappear.  ", 6
  537.     Center "Move and rotate the falling shapes to get them into the best     ", 7
  538.     Center "position.  The game will get faster as you score more points.    ", 8
  539.  
  540.     COLOR 4                                 ' Change foreground color for line to red.
  541.     Center STRING$(74, 196), 11             ' Put horizontal red line on screen.
  542.     COLOR 7     ' White (7) letters.        ' Change foreground color back to white
  543.     Center " Game Controls ", 11            ' Display game controls.
  544.     Center "     General                             Block Control      ", 13
  545.     Center "                                     (Rotate)", 15
  546.     Center "   P - Pause                                 " + CHR$(24) + " (or 5)   ", 16
  547.     Center "      Q - Quit                         (Left) " + CHR$(27) + "   " + CHR$(26) + " (Right)   ", 17
  548.     Center "                                    " + CHR$(25), 18
  549.     Center "                                          (Drop)      ", 19
  550.     
  551.     DO                                      ' Wait for any key to be pressed.
  552.         kbd$ = UCASE$(INKEY$)
  553.     LOOP WHILE kbd$ = ""
  554.     IF kbd$ = "Q" THEN                      'Allow player to quit now
  555.         CLS
  556.         LOCATE 10, 30: PRINT "Really quit? (Y/N)";
  557.         DO
  558.             kbd$ = UCASE$(INKEY$)
  559.         LOOP WHILE kbd$ = ""
  560.         IF kbd$ = "Y" THEN
  561.             CLS
  562.             END
  563.         END IF
  564.     END IF
  565.  
  566. END SUB
  567.  
  568. '----------------------------------------------------------------------------
  569. ' DrawAllShapes
  570. '
  571. '    Quickly draws all shapes in all four rotations.  Uses GET
  572. '    to store the images so they can be PUT onto the screen
  573. '    later very quickly.
  574. '
  575. '           PARAMETERS:    None.
  576. '----------------------------------------------------------------------------
  577. SUB DrawAllShapes
  578.  
  579.     DIM b AS BlockType
  580.     SCREEN ScreenMode                   ' Set the appropriate screen mode.
  581.    
  582.     ' On EGA and VGA systems, appear to blank the screen.
  583.     IF ScreenMode = 7 THEN
  584.         DIM Colors(0 TO 15)             ' DIM an array of 16 elements.  By default, all elements are 0.
  585.         PALETTE USING Colors            ' Redefine the colors all to 0.
  586.         FOR i = 1 TO NUMSTYLES          ' Set block colors EGA, VGA
  587.             BlockColor(i) = ((i - 1) MOD 7) + 1
  588.         NEXT i
  589.     ELSE
  590.         FOR i = 1 TO NUMSTYLES          'Set block colors for CGA
  591.             BlockColor(i) = ((i - 1) MOD 3) + 1
  592.         NEXT i
  593.     END IF
  594.  
  595.     CLS
  596.     Count = 0                           ' Count determines how many shapes have been drawn on the screen and vertically where.
  597.     FOR shape = 1 TO NUMSTYLES          ' Loop through all shapes.
  598.  
  599.         RtSide = 4
  600.         DO
  601.             IF BlockShape(RtSide - 1, 0, shape) = 1 OR BlockShape(RtSide - 1, 1, shape) = 1 THEN EXIT DO
  602.             RtSide = RtSide - 1
  603.         LOOP UNTIL RtSide = 1
  604.  
  605.         LtSide = 0
  606.         DO
  607.             IF BlockShape(LtSide, 0, shape) = 1 OR BlockShape(LtSide, 1, shape) = 1 THEN EXIT DO
  608.             LtSide = LtSide + 1
  609.         LOOP UNTIL LtSide = 3
  610.  
  611.         FOR Rotation = 0 TO 3           ' Loop through all rotations.
  612.             b.X = Rotation * 4 + 2      ' Determine where to put the shape.
  613.             b.Y = Count + 2
  614.             b.Rotation = Rotation
  615.             b.Style = shape
  616.             Show b                      ' Draw the shape.
  617.            
  618.             X = b.X: Y = b.Y
  619.             SELECT CASE Rotation        ' Based on Rotation, determine where the shape really is on the screen.
  620.                 CASE 0                  ' No rotation.
  621.                     x1 = X: x2 = X + RtSide: y1 = Y: y2 = Y + 2
  622.                 CASE 1                  ' Rotated 90 degrees clockwise.
  623.                     x1 = X + 1: x2 = X + 3: y1 = Y - 1: y2 = Y + RtSide - 1
  624.                 CASE 2                  ' 180 degrees.
  625.                     x1 = X: x2 = X + 4 - LtSide: y1 = Y: y2 = Y + 2
  626.                 CASE 3                  ' Rotated 270 degrees clockwise.
  627.                     x1 = X + 1: x2 = X + 3: y1 = Y - 1: y2 = Y + 3 - LtSide
  628.             END SELECT
  629.            
  630.             ' Store the image of the rotated shape into an array for fast recall later.
  631.             GET (x1 * XSIZE, y1 * YSIZE)-(x2 * XSIZE, y2 * YSIZE), BlockImage(((shape - 1) * 4 + Rotation) * ELEMENTSPERBLOCK)
  632.        
  633.         NEXT Rotation
  634.        
  635.         Count = Count + 5               ' Increase Count by 5 to leave at least one blank line between shapes.
  636.         IF Count = 20 THEN              ' No space for any more shapes.
  637.             CLS
  638.             Count = 0
  639.         END IF
  640.    
  641.     NEXT shape
  642.    
  643.     CLS
  644.    
  645.     ' Changes the color palette if SCREEN is used.
  646.     IF ScreenMode = 7 THEN
  647.         PALETTE                         ' Restore default color settings.
  648.         PALETTE 6, 14                   ' Make brown (6) look like yellow (14).
  649.         PALETTE 14, 15                  ' Make yellow (14) look like bright white (15).
  650.     END IF
  651.  
  652. END SUB
  653.  
  654. '----------------------------------------------------------------------------
  655. ' DrawBlock
  656. '
  657. '    Draws one block of a QBlocks shape.
  658. '
  659. '           PARAMETERS:    X         - Horizontal screen location.
  660. '                          Y         - Vertical screen location.
  661. '                          FillColor - The primary color of the block.
  662. '                                      The top and left edges will be the
  663. '                                      brighter shade of that color.
  664. '----------------------------------------------------------------------------
  665. SUB DrawBlock (X, Y, FillColor)
  666.  
  667.     LINE (X * XSIZE + 2, Y * YSIZE + 2)-((X + 1) * XSIZE - 2, (Y + 1) * YSIZE - 2), FillColor, BF
  668.     LINE (X * XSIZE + 1, Y * YSIZE + 1)-((X + 1) * XSIZE - 1, Y * YSIZE + 1), FillColor + 8
  669.     LINE (X * XSIZE + 1, Y * YSIZE + 1)-(X * XSIZE + 1, (Y + 1) * YSIZE - 1), FillColor + 8
  670.  
  671. END SUB
  672.  
  673. '----------------------------------------------------------------------------
  674. ' DrawPattern
  675. '
  676. '    Draws a background pattern that is 32 pixels wide by 20 pixels
  677. '    deep.  Gets the pattern and duplicates it to fill the screen.
  678. '
  679. '           PARAMETERS:    Pattern - Which of the 10 available patterns to
  680. '                                    draw.
  681. '----------------------------------------------------------------------------
  682. SUB DrawPattern (Pattern)
  683.  
  684.     CLS
  685.     X = 1: Y = 1
  686.     DIM Temp2(215) AS INTEGER           ' Create an array to store the image.
  687.    
  688.     ' Draw the pattern specified.
  689.     SELECT CASE Pattern
  690.     CASE 0
  691.         j = Y + 21
  692.         FOR i = X TO X + 27 STEP 3
  693.             j = j - 2
  694.             LINE (i, j)-(i, Y + 19), 12, BF
  695.         NEXT i
  696.         LINE (X, Y)-(X + 30, Y + 19), 4, B
  697.         LINE (X + 1, Y + 1)-(X + 31, Y + 18), 4, B
  698.     CASE 1
  699.         LINE (X, Y)-(X + 8, Y + 12), 1, BF
  700.         LINE (X + 9, Y + 8)-(X + 24, Y + 20), 2, BF
  701.         LINE (X + 25, Y)-(X + 32, Y + 12), 3, BF
  702.     CASE 2
  703.         LINE (X, Y)-(X + 29, Y + 18), X / 32 + 1, B
  704.         LINE (X + 1, Y + 1)-(X + 28, Y + 17), X / 32 + 2, B
  705.     CASE 3
  706.         FOR i = 0 TO 9 STEP 2
  707.             LINE (X + i, Y + i)-(X + 29 - i, Y + 18 - i), i, B
  708.         NEXT i
  709.     CASE 4
  710.         j = 0
  711.         FOR i = 1 TO 30 STEP 3
  712.             LINE (X + i, Y + j)-(X + 30 - i, Y + j), i
  713.             LINE (X + i, Y + 19 - j)-(X + 30 - i, Y + 19 - j), i
  714.             j = j + 2
  715.         NEXT i
  716.     CASE 5
  717.         LINE (X, Y)-(X + 29, Y + 4), 1, BF
  718.         LINE (X, Y)-(X + 4, Y + 18), 1, BF
  719.         LINE (X + 7, Y + 7)-(X + 29, Y + 11), 5, BF
  720.         LINE (X + 7, Y + 7)-(X + 11, Y + 18), 5, BF
  721.         LINE (X + 14, Y + 14)-(X + 29, Y + 18), 4, BF
  722.     CASE 6
  723.         LINE (X + 15, Y)-(X + 17, Y + 19), 1
  724.         LINE (X, Y + 9)-(X + 31, Y + 11), 2
  725.         LINE (X, Y + 1)-(X + 31, Y + 18), 9
  726.         LINE (X + 30, Y)-(X + 1, Y + 19), 10
  727.     CASE 7
  728.         FOR i = 1 TO 6
  729.             CIRCLE (X + 16, Y + 10), i, i
  730.         NEXT i
  731.     CASE 8
  732.         FOR i = X TO X + 30 STEP 10
  733.             CIRCLE (i, Y + 9), 10, Y / 20 + 1
  734.         NEXT i
  735.     CASE 9
  736.         LINE (X + 1, Y)-(X + 1, Y + 18), 3
  737.         LINE (X + 1, Y)-(X + 12, Y + 18), 3
  738.         LINE (X + 1, Y + 18)-(X + 12, Y + 18), 3
  739.         LINE (X + 30, Y)-(X + 30, Y + 18), 3
  740.         LINE (X + 30, Y)-(X + 19, Y + 18), 3
  741.         LINE (X + 30, Y + 18)-(X + 19, Y + 18), 3
  742.         LINE (X + 4, Y)-(X + 26, Y), 1
  743.         LINE (X + 4, Y)-(X + 15, Y + 18), 1
  744.         LINE (X + 26, Y)-(X + 15, Y + 18), 1
  745.     END SELECT
  746.    
  747.     GET (0, 0)-(31, 19), Temp2  ' GET the image.
  748.    
  749.     ' Duplicate the image 10 times across by 10 times down.
  750.     FOR H = 0 TO 319 STEP 32
  751.         FOR V = 0 TO 199 STEP 20
  752.             PUT (H, V), Temp2, PSET
  753.         NEXT V
  754.     NEXT H
  755.  
  756. END SUB
  757.  
  758. '----------------------------------------------------------------------------
  759. ' DrawPlayingField
  760. '
  761. '    Draws the playing field, including the well, the title, the
  762. '    score/level box, etc.
  763. '
  764. '           PARAMETERS:   None
  765. '----------------------------------------------------------------------------
  766. SUB DrawPlayingField
  767.    
  768.     SELECT CASE ScreenMode               ' Choose the screen colors based on the current mode.
  769.         CASE 7
  770.             WellColor = WELLCOLOR7
  771.             BorderColor = BORDERCOLOR7
  772.  
  773.         CASE ELSE                         ' Setup for SCREEN 1.
  774.             WellColor = WELLCOLOR1
  775.             BorderColor = BORDERCOLOR1
  776.     END SELECT
  777.    
  778.     ScreenWidth = 40                      ' Set to proper width and colors.
  779.    
  780.     ' Draw the background pattern.
  781.     DrawPattern Level
  782.   
  783.     ' Draw the well box.
  784.     LINE (WELLX - 1, WELLY - 5)-(WELLX + WELLWIDTH * XSIZE + 1, WELLY + WELLHEIGHT * YSIZE + 1), WellColor, BF
  785.     LINE (WELLX - 1, WELLY - 5)-(WELLX + WELLWIDTH * XSIZE + 1, WELLY + WELLHEIGHT * YSIZE + 1), BorderColor, B
  786.    
  787.     ' Draw the title box.
  788.     LINE (XSIZE, WELLY - 5)-(XSIZE * 8, WELLY + 12), WellColor, BF
  789.     LINE (XSIZE, WELLY - 5)-(XSIZE * 8, WELLY + 12), BorderColor, B
  790.    
  791.     ' Draw the scoring box.
  792.     LINE (XSIZE, WELLY + 20)-(WELLX - 2 * XSIZE, 78), WellColor, BF
  793.     LINE (XSIZE, WELLY + 20)-(WELLX - 2 * XSIZE, 78), BorderColor, B
  794.                                          
  795.     MakeInfoBox                     ' Draw the Information Box.
  796.  
  797.     COLOR 12
  798.     LOCATE 3, 5: PRINT "QBLOCKS"     ' Center the program name on line 2.
  799.     COLOR BorderColor
  800.  
  801.     ' Draw the scoring area.
  802.     LOCATE 6, 4: PRINT "Score:";
  803.     LOCATE 7, 4: PRINT USING "#,###,###"; Score
  804.     LOCATE 9, 4: PRINT USING "Level: ##"; Level
  805.  
  806. END SUB
  807.  
  808. '----------------------------------------------------------------------------
  809. ' GameOver
  810. '
  811. '    Ends the game and asks the player if he/she wants to play
  812. '    again.  GameOver returns TRUE if the player wishes to stop
  813. '    or FALSE if the player wants another game.
  814. '
  815. '           PARAMETERS:   None
  816. '----------------------------------------------------------------------------
  817. FUNCTION GameOver
  818.    
  819.     PLAY PLAYGAMEOVER                           ' Play the game over tune.
  820.     MakeInfoBox
  821.  
  822.     DO WHILE INKEY$ <> "": LOOP                 ' Clear the keyboard buffer.
  823.  
  824.     ' Put Game Over messages into the InfoBox.
  825.     LOCATE 14, 4: PRINT "Game Over"
  826.     LOCATE 17, 6: PRINT "Play"
  827.     LOCATE 18, 5: PRINT "again?"
  828.     LOCATE 20, 6: PRINT "(Y/N)"
  829.     
  830.     ' Wait for the player to press either Y or N.
  831.     DO
  832.         a$ = UCASE$(INKEY$)                     ' UCASE$ assures that the key will be uppercase.  This eliminates the need to check for y and n in addition to Y and N.
  833.     LOOP UNTIL a$ = "Y" OR a$ = "N"
  834.    
  835.     IF a$ = "Y" THEN                            ' If player selects "Y",
  836.         GameOver = FALSE                        ' game is not over,
  837.     ELSE                                        ' otherwise
  838.         GameOver = TRUE                         ' the game is over.
  839.     END IF
  840.   
  841. END FUNCTION
  842.  
  843. '----------------------------------------------------------------------------
  844. ' InitScreen
  845. '
  846. '    Draws the playing field and ask for the desired starting level.
  847. '
  848. '           PARAMETERS:   None
  849. '----------------------------------------------------------------------------
  850. SUB InitScreen
  851.  
  852.     DrawPlayingField                ' Draw playing field assuming Level 0.
  853.  
  854.     ' Prompt for starting level.
  855.     COLOR 12                        ' Change foreground color to bright red.
  856.     LOCATE 14, 5: PRINT "Select";
  857.     LOCATE 16, 5: PRINT "start";
  858.     LOCATE 18, 5: PRINT "level?";
  859.     LOCATE 20, 5: PRINT "(0 - 9)";
  860.     COLOR BorderColor               ' Restore the default text color to BorderColor (white).
  861.     Level = TRUE                    ' Use level as flag as well as a real value.  Level remain TRUE if Q (Quit) is pressed instead of a level.
  862.    
  863.     ' Get a value for Level or accept a Q.
  864.     DO
  865.         a$ = UCASE$(INKEY$)
  866.     LOOP WHILE (a$ > "9" OR a$ < "0") AND a$ <> "Q"
  867.    
  868.     IF a$ = "Q" THEN
  869.         EXIT SUB
  870.     ELSE
  871.         Level = VAL(a$)
  872.     END IF
  873.  
  874.     IF Level > 0 THEN DrawPlayingField    ' Draw new playing field because the background pattern depends on the level.
  875.     RedrawControls      ' Draw the controls.
  876.  
  877. END SUB
  878.  
  879. '----------------------------------------------------------------------------
  880. ' MakeInfoBox
  881. '
  882. '    Draws the information box.
  883. '
  884. '           PARAMETERS:   None
  885. '----------------------------------------------------------------------------
  886. SUB MakeInfoBox
  887.  
  888.     LINE (WELLX - 9 * XSIZE, 90)-(WELLX - 2 * XSIZE, 185), WellColor, BF    ' Clear the Info area.
  889.     LINE (WELLX - 9 * XSIZE, 90)-(WELLX - 2 * XSIZE, 185), BorderColor, B   ' Draw a border around it.
  890.  
  891. END SUB
  892.  
  893. '----------------------------------------------------------------------------
  894. ' NewBlock
  895. '
  896. '    Initializes a new falling shape about to enter the well.
  897. '
  898. '           PARAMETERS:   None
  899. '----------------------------------------------------------------------------
  900. SUB NewBlock
  901.  
  902.     CurBlock.Style = INT(RND(1) * NUMSTYLES) + 1    ' Randomly pick a block style.
  903.     CurBlock.X = (WELLWIDTH \ 2) - 1                ' Put the new shape in the horizontal middle of the well
  904.     CurBlock.Y = 0                                  ' and at the top of the well.
  905.     CurBlock.Rotation = 0                           ' Begin with no rotation.
  906.  
  907.     PLAY PLAYNEWBLOCK
  908.  
  909. END SUB
  910.  
  911. '----------------------------------------------------------------------------
  912. ' PerformGame
  913. '
  914. '    Continues to play the game until the player quits.
  915. '
  916. '           PARAMETERS:   None
  917. '----------------------------------------------------------------------------
  918. SUB PerformGame
  919.  
  920.     DO                                          ' Loop for repetitive games
  921.         a$ = ""
  922.         ERASE WellBlocks                        ' Set all the elements in the WellBlocks array to 0.
  923.         Score = 0                               ' Clear initial score.
  924.         Level = 0                               ' Assume Level 0.
  925.         PrevScore = BASESCORE - NEXTLEVEL       ' Set score needed to get to first level
  926.         GameTiltScore = WINGAME                 ' Set the initial win game value.
  927.        
  928.         InitScreen                              ' Prepare the screen and get the difficulty level.
  929.         IF Level = -1 THEN EXIT SUB             ' Player pressed Q instead of a level.
  930.        
  931.         TargetTime = TIMER + 1 / (Level + 1)    ' TargetTime is when the falling shape will move down again.
  932.         DO                                      ' Create new falling shapes until the game is over.
  933.             DoneWithThisBlock = FALSE           ' This falling shape is not done falling yet.
  934.             NewBlock                            ' Create a new falling unit.
  935.             IF CheckFit = FALSE THEN EXIT DO    ' If it does not fit, then the game is over.
  936.             PutBlock CurBlock                   ' Display the new shape.
  937.            
  938.             DO                                  ' Continue dropping the falling shape.
  939.                 OldBlock = CurBlock             ' Save current falling shape for possible later use.
  940.                 DO                              ' Loop until enough time elapses.
  941.                    
  942.                     ValidEvent = TRUE           ' Assume a key was pressed.
  943.                     ans$ = UCASE$(INKEY$)
  944.  
  945.                     IF ans$ = PAUSE OR ans$ = QUIT THEN
  946.                         MakeInfoBox
  947.                    
  948.                         ' SELECT CASE will do different actions based on the
  949.                         ' value of the SELECTED variable.
  950.                         SELECT CASE ans$
  951.                             CASE PAUSE
  952.                                 SOUND 1100, .75
  953.                                 LOCATE 16, 6: PRINT "GAME";
  954.                                 LOCATE 18, 5: PRINT "PAUSED";
  955.                                 DO WHILE INKEY$ = "": LOOP  ' Wait until another key is pressed.
  956.                             CASE QUIT
  957.                                 ' Play sounds to tell the player that Q was pressed.
  958.                                 SOUND 1600, 1
  959.                                 SOUND 1000, .75
  960.                                
  961.                                 ' Confirm that the player really wants to quit.
  962.                                 LOCATE 15, 5: PRINT "Really";
  963.                                 LOCATE 17, 6: PRINT "quit?";
  964.                                 LOCATE 19, 6: PRINT "(Y/N)";
  965.                                 DO
  966.                                     a$ = UCASE$(INKEY$)
  967.                                 LOOP UNTIL a$ <> ""
  968.                                 IF a$ = "Y" THEN EXIT SUB
  969.                         END SELECT
  970.                         RedrawControls  ' Redraw controls if either Q or P is pressed.
  971.                    
  972.                     ELSE    ' A key was pressed but not Q or P.
  973.                         ans = ASC(RIGHT$(CHR$(0) + ans$, 1))    ' Convert the key press to an ASCII code for faster processing.
  974.                         SELECT CASE ans
  975.                         CASE DOWNARROW, DOWNARROW2, SPACEBAR    ' Drop shape immediately.
  976.                             DO                                  ' Loop to drop the falling unit one row at a time.
  977.                                 CurBlock.Y = CurBlock.Y + 1
  978.                             LOOP WHILE CheckFit = TRUE          ' Keep looping while the falling unit isn't stopped.
  979.                             CurBlock.Y = CurBlock.Y - 1         ' Went one down too far, restore to previous.
  980.                             TargetTime = TIMER - 1              ' Ensure that the shape falls immediately.
  981.                         CASE RIGHTARROW, RIGHTARROW2
  982.                             CurBlock.X = CurBlock.X + 1         ' Move falling unit right.
  983.                         CASE LEFTARROW, LEFTARROW2
  984.                             CurBlock.X = CurBlock.X - 1         ' Move falling unit left.
  985.                         CASE UPARROW, UPARROW2, UPARROW3
  986.                             CurBlock.Rotation = ((CurBlock.Rotation + ROTATEDIR) MOD 4)  ' Rotate falling unit.
  987.                         CASE ELSE
  988.                             ValidEvent = FALSE
  989.                     END SELECT
  990.  
  991.                     IF ValidEvent = TRUE THEN
  992.                         IF CheckFit = TRUE THEN         ' If the move is valid and the shape fits in the new position,
  993.                             PutBlock OldBlock           ' erase the shape from its old position
  994.                             PutBlock CurBlock           ' and display it in the new position.
  995.                             OldBlock = CurBlock
  996.                         ELSE
  997.                             CurBlock = OldBlock         ' If it does not fit then reset CurBlock to the OldBlock.
  998.                         END IF
  999.                     END IF
  1000.                 END IF
  1001.  
  1002.                 LOOP UNTIL TIMER >= TargetTime       ' Keep repeating the loop until it is time to drop the shape.  This allows many horizontal movements and rotations per vertical step.
  1003.                
  1004.                 TargetTime = TIMER + 1 / (Level + 1) ' The player has less time between vertical movements as the skill level increases.
  1005.                 CurBlock.Y = CurBlock.Y + 1          ' Try to drop the falling unit one row.
  1006.  
  1007.                 IF CheckFit = FALSE THEN             ' Cannot fall any more.
  1008.                     DoneWithThisBlock = TRUE         ' Done with this block.
  1009.                     CurBlock = OldBlock
  1010.                 END IF
  1011.                
  1012.                 PutBlock OldBlock                    ' Erase the falling shape from the old position,
  1013.                 PutBlock CurBlock                    ' and display it in the new position.
  1014.                 OldBlock = CurBlock
  1015.  
  1016.             LOOP UNTIL DoneWithThisBlock             ' Continue getting keys and moving shapes until the falling shape stops.
  1017.            
  1018.             AddBlockToWell                           ' Shape has stopped so logically add it to the well.
  1019.             CheckForFullRows                         ' Check to see if a row(s) is now full.  If so, deletes it.
  1020.             UpdateScoring                            ' Use the UpdateScoring subprogram to add to the score.
  1021.  
  1022.             IF Score >= GameTiltScore THEN           ' See if the score has hit the tilt score.
  1023.  
  1024.                 PLAY PLAYWINGAME
  1025.                 MakeInfoBox
  1026.                 LOCATE 13, 5: PRINT USING "#######"; Score
  1027.                 PLAY PLAYWINGAME
  1028.  
  1029.                 IF GameTiltScore = TILTVALUE THEN    ' If the player has tilted the game.
  1030.                     LOCATE 15, 4: PRINT "GAME TILT"
  1031.                     LOCATE 17, 5: PRINT "You are"
  1032.                     LOCATE 18, 4: PRINT "Awesome!"
  1033.                     LOCATE 20, 4: PRINT "Press any"
  1034.                     LOCATE 21, 6: PRINT "key..."
  1035.                     PLAY PLAYWINGAME
  1036.                     DO WHILE INKEY$ = "": LOOP
  1037.                     EXIT SUB
  1038.                 ELSE                                 ' If they just met the WINGAME value.
  1039.                     LOCATE 15, 4: PRINT "YOU WON!"
  1040.                     LOCATE 17, 5: PRINT "Want to"
  1041.                     LOCATE 18, 4: PRINT "continue"
  1042.                     LOCATE 20, 6: PRINT "(Y/N)"
  1043.  
  1044.                     DO                               ' DO loop to wait for the player to press anything.
  1045.                         a$ = UCASE$(INKEY$)          ' The UCASE$ function assures that a$ always has an uppercase letter in it.
  1046.                     LOOP UNTIL a$ <> ""
  1047.         
  1048.                     IF a$ <> "Y" THEN EXIT DO        ' Exit this main loop if the player pressed anything but Y.
  1049.  
  1050.                     GameTiltScore = TILTVALUE        ' Reset to the tilt value.
  1051.  
  1052.                     RedrawControls
  1053.                 END IF
  1054.             END IF
  1055.  
  1056.         LOOP                                         ' Unconditional loop.  Each game is stopped by the EXIT DO command at the top of this loop that executes when a new block will not fit in the well.
  1057.     LOOP UNTIL GameOver                              ' GameOver is always TRUE (-1) unless the user presses X or the well is full.
  1058.  
  1059. END SUB
  1060.  
  1061. '----------------------------------------------------------------------------
  1062. ' PutBlock
  1063. '
  1064. '    Uses very fast graphics PUT command to draw the shape.
  1065. '
  1066. '           PARAMETERS:    B - Block to be put onto the screen.
  1067. '----------------------------------------------------------------------------
  1068. SUB PutBlock (b AS BlockType)
  1069.    
  1070.     SELECT CASE b.Rotation          ' Base exact placement on the rotation.
  1071.         CASE 0                      ' No rotation.
  1072.             x1 = b.X: y1 = b.Y
  1073.         CASE 1                      ' Rotated 90 degrees clockwise, or 270 degrees counterclockwise.
  1074.             x1 = b.X + 1: y1 = b.Y - 1
  1075.         CASE 2                      ' Rotated 180 degrees.
  1076.             x1 = b.X: y1 = b.Y
  1077.         CASE 3                      ' Rotated 270 degrees clockwise, or 90 degrees counterclockwise.
  1078.             x1 = b.X + 1: y1 = b.Y - 1
  1079.     END SELECT
  1080.    
  1081.     ' Actually PUT the rotated shape on the screen.  The XOR option makes the
  1082.     ' new image blend with whatever used to be there in such a way that
  1083.     ' identical colors cancel each other out.  Therefore, one PUT with the XOR
  1084.     ' option can draw an object while the second PUT to that same location
  1085.     ' erases it without affecting anything else near it.  Often used for animation.
  1086.  
  1087.     PUT (x1 * XSIZE + WELLX, y1 * YSIZE + WELLY), BlockImage(((b.Style - 1) * 4 + b.Rotation) * ELEMENTSPERBLOCK), XOR  ' XOR mixes what used to be there on the screen with the new image.  Two identical colors cancel each other.
  1088.  
  1089. END SUB
  1090.  
  1091. '----------------------------------------------------------------------------
  1092. ' RedrawControls
  1093. '
  1094. '    Puts control keys information into the information box.
  1095. '
  1096. '           PARAMETERS:   None
  1097. '----------------------------------------------------------------------------
  1098. SUB RedrawControls
  1099.   
  1100.     ' Draw the InfoBox and erase anything that used to be in it.
  1101.     MakeInfoBox
  1102.  
  1103.     ' Print the key assignments within the Info Box.
  1104.     COLOR BorderColor
  1105.     LOCATE 13, 4: PRINT "Controls"
  1106.     LOCATE 14, 4: PRINT "--------"
  1107.     LOCATE 15, 4: PRINT CHR$(24) + " = Turn"
  1108.     LOCATE 16, 4: PRINT CHR$(27) + " = Left"
  1109.     LOCATE 17, 4: PRINT CHR$(26) + " = Right"
  1110.     LOCATE 18, 4: PRINT CHR$(25) + " = Drop"
  1111.     LOCATE 20, 4: PRINT "P = Pause"
  1112.     LOCATE 21, 4: PRINT "Q = Quit"
  1113.  
  1114. END SUB
  1115.  
  1116. '----------------------------------------------------------------------------
  1117. ' Show
  1118. '
  1119. '    Draws the falling shape one block at a time.  Only used by
  1120. '    DisplayAllShapes.  After that, PutBlock draws all falling
  1121. '    shapes.
  1122. '
  1123. '           PARAMETERS:    B - Block to be put onto the screen.
  1124. '----------------------------------------------------------------------------
  1125. SUB Show (b AS BlockType)
  1126.                                                  
  1127.     ' Loop through all possible block locations.
  1128.     FOR i = 0 TO XMATRIX
  1129.         FOR j = 0 TO YMATRIX
  1130.            
  1131.             IF BlockShape(i, j, b.Style) = 1 THEN   ' 1 means there is a block there.
  1132.                  SELECT CASE b.Rotation             ' Exact screen position is determined by the rotation.
  1133.                     CASE 0                          ' No rotation.
  1134.                         DrawBlock b.X + i, b.Y + j, BlockColor(b.Style)
  1135.                     CASE 1                          ' Rotated 90 degrees clockwise, or 270 degrees counterclockwise.
  1136.                         DrawBlock b.X - j + 2, b.Y - 1 + i, BlockColor(b.Style)
  1137.                     CASE 2                          ' Rotated 180 degrees.
  1138.                         DrawBlock b.X + 3 - i, b.Y - j + 1, BlockColor(b.Style)
  1139.                     CASE 3                          ' Rotated 270 degrees clockwise, or 90 degrees counterclockwise.
  1140.                         DrawBlock b.X + j + 1, b.Y - i + 2, BlockColor(b.Style)
  1141.                 END SELECT
  1142.             END IF
  1143.         NEXT j
  1144.     NEXT i
  1145.  
  1146. END SUB
  1147.  
  1148. '---------------------------------------------------------------------------
  1149. ' UpdateScoring
  1150. '
  1151. '    Puts the new score on the screen.  Checks if the new score forces
  1152. '    a new level.  If so, change the background pattern to match the
  1153. '    new level.
  1154. '
  1155. '           PARAMETERS:     None
  1156. '----------------------------------------------------------------------------
  1157. SUB UpdateScoring
  1158.    
  1159.     ' Increase the level if the score is high enough and the level is not
  1160.     ' maximum already.
  1161.     IF Level < 9 AND Score >= (NEXTLEVEL * (Level + 1) + PrevScore) THEN
  1162.    
  1163.         ' Store the entire well image to quickly PUT it back after the
  1164.         ' background changes.
  1165.         GET (WELLX, WELLY)-(WELLX + WELLWIDTH * XSIZE, WELLY + WELLHEIGHT * YSIZE), Temp
  1166.        
  1167.         PrevScore = Score           ' Save previous Score for next level.
  1168.         Level = Level + 1
  1169.         DrawPlayingField            ' Draw playing field again, this time with the new background pattern.
  1170.         PUT (WELLX, WELLY), Temp    ' Restore the image of the old well.
  1171.    
  1172.         RedrawControls              ' Show the controls again.
  1173.     END IF
  1174.  
  1175.     LOCATE 7, 4: PRINT USING "#,###,###"; Score   ' Print the score and level.
  1176.     
  1177. END SUB
  1178.  
  1179.