Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DIM wellWidth AS UBYTE = 10 REM Well width in characters
- DIM wellHeight AS UBYTE = 20 REM Well height in characters
- DIM shapeRow AS UBYTE = 0 REM Shape's top row
- DIM shapeCol AS UBYTE = 4 REM Shape's left column
- DIM shapeWidth AS UBYTE = 2 REM 2x2 square shape
- DIM shapeHeight AS UBYTE = 2
- DIM gameOver AS UBYTE = 0
- REM Initialize screen and well
- CLS
- REM Set well background attributes to 0 (black)
- FOR row = 0 TO wellHeight - 1
- FOR col = 0 TO wellWidth - 1
- POKE (22528 + row * 32 + col), 0
- PRINT AT row, col; " " REM Clear display
- NEXT col
- NEXT row
- REM Draw well borders (optional, for visibility)
- FOR row = 0 TO wellHeight - 1
- PRINT AT row, wellWidth; "|"
- POKE (22528 + row * 32 + wellWidth), 6 REM Yellow border
- NEXT row
- PRINT AT wellHeight, 0; STRING$(wellWidth, "-")
- FOR col = 0 TO wellWidth - 1
- POKE (22528 + wellHeight * 32 + col), 6
- NEXT col
- REM Main game loop
- DO WHILE gameOver = 0
- REM Draw shape (2x2 square)
- FOR r = 0 TO shapeHeight - 1
- FOR c = 0 TO shapeWidth - 1
- PRINT AT shapeRow + r, shapeCol + c; CHR$ 143
- POKE (22528 + (shapeRow + r) * 32 + shapeCol + c), 7
- NEXT c
- NEXT r
- REM Handle input
- IF INKEY$ = "q" AND shapeCol > 0 THEN
- LET shapeCol = shapeCol - 1 REM Move left
- ELSE IF INKEY$ = "p" AND shapeCol + shapeWidth < wellWidth THEN
- LET shapeCol = shapeCol + 1 REM Move right
- ELSE IF INKEY$ = "a" THEN
- LET shapeRow = shapeRow + 1 REM Move down faster
- END IF
- REM Check collision below
- LET collision = 0
- IF shapeRow + shapeHeight >= wellHeight THEN
- LET collision = 1 REM Hit bottom
- ELSE
- FOR c = shapeCol TO shapeCol + shapeWidth - 1
- LET attrAddr = 22528 + (shapeRow + shapeHeight) * 32 + c
- IF PEEK(attrAddr) <> 0 THEN
- LET collision = 1
- EXIT
- END IF
- NEXT c
- END IF
- REM Move shape down or stop
- IF collision = 0 THEN
- LET shapeRow = shapeRow + 1
- ELSE
- REM Stop shape, check for game over
- IF shapeRow = 0 THEN
- LET gameOver = 1
- EXIT
- END IF
- REM Check for completed rows
- GOSUB checkRows
- REM Spawn new shape
- LET shapeRow = 0
- LET shapeCol = 4
- END IF
- REM Clear previous shape position
- FOR r = 0 TO shapeHeight - 1
- FOR c = 0 TO shapeWidth - 1
- PRINT AT shapeRow + r - 1, shapeCol + c; " "
- POKE (22528 + (shapeRow + r - 1) * 32 + shapeCol + c), 0
- NEXT c
- NEXT r
- PAUSE 10 REM Slow down for playability
- LOOP
- PRINT AT 10, 2; "Game Over"
- STOP
- checkRows:
- REM Check each row of the shape for completion
- FOR r = shapeRow TO shapeRow + shapeHeight - 1
- LET complete = 1
- FOR c = 0 TO wellWidth - 1
- IF PEEK(22528 + r * 32 + c) = 0 THEN
- LET complete = 0
- EXIT
- END IF
- NEXT c
- IF complete = 1 THEN
- REM Shift rows down
- FOR row = r TO 1 STEP -1
- FOR col = 0 TO wellWidth - 1
- LET attrAbove = PEEK(22528 + (row - 1) * 32 + col)
- POKE (22528 + row * 32 + col), attrAbove
- PRINT AT row, col; " "
- IF attrAbove <> 0 THEN
- PRINT AT row, col; CHR$ 143
- END IF
- NEXT col
- NEXT row
- REM Clear top row
- FOR col = 0 TO wellWidth - 1
- POKE (22528 + col), 0
- PRINT AT 0, col; " "
- NEXT col
- END IF
- NEXT r
- RETURN
Advertisement
Add Comment
Please, Sign In to add comment