Shaun_B

Some BASIC fun

Jul 29th, 2025
121
0
11 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Basic4GL 3.59 KB | Gaming | 0 0
  1. DIM wellWidth AS UBYTE = 10   REM Well width in characters
  2. DIM wellHeight AS UBYTE = 20  REM Well height in characters
  3. DIM shapeRow AS UBYTE = 0     REM Shape's top row
  4. DIM shapeCol AS UBYTE = 4     REM Shape's left column
  5. DIM shapeWidth AS UBYTE = 2   REM 2x2 square shape
  6. DIM shapeHeight AS UBYTE = 2
  7. DIM gameOver AS UBYTE = 0
  8.  
  9. REM Initialize screen and well
  10. CLS
  11. REM Set well background attributes to 0 (black)
  12. FOR row = 0 TO wellHeight - 1
  13.     FOR col = 0 TO wellWidth - 1
  14.         POKE (22528 + row * 32 + col), 0
  15.         PRINT AT row, col; " "  REM Clear display
  16.     NEXT col
  17. NEXT row
  18. REM Draw well borders (optional, for visibility)
  19. FOR row = 0 TO wellHeight - 1
  20.     PRINT AT row, wellWidth; "|"
  21.     POKE (22528 + row * 32 + wellWidth), 6  REM Yellow border
  22. NEXT row
  23. PRINT AT wellHeight, 0; STRING$(wellWidth, "-")
  24. FOR col = 0 TO wellWidth - 1
  25.     POKE (22528 + wellHeight * 32 + col), 6
  26. NEXT col
  27.  
  28. REM Main game loop
  29. DO WHILE gameOver = 0
  30.     REM Draw shape (2x2 square)
  31.     FOR r = 0 TO shapeHeight - 1
  32.         FOR c = 0 TO shapeWidth - 1
  33.             PRINT AT shapeRow + r, shapeCol + c; CHR$ 143
  34.             POKE (22528 + (shapeRow + r) * 32 + shapeCol + c), 7
  35.         NEXT c
  36.     NEXT r
  37.  
  38.     REM Handle input
  39.     IF INKEY$ = "q" AND shapeCol > 0 THEN
  40.         LET shapeCol = shapeCol - 1  REM Move left
  41.     ELSE IF INKEY$ = "p" AND shapeCol + shapeWidth < wellWidth THEN
  42.         LET shapeCol = shapeCol + 1  REM Move right
  43.     ELSE IF INKEY$ = "a" THEN
  44.         LET shapeRow = shapeRow + 1  REM Move down faster
  45.     END IF
  46.  
  47.     REM Check collision below
  48.     LET collision = 0
  49.     IF shapeRow + shapeHeight >= wellHeight THEN
  50.         LET collision = 1  REM Hit bottom
  51.     ELSE
  52.         FOR c = shapeCol TO shapeCol + shapeWidth - 1
  53.             LET attrAddr = 22528 + (shapeRow + shapeHeight) * 32 + c
  54.             IF PEEK(attrAddr) <> 0 THEN
  55.                 LET collision = 1
  56.                 EXIT
  57.             END IF
  58.         NEXT c
  59.     END IF
  60.  
  61.     REM Move shape down or stop
  62.     IF collision = 0 THEN
  63.         LET shapeRow = shapeRow + 1
  64.     ELSE
  65.         REM Stop shape, check for game over
  66.         IF shapeRow = 0 THEN
  67.             LET gameOver = 1
  68.             EXIT
  69.         END IF
  70.         REM Check for completed rows
  71.         GOSUB checkRows
  72.         REM Spawn new shape
  73.         LET shapeRow = 0
  74.         LET shapeCol = 4
  75.     END IF
  76.  
  77.     REM Clear previous shape position
  78.     FOR r = 0 TO shapeHeight - 1
  79.         FOR c = 0 TO shapeWidth - 1
  80.             PRINT AT shapeRow + r - 1, shapeCol + c; " "
  81.             POKE (22528 + (shapeRow + r - 1) * 32 + shapeCol + c), 0
  82.         NEXT c
  83.     NEXT r
  84.  
  85.     PAUSE 10  REM Slow down for playability
  86. LOOP
  87.  
  88. PRINT AT 10, 2; "Game Over"
  89. STOP
  90.  
  91. checkRows:
  92. REM Check each row of the shape for completion
  93. FOR r = shapeRow TO shapeRow + shapeHeight - 1
  94.     LET complete = 1
  95.     FOR c = 0 TO wellWidth - 1
  96.         IF PEEK(22528 + r * 32 + c) = 0 THEN
  97.             LET complete = 0
  98.             EXIT
  99.         END IF
  100.     NEXT c
  101.     IF complete = 1 THEN
  102.         REM Shift rows down
  103.         FOR row = r TO 1 STEP -1
  104.             FOR col = 0 TO wellWidth - 1
  105.                 LET attrAbove = PEEK(22528 + (row - 1) * 32 + col)
  106.                 POKE (22528 + row * 32 + col), attrAbove
  107.                 PRINT AT row, col; " "
  108.                 IF attrAbove <> 0 THEN
  109.                     PRINT AT row, col; CHR$ 143
  110.                 END IF
  111.             NEXT col
  112.         NEXT row
  113.         REM Clear top row
  114.         FOR col = 0 TO wellWidth - 1
  115.             POKE (22528 + col), 0
  116.             PRINT AT 0, col; " "
  117.         NEXT col
  118.     END IF
  119. NEXT r
  120. RETURN
Advertisement
Add Comment
Please, Sign In to add comment