Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 REM T3tr1s by Donkeysoft
- 2 DIM wellWidth AS UBYTE
- 3 DIM wellHeight AS UBYTE
- 4 DIM shapeRow AS UBYTE
- 5 DIM shapeCol AS UBYTE
- 6 DIM shapeWidth AS UBYTE
- 7 DIM shapeHeight AS UBYTE
- 8 DIM gameOver AS UBYTE
- 9 DIM title AS UBYTE
- 10 DIM fla AS UBYTE
- 11 DIM flaDirection AS INTEGER
- 12 DIM scrolly$ AS STRING
- 13 DIM message AS UBYTE
- 14 DIM score AS INTEGER
- 15 DIM highScore AS INTEGER
- 16 DIM shape AS UBYTE
- 17 DIM canRotate AS UBYTE
- 18 DIM lastShape AS UBYTE
- 19 DIM shapeData(7, 4, 2) AS UBYTE REM Shape data: 7 shapes, 4 blocks, (row, col)
- 20 RANDOMIZE -PEEK(23672): BORDER 0: PAPER 0: INK 6: CLS: GO SUB 1000: GO SUB 2000
- 21 PRINT AT 2, title+3; BRIGHT 1; INK 1;"D"; INK 2;"o"; INK 3;"n"; INK 4;"k"; INK 5;"e"; INK 6;"y"; INK 7;"soft"; AT 4, title+4; INK 6; BRIGHT 0;"PRESENTS"
- 22 PRINT AT 6, title+5; INK fla;"T3tr1s"; AT 23, title; INK 6; scrolly$(message TO message + 13); AT 16, title + 1; INK 7;"Score: "; score; AT 18, title + 1;"High"; AT 19, title + 1;"score: "; highScore; AT 12, title + 1;"Next:"
- 23 LET fla = fla + flaDirection: PAUSE 4: IF fla = 7 OR fla = 0 THEN LET flaDirection = -flaDirection
- 24 IF fla > 7 THEN LET fla = 7
- 25 IF fla < 0 THEN LET fla = 0
- 26 IF INKEY$ = "5" OR INKEY$ = "z" OR INKEY$ = "Z" THEN LET message = message - 1: IF message < 0 THEN LET message = 0
- 27 IF INKEY$ = "8" OR INKEY$ = "x" OR INKEY$ = "X" THEN LET message = message + 1: IF message > 264 THEN LET message = 264
- 28 IF INKEY$ = "S" OR INKEY$ = "s" THEN GO TO 30
- 29 GO TO 21
- 30 CLS: GO SUB 2000: GO SUB 3000: LET score = 0: LET gameOver = 0
- 31 GO SUB 4000: REM Choose first shape
- 32 DO WHILE gameOver = 0
- 33 GO SUB 5000: REM Draw next shape
- 34 GO SUB 7000: REM Move shape down
- 35 IF gameOver THEN EXIT
- 36 PAUSE 10
- 37 LOOP
- 38 GO SUB 10000: STOP
- 1000 REM Initialization
- 1001 LET wellHeight = 24: LET wellWidth = 16: LET shapeRow = 0: LET shapeCol = 6: LET gameOver = 0: LET title = 17: LET fla = 0: LET flaDirection = 1
- 1002 LET scrolly$ = "S to start ... Another Tetris game by Donkeysoft ... Move the blocks left and right to position them ... Build complete rows of blocks as high as possible ... Push UP to remove them from the play field; for each row you remove, you score points ... HI RUBY MAE!"
- 1003 LET message = 0: LET score = 0: LET highScore = 0: LET shape = 0: LET lastShape = 0: LET canRotate = 1
- 1004 REM Define shapes: (row, col) offsets for 4 blocks
- 1005 REM Block (1): [[0,0],[0,1],[1,0],[1,1]]
- 1006 DATA 0,0, 0,1, 1,0, 1,1
- 1007 REM Line (2): [[0,0],[0,1],[0,2],[0,3]]
- 1008 DATA 0,0, 0,1, 0,2, 0,3
- 1009 REM L (3): [[0,0],[0,1],[0,2],[1,2]]
- 1010 DATA 0,0, 0,1, 0,2, 1,2
- 1011 REM Reverse L (4): [[0,0],[0,1],[0,2],[1,0]]
- 1012 DATA 0,0, 0,1, 0,2, 1,0
- 1013 REM T (5): [[0,0],[0,1],[0,2],[1,1]]
- 1014 DATA 0,0, 0,1, 0,2, 1,1
- 1015 REM Z (6): [[0,0],[0,1],[1,1],[1,2]]
- 1016 DATA 0,0, 0,1, 1,1, 1,2
- 1017 REM S (7): [[0,1],[0,2],[1,0],[1,1]]
- 1018 DATA 0,1, 0,2, 1,0, 1,1
- 1019 FOR s = 1 TO 7: FOR b = 0 TO 3: FOR c = 0 TO 1: READ shapeData(s, b, c): NEXT c: NEXT b: NEXT s
- 1020 LET shapeWidth = 4: LET shapeHeight = 2: REM Max dimensions for any shape
- 1021 RETURN
- 2000 REM Draw well border
- 2001 FOR row = 0 TO wellHeight - 1: PRINT AT row, wellWidth; INK 5; INVERSE 1;" ": POKE (22528 + row * 32 + wellWidth), 5: NEXT row
- 2002 FOR col = 0 TO wellWidth - 1: PRINT AT wellHeight, col; INK 5; "-": POKE (22528 + wellHeight * 32 + col), 5: NEXT col
- 2003 RETURN
- 3000 REM Clear the well
- 3001 FOR row = 0 TO wellHeight - 1: FOR col = 0 TO wellWidth - 1: POKE (22528 + row * 32 + col), 0: PRINT AT row, col; " ": NEXT col: NEXT row
- 3002 RETURN
- 4000 REM Decide shape
- 4001 LET canRotate = (RND > 0.5): IF shape = 1 THEN LET canRotate = 0
- 4002 LET shape = 1 + INT(RND * 7)
- 4003 IF RND < 0.5 AND shape <> lastShape THEN LET shape = lastShape
- 4004 LET lastShape = shape
- 4005 RETURN
- 5000 REM Draw next shape
- 5001 FOR i = 12 TO 14: PRINT AT i, title+7; INK 0; BRIGHT 0; INVERSE 0;" ": NEXT i
- 5002 FOR b = 0 TO 3
- 5003 LET r = shapeData(shape, b, 0): LET c = shapeData(shape, b, 1)
- 5004 PRINT AT 12 + r, title + 7 + c; INK shape; BRIGHT 1; INVERSE 1;" "
- 5005 NEXT b
- 5006 RETURN
- 6000 REM Rotate block
- 6001 IF NOT canRotate THEN RETURN
- 6002 DIM tempData(4, 2) AS UBYTE
- 6003 FOR b = 0 TO 3
- 6004 LET r = shapeData(shape, b, 0): LET c = shapeData(shape, b, 1)
- 6005 LET tempData(b, 0) = c: LET tempData(b, 1) = shapeHeight - 1 - r REM Rotate 90 degrees
- 6006 NEXT b
- 6007 REM Check if rotation is valid
- 6008 LET valid = 1
- 6009 FOR b = 0 TO 3
- 6010 LET r = shapeRow + tempData(b, 0): LET c = shapeCol + tempData(b, 1)
- 6011 IF r >= wellHeight OR c >= wellWidth OR c < 0 THEN LET valid = 0: EXIT
- 6012 IF PEEK(22528 + r * 32 + c) <> 0 THEN LET valid = 0: EXIT
- 6013 NEXT b
- 6014 IF valid THEN
- 6015 FOR b = 0 TO 3: LET shapeData(shape, b, 0) = tempData(b, 0): LET shapeData(shape, b, 1) = tempData(b, 1): NEXT b
- 6016 END IF
- 6017 RETURN
- 7000 REM Move block down; respond to user movements
- 7001 REM Clear current shape
- 7002 FOR b = 0 TO 3
- 7003 LET r = shapeRow + shapeData(shape, b, 0): LET c = shapeCol + shapeData(shape, b, 1)
- 7004 PRINT AT r, c; " ": POKE (22528 + r * 32 + c), 0
- 7005 NEXT b
- 7006 REM Handle input
- 7007 IF INKEY$ = "5" AND shapeCol > 0 THEN
- 7008 LET valid = 1
- 7009 FOR b = 0 TO 3
- 7010 LET c = shapeCol - 1 + shapeData(shape, b, 1)
- 7011 IF c < 0 OR PEEK(22528 + (shapeRow + shapeData(shape, b, 0)) * 32 + c) <> 0 THEN LET valid = 0: EXIT
- 7012 NEXT b
- 7013 IF valid THEN LET shapeCol = shapeCol - 1
- 7014 END IF
- 7015 IF INKEY$ = "8" AND shapeCol + shapeWidth < wellWidth THEN
- 7016 LET valid = 1
- 7017 FOR b = 0 TO 3
- 7018 LET c = shapeCol + 1 + shapeData(shape, b, 1)
- 7019 IF c >= wellWidth OR PEEK(22528 + (shapeRow + shapeData(shape, b, 0)) * 32 + c) <> 0 THEN LET valid = 0: EXIT
- 7020 NEXT b
- 7021 IF valid THEN LET shapeCol = shapeCol + 1
- 7022 END IF
- 7023 IF INKEY$ = "0" THEN GO SUB 6000 REM Rotate
- 7024 REM Check collision below
- 7025 LET collision = 0
- 7026 IF shapeRow + shapeHeight >= wellHeight THEN
- 7027 LET collision = 1
- 7028 ELSE
- 7029 FOR b = 0 TO 3
- 7030 LET r = shapeRow + shapeData(shape, b, 0) + 1: LET c = shapeCol + shapeData(shape, b, 1)
- 7031 IF r < wellHeight AND PEEK(22528 + r * 32 + c) <> 0 THEN LET collision = 1: EXIT
- 7032 NEXT b
- 7033 END IF
- 7034 IF collision = 0 THEN
- 7035 LET shapeRow = shapeRow + 1
- 7036 ELSE
- 7037 REM Place shape
- 7038 FOR b = 0 TO 3
- 7039 LET r = shapeRow + shapeData(shape, b, 0): LET c = shapeCol + shapeData(shape, b, 1)
- 7040 PRINT AT r, c; INK shape; BRIGHT 1; INVERSE 1;" "
- 7041 POKE (22528 + r * 32 + c), shape
- 7042 NEXT b
- 7043 IF shapeRow = 0 THEN LET gameOver = 1: RETURN
- 7044 GO SUB 9000: REM Check rows
- 7045 GO SUB 8000: REM Update score
- 7046 GO SUB 4000: REM Choose next shape
- 7047 LET shapeRow = 0: LET shapeCol = 6
- 7048 END IF
- 7049 REM Draw shape
- 7050 FOR b = 0 TO 3
- 7051 LET r = shapeRow + shapeData(shape, b, 0): LET c = shapeCol + shapeData(shape, b, 1)
- 7052 PRINT AT r, c; INK shape; BRIGHT 1; INVERSE 1;" "
- 7053 POKE (22528 + r * 32 + c), shape
- 7054 NEXT b
- 7055 RETURN
- 8000 REM Increase score
- 8001 REM Score updated in 9000 based on rows cleared
- 8002 PRINT AT 16, title + 1; INK 7;"Score: "; score
- 8003 IF score > highScore THEN LET highScore = score: PRINT AT 19, title + 1; INK 7;"score: "; highScore
- 8004 RETURN
- 9000 REM Check well for completed rows
- 9001 FOR r = 0 TO wellHeight - 1
- 9002 LET complete = 1
- 9003 FOR c = 0 TO wellWidth - 1
- 9004 IF PEEK(22528 + r * 32 + c) = 0 THEN LET complete = 0: EXIT
- 9005 NEXT c
- 9006 IF complete THEN
- 9007 LET score = score + 100 REM 100 points per row
- 9008 FOR row = r TO 1 STEP -1
- 9009 FOR col = 0 TO wellWidth - 1
- 9010 LET attrAbove = PEEK(22528 + (row - 1) * 32 + col)
- 9011 POKE (22528 + row * 32 + col), attrAbove
- 9012 PRINT AT row, col; " "
- 9013 IF attrAbove <> 0 THEN PRINT AT row, col; INK attrAbove; BRIGHT 1; INVERSE 1;" "
- 9014 NEXT col
- 9015 NEXT row
- 9016 FOR col = 0 TO wellWidth - 1
- 9017 POKE (22528 + col), 0: PRINT AT 0, col; " "
- 9018 NEXT col
- 9019 END IF
- 9020 NEXT r
- 9021 RETURN
- 10000 REM Game over
- 10001 CLS: PRINT AT 10, 8; INK 7; BRIGHT 1; "Game Over"
- 10002 PRINT AT 12, 8; "Score: "; score; AT 14, 8; "High score: "; highScore
- 10003 PRINT AT 16, 8; "Press S to restart"
- 10004 IF INKEY$ = "S" OR INKEY$ = "s" THEN RUN
- 10005 GO TO 10004
Advertisement
Add Comment
Please, Sign In to add comment