Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::: NEW VERSION including getkeys.exe for enhanced controls and gameplay
- ::: available for download from:
- ::: https://drive.google.com/file/d/1iLm9RsbWIfIBDEU854IQbvg_mjA3RnvC/view?usp=sharing
- @Echo off
- Setlocal EnableExtensions DISABLEdelayedexpansion
- wmic OS get OSArchitecture,caption | FIND "10" >nul || (ECHO/Windows 10 required for ascii escape codes & Endlocal & Exit /B)
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- Title Tetris by T3RRY & rem commenced 30/10/2020
- rem ::: 30/10/2020 Piece creation, basic collision detection, piece movement implemented.
- rem ::: 31/10/2020 New piece and Game over trigger tests added.
- rem ::: 31/10/2020 Color, Piece rotation added
- rem ::: 01/11/2020 Function to test for a completed line added.
- rem ::: 01/11/2020 Scoring system added
- :::::::: [ TO BE ACTIONED ] :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- rem ::: Getkeys controller version with variable delay for speed increase based on score
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- rem ---------------------------------------------------- /* ASCII escape code definition */
- for /F "delims=#" %%a in ('"prompt #$E# & for %%a in (1) do rem"') do set "\E=%%a"
- rem ------------------------------------------------------------------ /* define macro's */
- Set "nPiece[1]=Set /A "x1=6,y1=1,x2=6,y2=2,x3=6,y3=3,x4=6,y4=4""
- Set "nPiece[2]=Set /A "x1=6,y1=1,x2=7,y2=1,x3=6,y3=2,x4=7,y4=2""
- Set "nPiece[3]=Set /A "x1=6,y1=1,x2=7,y2=1,x3=7,y3=2,x4=7,y4=3""
- Set "nPiece[4]=Set /A "x1=6,y1=1,x2=6,y2=2,x3=6,y3=3,x4=7,y4=1""
- Set "nPiece[5]=Set /A "x1=6,y1=1,x2=6,y2=2,x3=7,y3=2,x4=7,y4=3""
- Set "nPiece[6]=Set /A "x1=7,y1=1,x2=7,y2=2,x3=6,y3=2,x4=6,y4=3""
- Set "nPiece[7]=Set /A "x1=6,y1=1,x2=6,y2=2,x3=7,y3=2,x4=6,y4=3""
- Set "MoveLeft=Set "valid=0"&Set /A "_x1=!x1!-1,_x2=!x2!-1,_x3=!x3!-1,_x4=!x4!-1" & (For %%v in ("!y1!;!_x1!" "!y2!;!_x2!" "!y3!;!_x3!" "!y4!;!_x4!")Do (IF "!}%%~v!" == "" (Set /A "Valid=!Valid! + 1"))) & If "!Valid!" == "4" (Set /A "x1-=1,x2-=1,x3-=1,x4-=1")"
- Set "MoveRight=Set "valid=0"&Set /A "_x1=!x1!+1,_x2=!x2!+1,_x3=!x3!+1,_x4=!x4!+1" & (For %%v in ("!y1!;!_x1!" "!y2!;!_x2!" "!y3!;!_x3!" "!y4!;!_x4!")Do (IF "!}%%~v!" == "" (Set /A "Valid=!Valid! + 1"))) & If "!Valid!" == "4" (Set /A "x1+=1,x2+=1,x3+=1,x4+=1")"
- Set "MoveDown=Set "valid=0"&Set /A "_y1=!y1!+1,_y2=!y2!+1,_y3=!y3!+1,_y4=!y4!+1" & (For %%v in ("!_y1!;!x1!" "!_y2!;!x2!" "!_y3!;!x3!" "!_y4!;!x4!")Do (IF "!}%%~v!" == "" (Set /A "Valid=!Valid! + 1"))) & (If "!Valid!" == "4" (Set /A "y1+=1,y2+=1,y3+=1,y4+=1")Else (Set /A "Score+=10"&Set "}!y1!;!x1!=%\E%[!y1!;!x1!H%\E%[3!pce!mX%\E%[0m"& Set "}!y2!;!x2!=%\E%[!y2!;!x2!H%\E%[3!pce!mX%\E%[0m"& Set "}!y3!;!x3!=%\E%[!y3!;!x3!H%\E%[3!pce!mX%\E%[0m"& Set "}!y4!;!x4!=%\E%[!y4!;!x4!H%\E%[3!pce!mX%\E%[0m"& >"%TEMP%\tetris.~tmp" (For /F "Tokens=2* Delims==" %%G in ('Set }')Do Echo/%%G) & If "!y1!" == "1" (Goto :Gameover)Else ( Call :isMatch & Goto :newpiece )))"
- Set "ShowPiece=<Nul Set /P "=%\E%[3!pce!m%\E%[!y1!;!x1!HX%\E%[!y2!;!x2!HX%\E%[!y3!;!x3!HX%\E%[!y4!;!x4!HX%\E%[0m""
- Set "HideLast=<Nul Set /P "=%\E%[!ly1!;!lx1!H %\E%[!ly2!;!lx2!H %\E%[!ly3!;!lx3!H %\E%[!ly4!;!lx4!H %\E%[0m""
- rem ---------------------------------------------------------- /* Define Control Display */
- Set "}1;20=%\E%[1;20H%\E%[90mScore: !Score!"
- Set "}3;20=%\E%[3;20H%\E%[33mControls:"
- Set "}4;20=%\E%[4;20HA - move Left"
- Set "}5;20=%\E%[5;20HS - move Down"
- Set "}6;20=%\E%[6;20HD - move Right"
- Set "}7;20=%\E%[7;20HR - Rotate"
- Set "}8;20=%\E%[8;20HV - Drop Piece"
- Set "}9;20=%\E%[9;20H%\E%[32mE - Exit%\E%[0m"
- rem -------------------- /* Establish environment for macro usage and code block actions */
- Setlocal EnableDelayedExpansion
- mode 60,42
- rem ----------------------------------------------------------------- /* hide the cursor */
- <nul Set /P "=%\E%[?25l"
- rem --------------------------------------------------------------- /* define the border */
- For %%s in (1 12)Do For /L %%n in (1 1 41) Do (
- Set "}%%n;%%s=%\E%[%%n;%%sH%\E%[90m.%\E%[0m"
- If %%n==41 For /L %%b in (2 1 11)Do (
- Set "}%%n;%%b=%\E%[%%n;%%bH%\E%[90m.%\E%[0m"
- )
- )
- >"%TEMP%\tetris.~tmp" (For /F "Tokens=2* Delims==" %%G in ('Set "}"')Do Echo/%%G)
- :newpiece
- CLS
- Type "%TEMP%\tetris.~tmp"
- Set /A pce=%random% %%7 + 1
- !nPiece[%pce%]!
- %ShowPiece%
- :loop
- rem ----------------------------- /* get pieces last y;x vals to blank out with hidelast */
- For %%c in (y x)Do For %%i in (1 2 3 4)Do Set "l%%c%%i=!%%c%%i!"
- rem ----------------------------------------------------------------------- /* game pace */
- Set /A tick+=1
- If "!tick!" == "4" (
- Set "tick=0"
- %movedown%
- )
- rem ----------------------------------------------------------------- /* game controller */
- For /F "delims=" %%G in ('choice /N /T 1 /C:prevasd /D S') Do (
- If "%%G" == "E" (TITLE Quit Y\N?&For /F "Delims=" %%C in ('Choice /N /C:YN')Do if %%C==Y (Title & Goto :quit)Else (Title Tetris by T3RRY))
- If "%%G" == "A" %Moveleft%
- If "%%G" == "S" %Movedown%
- If "%%G" == "D" %Moveright%
- If "%%G" == "P" ( Title Paused & Pause > nul & Title Tetris by T3RRY )
- If "%%G" == "V" (For /L %%s in (1 1 39)Do %MoveDown%)
- rem ------------------------------------------------------------ /* start rotation logic */
- rem --- [ Horizontal flip followed by mirror to simulate 90 degree rotation. ]
- If "%%G" == "R" (
- rem ----------------------------------------------------------------- /* flip horizontal */
- Set /A midX=500,midY=500
- For %%A in ("!y1!;!x1!" "!y2!;!x2!" "!y3!;!x3!" "!y4!;!x4!") Do (
- For /F "Tokens=1,2 Delims=;" %%X in ("%%~A") Do (
- Set /A "oY=%%~X"
- Set /A "oX=%%~Y"
- )
- If !oY! LSS !midY! Set /A "midY=!oY!"
- If !oX! LSS !midX! Set /A "midX=!oX!"
- )
- Set "pixel=0"
- For %%B in ("!y1!;!x1!" "!y2!;!x2!" "!y3!;!x3!" "!y4!;!x4!") Do (
- Set /A pixel+=1
- For /F "Tokens=1,2 Delims=;" %%r in ("%%~B") Do (
- Set /A "ny!pixel!=(%%~s-midX)+!midY!,nx!pixel!=(%%~r-!midY!)+!midX!"
- ))
- rem -------------------------------------------------------------------------- /* mirror */
- Set "pixel=0"
- Set /A lmidX=500,umidX=0
- For %%C in (!nx1! !nx2! !nx3! !nx4!) Do (
- If %%C LSS !lmidX! (Set /A "lmidX=%%C")
- If %%C GTR !umidX! (Set /A "umidX=%%C")
- )
- Set /A "Mid.X=( !lmidX! + !umidX! ) / 2"
- For %%X in (!nx1! !nx2! !nx3! !nx4!) Do (
- Set /A "pixel=!pixel! + 1"
- Set /A "nx!pixel!=%%X + 1"
- IF %%X LSS !Mid.X! (Set /A "nx!pixel!= %%X + ((!Mid.X!-%%X) * 2) + 1")
- IF %%X GTR !Mid.X! (Set /A "nx!pixel!= %%X - ((%%X-!Mid.X!) * 2) + 1")
- )
- rem ------------------------------------------- /* collision detection for rotated coords */
- Set "valid=0"
- For /L %%i in (1 1 4)Do (
- for %%c in ("!ny%%i!;!nx%%i!")Do If "!}%%~c!" == "" (
- Set /A "valid=!valid!+1"
- ))
- If "!valid!" == "4" (
- For %%v in (x y)Do For /L %%i in (1 1 4)Do (
- Set "%%v%%i=!n%%v%%i!"
- )))
- rem --------------------------------------------------------------- /* end rotation logic */
- rem ------------------------------------------------------------ /* display current state */
- TYPE "%TEMP%\tetris.~tmp"
- %HideLast%
- %ShowPiece%
- )
- Goto :loop
- rem ----------------------------- /* test for completed line when a piece is set in place */
- :isMatch
- Set "match=0"
- Set "ymin=42"
- Set "ymax=0"
- For %%n in (!y1! !y2! !y3! !y4!)Do (
- if %%n gtr !ymax! Set "ymax=%%n"
- if %%n lss !ymin! Set "ymin=%%n"
- )
- rem ------------- /* test completion of line for each y coord for last piece set in place */
- For /L %%i in (!ymin! 1 !ymax!)Do (
- Set "#of10=0"
- For /L %%c in (2 1 11)Do If Not "!}%%i;%%c!" == "" Set /A "#of10=!#of10!+1"
- If "!#of10!" == "10" (
- Set /A "match=!match!+1"
- Set /A "Score+=(150 * !match!)"
- Set /A "lineabove=%%i-1"
- For /L %%n in (0 1 !lineabove!) Do (
- Set /A "offset=%%n+1"
- rem -------------------------- /* transfer updated coord values after iteration complete */
- For %%o in (!offset!)Do For /L %%x in (2 1 11) Do If not "!}%%n;%%x!" == "" (
- Set "n}%%o;%%x=!}%%n;%%x:[%%n;=[%%o;!"
- ) Else (
- Set "n}%%o;%%x="
- ))
- For /L %%Y in (1 1 %%i) Do For /L %%X in (2 1 11) Do Set "}%%Y;%%X=!n}%%Y;%%X!"
- CLS
- ))
- rem ----------------------------- /* Update display values for each cell to display file */
- >"%TEMP%\tetris.~tmp" (For /F "Tokens=2* Delims==" %%G in ('Set "}"')Do Echo/%%G)
- Exit /B 0
- :gameover
- Echo/| CHOICE /N 2> nul & rem BEL
- Echo/%\E%[2;20H%\E%[31mGame Over.%\E%[31m
- Pause > Nul
- :quit
- rem -------------------------------------- /* restore the cursor ; End of script cleanup */
- <nul Set /P "=%\E%[?25h"
- Del /Q "%TEMP%\tetris.~tmp" 2> nul
- Endlocal
- Endlocal
- cls
- Title
- Goto :Eof
Add Comment
Please, Sign In to add comment