Advertisement
T3RRYT3RR0R

HighFPS demo Animated Sprite

Feb 24th, 2022 (edited)
1,447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 22.48 KB | None | 0 0
  1. @Echo off & Cls
  2. REM See this demo at: https://youtu.be/ph3SYsXvz-M
  3. REM Advanced sprite based high fps tutaorial / demo game
  4. REM Github: https://github.com/T3RRYT3RR0R/Batch/blob/main/fade.bat
  5.  
  6. (Title )
  7. :Start
  8.  
  9.  If not "%~1"=="" Goto:%1
  10.  
  11. REM Signal file that the Controller uses to pass keypress to the game via without blocking execution.
  12. REM - Note - This is not a Lockfile: executing multiple instances of this script simultaneously is not supported.
  13.  Set "SignalFile=%TEMP%\%~n0_Signal.tmp"
  14.  
  15. REM Signal file that the game uses to communicate an Exit signal to the controllor.
  16.  Del "%SignalFile:Signal=Stop%" 2> nul 1> nul
  17.  
  18. REM Stores the active codepage for restoration upon game completion.
  19.  For /F "tokens=2 Delims=:" %%G in ('CHCP')Do >"%TEMP%\%~n0_restore.cmd" Echo(@CHCP %%G ^> nul
  20.  
  21. REM Defines nonprintable characters used by this script.
  22.  Call :createChars
  23.  
  24. Rem GetDelay routine gets a baseline of how many For /l iterations the pc executes per second
  25. Rem which is used to define the starting value of the delay rate. This approach permits higher fps and finer fps control
  26. Rem than tdiff, which is limited to centiseconds.
  27.  
  28.  Call "%TEMP%\%~n0_Delay.cmd" 2>nul || (
  29.     >"%TEMP%\%~n0_Delay.cmd" (
  30.         For /l %%i in (1 1 4)Do (
  31.             Title 1st Run Setup - FPS Baseline %%i
  32.             Call:GetDelay D%%i
  33.         )
  34.         (Title )
  35.         Set /A "InitDelay=(D1+D2+D3+D4)/4"
  36.         Call Echo(@Set /A InitDelay=%%InitDelay%%
  37.         Echo(@Exit /b 0
  38.     )
  39.  )
  40.  
  41. REM change codepage to facilitate utf-8 characters used by script
  42.  CHCP 65001 > nul
  43.  
  44. REM confirm environment type suitable for macro definitions
  45.  If "!!"=="" (
  46.     Echo(Delayed Expansion must be disabled prior to starting %~n0
  47.     Exit /b 1
  48.  )
  49.  
  50.  Set "SkipVTtest="
  51.  Where Powershell.exe > nul
  52.  If Errorlevel 1 (
  53.     Powershell required to confirm Escape sequence support.
  54.     Choice /C:YN /M "Skip Validation {This script May not work as intended} [Y]es [N]o?"
  55.     If Errorlevel 2 (
  56.         Endlocal
  57.         Goto:Eof
  58.     )
  59.     Set "SkipVTtest=true"
  60.     CLS
  61.  )
  62.  
  63.  If not defined SkipVTtest Call:TestVT || (%= Function tests vt sequence support =%
  64.     Echo(Virtual terminal sequences not supported
  65.     Exit /b 1
  66.  )
  67.  
  68. REM macro used to implement relative frame intervals
  69.  SET every="1/(((~(0-(frames %% #))>>31)&1)&((~((frames %% #)-0)>>31)&1))"
  70.  
  71. REM properties / initial values
  72.  
  73.  %= console dims, zero sprite array size and turn count =%  Set /A "Height=35","Width=140","Sprites=0","turn=0"
  74.  %= Initial ForeGround and BackGround colors =%         Set "BG=10;10;10" & Set "FG=10;10;10"
  75.  %= initail colors of sprite 1 substrings =%            Set /A "S1cR=50,Thrust=S1cR"
  76.  
  77. REM Sprite 1 rotor blade animation array, Starting frame, Array Size for modulo cycling and initial thruster character
  78.  Set "R[1]=╔═╦═╗"
  79.  Set "R[2]= ═╦═ "
  80.  Set "R[3]=  ╬  "
  81.  Set "R[4]= ═╦═ "
  82.  Set "R[5]=╔═╦═╗"
  83.  Set /A "bladesSTEP=1","bladesMOD=5"
  84.  Set "Thruster=▼"
  85.  
  86. REM Sprite 2 animation array, Starting frame, Array Size for modulo cycling array
  87.  Set "hunter[1]=%\E%[38;2;20;160;140m♦%\E%[38;2;180;;m♦♦%\E%[1B%\E%[1D♦%\E%[1B%\E%[3D%\E%7♦♦♦%\E%8%\E%[1A♦%\E%[38;5;145%\E%[48;2;150;120;50m"
  88.  Set "hunter[2]=%\E%[38;2;180;;m♦%\E%[38;2;20;160;140m♦%\E%[38;2;180;;m♦%\E%[1B%\E%[1D♦%\E%[1B%\E%[3D%\E%7♦♦♦%\E%8%\E%[1A♦%\E%[38;5;140%\E%[48;2;150;120;50m☻"
  89.  Set "hunter[3]=%\E%[38;2;180;;m♦♦%\E%[38;2;20;160;140m♦%\E%[38;2;180;;m%\E%[1B%\E%[1D♦%\E%[1B%\E%[3D%\E%7♦♦♦%\E%8%\E%[1A♦%\E%[38;5;135%\E%[48;2;150;120;50m☻"
  90.  Set "hunter[4]=%\E%[38;2;180;;m♦♦♦%\E%[1B%\E%[1D%\E%[38;2;20;160;140m♦%\E%[38;2;180;;m%\E%[1B%\E%[3D%\E%7♦♦♦%\E%8%\E%[1A♦%\E%[38;5;130%\E%[48;2;150;120;50m☻"
  91.  Set "hunter[5]=%\E%[38;2;180;;m♦♦♦%\E%[1B%\E%[1D♦%\E%[1B%\E%[3D%\E%7%\E%[38;2;20;160;140m♦%\E%[38;2;180;;m♦♦%\E%8%\E%[1A♦%\E%[38;5;125m%\E%[48;2;150;120;50m☻"
  92.  Set "hunter[6]=%\E%[38;2;180;;m♦♦♦%\E%[1B%\E%[1D♦%\E%[1B%\E%[3D%\E%7♦%\E%[38;2;20;160;140m♦%\E%[38;2;180;;m♦%\E%8%\E%[1A♦%\E%[38;5;120m%\E%[48;2;150;120;50m☻"
  93.  Set "hunter[7]=%\E%[38;2;180;;m♦♦♦%\E%[1B%\E%[1D♦%\E%[1B%\E%[3D%\E%7♦♦%\E%[38;2;20;160;140m♦%!!!%\E%8%\E%[1A♦%\E%[38;5;115m%\E%[48;2;150;120;50m☻"
  94.  Set "hunter[8]=%\E%[38;2;180;;m♦♦♦%\E%[1B%\E%[1D♦%\E%[1B%\E%[3D%\E%7♦♦♦%\E%8%\E%[1A%\E%[38;2;20;160;140m♦%\E%[38;5;110m48;2;150;120;50m☻"
  95.  Set /A "hunterSTEP=1","hunterMOD=8"
  96.  
  97. REM Patrol sprites String definition, animation array, Starting frame and Array Size for modulo cycling.
  98.  Set "Patrollers[1]=╔╗%\E%[1B%\E%[2D╚╝"
  99.  Set "Patrollers[2]=▄▄%\E%[1B%\E%[2D▀▀"
  100.  Set "Patrollers[3]=◄►%\E%[1B%\E%[2D◄►"
  101.  Set "Patrollers[4]=▀▀%\E%[1B%\E%[2D▄▄"
  102.  Set "Patrollers[5]=▲▲%\E%[1B%\E%[2D▼▼"
  103.  Set "Patrollers[6]=▀▄%\E%[1B%\E%[2D▀▄"
  104.  Set /A "patrolSTEP=1","PatrolMOD=6"
  105.  
  106.  
  107. Set "BladesMod=4"
  108.  
  109.  Call:DefSprite "!\E![38;2;255;153;51m!R[%%%%b]!\n!\E![38;2;!S1cR!;220;!s1cR!m!\E![96m{!\E![91m!\E![48;2;;160;140m☻!\E![96m!\E![48;2;!BG!m}!\E![38;2;!S1cR!;220;!s1cR!m╬\n!\E![33m▀!\E![48;2;!Thrust!;;m!\E![38;2;;;!Thrust!m!Thruster!!\E![48;2;!BG!m!\E![33m▀!\E![48;2;!Thrust!;;m!\E![38;2;;;!Thrust!m!Thruster!!\E![48;2;!BG!m!\E![33m▀" 5 5 3 5 "!S1cR!;220;!s1cR!" "!BG!"
  110.  
  111.  REM obsolete:hunter:╔═╗\n║!\E![33m!\E![48;2;80;60;m♦!\E![38;2;200;;m!\E![48;2;!BG!m║\n╚═╝
  112.  Call:DefSprite "!hunter[%%%%d]!"       Height/2    Width/2-1 3 3 "200;;"     "!BG!"   2
  113.  
  114.  REM obsolete:patrol:╔╗\n╚╝
  115.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2-2  Width/2-2 2 2 "!RandRR!;120;!randBB!" "!BG!" 3
  116.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2+2  Width/2+2 2 2 "!RandRR!;140;!randBB!" "!BG!" 4
  117.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2-4  Width/2-4 2 2 "!RandRR!;160;!randBB!" "!BG!" 3
  118.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2+4  Width/2+4 2 2 "!RandRR!;180;!randBB!" "!BG!" 4
  119.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2-6  Width/2-6 2 2 "!RandRR!;200;!randBB!" "!BG!" 3
  120.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2+6  Width/2+6 2 2 "!RandRR!;220;!randBB!" "!BG!" 4
  121.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2-8  Width/2-8 2 2 "!RandRR!;240;!randBB!" "!BG!" 3
  122.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2+8  Width/2+8 2 2 "!RandRR!;220;!randBB!" "!BG!" 4
  123.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2-10 Width/2-8 2 2 "110;!RandGG!;160"      "!BG!" 3
  124.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2+10 Width/2+8 2 2 "130;!RandGG!;160"      "!BG!" 4
  125.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2-12 Width/2-6 2 2 "150;!RandGG!;180"      "!BG!" 3
  126.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2+12 Width/2+6 2 2 "170;!RandGG!;180"      "!BG!" 4
  127.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2-14 Width/2-4 2 2 "190;!RandGG!;220"      "!BG!" 3
  128.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2+14 Width/2+4 2 2 "210;!RandGG!;220"      "!BG!" 4
  129.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2-16 Width/2-2 2 2 "230;!RandGG!;240"      "!BG!" 3
  130.  Call:DefSprite "!Patrollers[%%%%c]!"   Height/2+16 Width/2+2 2 2 "250;!RandGG!;240"      "!BG!" 4
  131.  
  132. REM Assign actions to controls, indexed by Direction.
  133.  
  134.  REM Define player sprite movement macros
  135.     Set "Right=Set /A "1/((S1RB)/(S1X))" && Set /A "S1LX=S1X","S1LY=S1Y","S1X+=1" ||Set /A "S1LX=S1X","S1LY=S1Y""
  136.     Set "Left= Set /A "1/(S1LB-S1X)"     && Set /A "S1LX=S1X","S1LY=S1Y","S1X-=1" ||Set /A "S1LX=S1X","S1LY=S1Y""
  137.     Set "Up=   Set /A "1/(S1UB-S1Y)"     && Set /A "S1LX=S1X","S1LY=S1Y","S1Y-=1" ||Set /A "S1LX=S1X","S1LY=S1Y""
  138.     Set "Down= Set /A "1/(S1BB/S1Y)"     && Set /A "S1LX=S1X","S1LY=S1Y","S1Y+=1" ||Set /A "S1LX=S1X","S1LY=S1Y""
  139.     Set "Jump= Set /A "1/(S1BB/(S1Y+1))" || (Set /A "S1LX=S1X","S1LY=S1Y","S1Y-=10")"
  140.  
  141.  REM Define non player sprite movement macros
  142.     Set sRight=Set /A "1/(S%%iRB/S%%iX)" ^&^& Set /A "S%%iLX=S%%iX","S%%iLY=S%%iY","S%%iX+=1" ^|^|Set /A "S%%iLX=S%%iX","S%%iLY=S%%iY"
  143.     Set sLeft= Set /A "1/(S%%iLB-S%%iX)" ^&^& Set /A "S%%iLX=S%%iX","S%%iLY=S%%iY","S%%iX-=1" ^|^|Set /A "S%%iLX=S%%iX","S%%iLY=S%%iY"
  144.     Set sUp=   Set /A "1/(S%%iUB-S%%iY)" ^&^& Set /A "S%%iLX=S%%iX","S%%iLY=S%%iY","S%%iY-=1" ^|^|Set /A "S%%iLX=S%%iX","S%%iLY=S%%iY"
  145.     Set sDown= Set /A "1/(S%%iBB/S%%iY)" ^&^& Set /A "S%%iLX=S%%iX","S%%iLY=S%%iY","S%%iY+=1" ^|^|Set /A "S%%iLX=S%%iX","S%%iLY=S%%iY"
  146.  
  147.  Setlocal EnableDelayedExpansion
  148.  
  149. Rem Choice or Xcopy controllers available by Changing REM position of TypeOfControl definition below.
  150.  
  151. REM Control Scheme and Key assignments.
  152. REM XCOPY offers more Keys and therefor more control options, Choice is faster - allowing marginally smoother gameplay
  153. REM     (Set "TypeOfControl=CHOICE" & Set "QUITKEY=L")
  154.     (Set "TypeOfControl=XCOPY"  & Set "QUITKEY=%TAB%")
  155.  
  156. REM expands input !k%%i!, where %%i is the key pressed. xcopyCONTROL Exceptions: k{ENTER} ; k{BACKSPACE} (unasssigned)
  157.  Set "kD=Right" & Set "k6=Right"
  158.  Set "kA=Left"  & Set "k4=Left"
  159.  Set "kW=Up"    & Set "k8=Up"
  160.  Set "kS=Down"  & Set "k2=Down"
  161.  Set "kP=Pause" & Set "Pause=1" & Set "k =Pause" & Set "k{ENTER}=Pause"
  162.  
  163. REM DO NOT Modify below contoller verifications.
  164.  If not defined TypeOfControl (
  165.     CLS
  166.     Echo(Controller not defined. Supported:
  167.     For /f "tokens=1* Delims=:" %%G in ('%SystemRoot%\System32\Findstr.exe /R "^:.*CONTROL\>" "%~f0"')Do (
  168.         Set "Supported=%%G"
  169.         Echo(TypeofControl=!Supported:control=!
  170.     )
  171.     Exit /B 1
  172.  )Else (
  173.     %SystemRoot%\System32\Findstr.exe /BL ":!TypeOfControl!CONTROL" "%~f0" > nul
  174.     If Errorlevel 1 (
  175.         CLS
  176.         Echo(Controller type Invalid. Supported:
  177.         For /f "tokens=1* Delims=:" %%G in ('%SystemRoot%\System32\Findstr.exe /R "^:.*CONTROL\>" "%~f0"')Do (
  178.             Set "Supported=%%G"
  179.             Echo(TypeofControl=!Supported:control=!
  180.         )
  181.         Exit /b 1
  182.     )
  183.  )
  184.  
  185. REM confirm control utility present. If not abort with errorlevel 1
  186. REM error output preserved to notify missing control utility
  187.  1> nul Where %TypeOfControl%.exe
  188.  If Errorlevel 1 Exit /B 1
  189.  
  190.  Echo(Survive^^^!
  191.  Call:PlayMusic "%WINDIR%\Media\windows unlock.wav" 70
  192.  
  193.  Set "Title=Move: W A S D Quit: '^!QuitKey:%TAB%=TAB^!'.  Turns Survived: ^!turn^!"
  194.  
  195.  Mode %Width%,%Height%
  196.  
  197.  Set /A "Delay=InitDelay","DelayReduce=InitDelay/50","DelayEnd=DelayReduce-1","frames=0","RandBB=!Random! %% 130 + 120","RandGG=!Random! %% 130 + 120","RandRR=!Random! %% 70 + 60"
  198.  
  199.  For /F "tokens=1,2,3 Delims=;" %%b in ("!bladesSTEP!;!PatrolSTEP!;!hunterSTEP!")Do Echo(%\E%[?25l%\E%[1;1H%\E%[48;2;!BG!m%\E%[38;2;!FG!m%\E%[2J%Sprite[1]%%Sprite[2]%%Sprite[3]%%Sprite[4]%%Sprite[5]%%Sprite[6]%%Sprite[7]%%Sprite[8]%%Sprite[9]%%Sprite[10]%%Sprite[11]%%Sprite[12]%%Sprite[13]%%Sprite[14]%%Sprite[15]%%Sprite[16]%%Sprite[17]%%Sprite[18]%
  200.  
  201. REM Pipe the output of the function *CONTROL to Game to facilitate non blocking input.
  202.  Start /Wait /B "" "%~F0" %TypeOfControl%CONTROL 1>"%SignalFile%" | "%~F0" GAME <"%SignalFile%" 2> nul
  203.  
  204.     CALL "%TEMP%\%~n0_restore.cmd"
  205.     DEL "%TEMP%\%~n0_restore.cmd"
  206.     CLS & (Title )
  207.     Choice /C:PE /M "[E]xit [P]lay again"
  208.     If Errorlevel 2 Goto:Eof
  209.  
  210. Endlocal & Goto:Start
  211.  
  212.  
  213.  :GAME
  214.  
  215.  Setlocal EnableDelayedExpansion
  216.  Title %Title%
  217.  
  218.  <nul Set /p "=%\E%[?25l"   %= Supress cursor indicator =%
  219. 2> nul (
  220.     For /l %%. in () Do (%= Enact Infinite Loop =%
  221.            
  222.         For /l %%# in (1 1 !Delay!) Do Rem %= Implement Delay Timing. =%
  223.  
  224.         %= If not game paused Increment frame and assign BG colors and ... =%
  225.         Set /A "frames+=1","BGRm=((S1Y+10)*100)/130","BGBm=((S4X+10)*100)/130"
  226.         If not !Pause! EQU 2 (
  227.  
  228.             %= Every 10th frame Reduce Delay interval and recalculate speed percentage =%
  229.                 Set /A !every:#=10! && Set /a "Delay-=(Delay/DelayReduce)","Speed=(DelayEnd*100)/Delay"
  230.  
  231.             %= Every 2nd frame ... =%
  232.             Set /A !every:#=2! && (
  233.  
  234.                 %= Return thruster character to original =%
  235.                 Set "Thruster=░"
  236.  
  237.                 %= Modifiy BG S1 and Thrust colors + increment Enemy turn count =% %= Every Fourth frame cycle animation step of s1 blade rotation and patrol sprites =%
  238.                 Set /A "BGc+=5","S1cR+=1","thrust=!Random! %% 195 + 50","turn+=1",!every:#=4! && Set /A "bladesSTEP=bladesSTEP %%bladesMOD + 1","PatrolSTEP=PatrolSTEP %%!PatrolMOD! + 1","hunterSTEP=hunterSTEP %%!PatrolMOD! + 1"
  239.  
  240.                     %= Move sprites =%
  241.                 For /L %%i in (2 1 !Sprites!)Do     %= Implement sprite behaviours =% (
  242.  
  243.                     %= Sprite 2 Implement Hunter Behaviour. Hunter behaviour unique to prevent sprite overlap. If using multiple Hunters additional collision detection required =%
  244.                     If %%i LSS 3 (
  245.                         %= Sprite 2 is the only hunter sprite in this demo. =%
  246.                         If !S%%iY! GTR !S1Y! ( Set /A "S%%iYd=S%%iY-S1Y" )Else Set /A "S%%iYd=S1Y-S%%iY"
  247.                         If !S%%iX! GTR !S1X! ( Set /A "S%%iXd=S%%iX-S1Y" )Else Set /A "S%%iXd=S1X-S%%iX"
  248.                         If !S%%iX! GTR !S1X! Set "S%%iDir=3"
  249.                         If !S%%iYd! GTR !S%%iXd! (
  250.                             If !S%%iY! GTR !S1Y! Set "S%%iDir=1"
  251.                             If !S%%iY! LSS !S1Y! Set "S%%iDir=2"
  252.                         )Else (
  253.                             If !S%%iX! GTR !S1X! Set "S%%iDir=3"
  254.                             If !S%%iX! LSS !S1X! Set "S%%iDir=4"
  255.                         )
  256.  
  257.                         If !S%%iDir! EQU 1 %sUp%
  258.                         If !S%%iDir! EQU 2 %sDown%
  259.                         If !S%%iDir! EQU 3 %sLeft%
  260.                         If !S%%iDir! EQU 4 %sRight%
  261.                     )
  262.  
  263.                     %= Sprites 3+ example basic patrolling and implementation of group behaviour using arrays =%
  264.                     If %%i GEQ 3 (
  265.                         If !s%%iDir! EQU 3 If !S%%iX! NEQ !S%%iLB! ( Set /A "S%%iLX=S%%iX","S%%iX-=1" )Else Set "s%%iDir=4"
  266.                         If !s%%iDir! EQU 4 If !S%%iX! NEQ !S%%iRB! ( Set /A "S%%iLX=S%%iX","S%%iX+=1" )Else Set "s%%iDir=3"
  267.                     )
  268.  
  269.                     %= Implementation of Bounding box collison test via Bitshifted Or algorithm. Assess the following conditions and trigger divide by zero error if no condition true =%
  270.                     %= Conditions =% %= If Base1 LSS Top2   =% %=     If Top1 GTR Base2       =% %=    If Right1 LSS Left2    =% %=    If Left1 GTR Right2     =%
  271.                     Set /A "BBA=((((S1Y+(S1H-1))-S%%!!)>>)&)|((((%%iY+(S%%!!)))>>)&)|(((()(%%!!))>>)&)|((((%%iX+S%%iW)-1-S1X)>>31)&1)"
  272.                     If !BBA! EQU 0 (
  273.  
  274.                         %= Sprite is in Collision with S1 - player Sprite. Update screen with animations at desired animation step. =%
  275.                             For /f "tokens=1,2,3 Delims=;" %%b in ("1;1;!hunterSTEP!")Do Echo(%\E%[1;1H%\E%[48;2;!BG!m%\E%[38;2;!FG!m%\E%[0J%Sprite[1]%%Sprite[2]%%Sprite[3]%%Sprite[4]%%Sprite[5]%%Sprite[6]%%Sprite[7]%%Sprite[8]%%Sprite[9]%%Sprite[10]%%Sprite[11]%%Sprite[12]%%Sprite[13]%%Sprite[14]%%Sprite[15]%%Sprite[16]%%Sprite[17]%%Sprite[18]%
  276.  
  277.                         %= Use substitution to invert colliding sprite colors and output. =%
  278.                         %= Below line Not compatible with animated multicolor sprties =%
  279.                         REM For /F "delims=" %%v in ("!Sprite[%%i]:H=H%\E%[7m!")Do Call Echo(%%v
  280.  
  281.                         %= Use vbscript to play windows .wav file on collision =%
  282.                         Call:PlayMusic "%Windir%\media\Windows Error.wav" 70
  283.  
  284.                         %= Clear the console and environment and start a new game in the same window. =%
  285.                        
  286.                         Break >"%SignalFile:Signal=Stop%"
  287.                         Endlocal & Endlocal
  288.                         EXIT
  289.                     )
  290.                 )
  291.  
  292.                 %= Final adgustments to Sprite 1 and BackGround colors prior to output =%
  293.                 If !S1cR! GTR 250 Set "S1cR=50"
  294.                 Set "BG=!BGRm!;50;!BGBm!"
  295.                 Set "FG=!BG!"
  296.             )
  297.         )
  298.  
  299.         %= Read last key press from input buffer without waiting. aka Non blocking input =%
  300.         If not "!Lastkey!"=="Pause" Set "LastKey=!Key!"
  301.         Set "NewKey="
  302.         Set /P "NewKey="
  303.         If Defined NewKey For /f "delims=" %%v in ("!NewKey!")Do (
  304.             If not "!k%%v!"=="" Set "key=!k%%v!"
  305.             If /I "%%v" == "quit" EXIT
  306.         )
  307.  
  308.         %= Implement Control actions. =%
  309.         If Defined Key (
  310.             If "!Key!"=="Pause" (
  311.                 Set /A "!Key!=!Pause! %%2 +1"
  312.                 Set "Key="
  313.                 If not "!Key!" == "Pause" Set "Key=!LastKey!"
  314.             )
  315.             If not !Pause! EQU 2 (
  316.                 If "!Key!"=="Up" (
  317.                     %Up%
  318.                     Set "LastYkey=Up"
  319.                 )
  320.                 If "!Key!"=="Down" (
  321.                     %Down%
  322.                     Set "LastYkey=Down"
  323.                 )
  324.                 If "!Key!"=="Left" (
  325.                     %Left%
  326.                     Set "LastXkey=Left"
  327.                 )
  328.                 If "!Key!"=="Right" (
  329.                     %Right%
  330.                     Set "LastXkey=Right"
  331.                 )
  332.             )
  333.  
  334.             %= Notify Controls + demo info via title =%
  335.             Title %Title% Speed !Speed!%% !Time:~-6! %Time:~-6% +!Key!+
  336.         )
  337.  
  338.         For /F "tokens=1,2,3 Delims=;" %%b in ("!bladesSTEP!;!PatrolSTEP!;!hunterSTEP!")Do Echo(%\E%[1;1H%\E%[48;2;!BG!m%\E%[38;2;!FG!m%\E%[0J%Sprite[1]%%Sprite[2]%%Sprite[3]%%Sprite[4]%%Sprite[5]%%Sprite[6]%%Sprite[7]%%Sprite[8]%%Sprite[9]%%Sprite[10]%%Sprite[11]%%Sprite[12]%%Sprite[13]%%Sprite[14]%%Sprite[15]%%Sprite[16]%%Sprite[17]%%Sprite[18]%
  339.  
  340.         %= Alternate Thruster character definition for animation =%
  341.         Set "Thruster=▼"
  342.     )
  343. )
  344. ===============================================================
  345.  
  346.  :DefSprite "CELLline\nCELLline" Y X H W "RR GG BB(foreground)" "RR GG BB(background)" [1|2|3|4]
  347. REM   Args 1                    2 3 4 5  6                      7                      8 (Starting Direction)
  348.  
  349.     Set /A Sprites+=1
  350.     Set "cells=%~1"
  351.     Set /A "SH=%~4"
  352.     Set /A "SW=%~5"
  353.     Set "FGcol=%~6"
  354.     Set "BGcol=%~7"
  355.         Set "Spacing= "
  356.         For /L %%i in (2 1 %SW%)Do Call Set "Spacing=%%Spacing%% "
  357.     Set /A "S%Sprites%LY=%~2,S%Sprites%Y=%~2","S%Sprites%LX=%~3,S%Sprites%X=%~3","S%Sprites%H=SH","S%Sprites%W=SW"
  358.     Set /A "S%Sprites%UB=2","S%Sprites%BBG=Height-SH","S%Sprites%BB=Height-SH-1","S%Sprites%LB=2","S%Sprites%RB=Width-SW-1","S%Sprites%RBe=Width-SW"
  359.     Call Set "cells=%%Cells:\n=!\E![!S%Sprites%X!G!\E![1B%%"
  360.         Set "ClearCells=!\E![48;2;!BG!m%\E%[38;2;!FG!m!\E![!S%Sprites%LY!;!\E![!S%Sprites%LX!H%Spacing%"
  361.         For /L %%i in (2 1 %SH%)Do Call Set "ClearCells=%%ClearCells%%!\E![1B!\E![!S%Sprites%LX!G%Spacing%"
  362.     Set "Sprite[%Sprites%]=%ClearCells%!\E![!S%Sprites%Y!;!S%Sprites%X!H!\E![48;2;%BGcol%m!\E![38;2;%FGcol%m%Cells%!\E![0m"
  363.     If not "%~8"=="" Set "S%Sprites%Dir=%~8"
  364. Exit /b 0
  365.  
  366.  :TestVT Author:  T3RRY ; Released: 21/01/2022 ==========================================================================
  367. REM     PURPOSE: For use with scripts that utilise Vertual terminal sequences.
  368. REM See:         https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
  369. REM     METHOD:  Utilizes powershell to Identify if the terminal running the batch script is succesfully executing virual terminal sequences,
  370. REM              by assessing which character occupies the buffer cell the cursor is currently positioned at.
  371. REM              As this method is slow, an ADS of this file or a temporary file is used to remember if virtual terminal supported
  372.  Cls
  373.  
  374.  2> nul (
  375.     Set "NTFSdrive=true"
  376.     (Echo(verify) >"%~f0:ntfs.test" && (
  377.         Set "SupportINFO=%~f0:VTSupport.dat"
  378.     ) || (
  379.         Set "NTFSdrive="
  380.         For /f delims^= %%G in ("%~f0")Do Set "SupportINFO=%TEMP%\%%~nG_VTSupport.dat"
  381.     )
  382.  )
  383.  
  384.  2> nul (
  385.     More < "%SupportINFO%" > nul && (
  386.         Exit /b 0
  387.     ) || (
  388.         <Nul Set /P "=Verifying Compatability %\E%[2D" 1> CON
  389.         for /F "delims=" %%a in ('"PowerShell.exe $console=$Host.UI.RawUI; $curPos=$console.CursorPosition; $rect=new-object System.Management.Automation.Host.Rectangle $curPos.X,$curPos.Y,$curPos.X,$curPos.Y; $BufCellArray=$console.GetBufferContents($rect); Write-Host $BufCellArray[0,0].Character;"') do (
  390.             Cls
  391.             If "%%a" == "y" (
  392.                 (Echo(true) >"%SupportINFO%"
  393.                 Exit /b 0
  394.             )else (
  395.                 Exit /b 1
  396.             )
  397.         )
  398.     )
  399.  )
  400.  Exit /b 2
  401.  
  402.  
  403. ===============================================================
  404.  
  405. :playMusic <filepath.ext> [0~100] [nowait]
  406.     If "%~1" == "" (
  407.         Echo Play Music Usage:
  408.         Echo/Parameters required For Player: "filepath.ext" 0-100
  409.         pause
  410.         Exit /B 1
  411.     )
  412.  
  413.     Set "MusicPath=%~1"
  414.     Set /A vol=Loop_TF=0
  415.     Set /A "vol+=%~2 + 0" 2> nul
  416.     Set "Loop_TF=0"
  417.     If not Exist "%~1" Exit /b 1
  418.  
  419. Rem Creates a vbs Script to play audio
  420.     >"%~dp0Play_mp3.vbs" (
  421.         echo Set Sound = CreateObject^("WMPlayer.OCX.7"^)
  422.         echo Sound.URL = "%MusicPath%"
  423.         echo Sound.settings.volume = %vol%
  424.         echo Sound.settings.setMode "loop", %Loop_TF%
  425.         echo Sound.Controls.play
  426.         echo While Sound.playState ^<^> 1
  427.         echo WScript.Sleep 100
  428.         echo Wend
  429.     )
  430.     If "%~3"=="" (
  431.         start /wait /min "" "%~dp0Play_mp3.vbs"
  432.     )Else (
  433.         start /min "" "%~dp0Play_mp3.vbs"
  434.     )
  435.  
  436. Exit /b 0
  437.  
  438. ===============================================================
  439.  
  440. :createChars
  441. (Set LF=^
  442.  
  443.  
  444. %= Do Not Modify. Linefeed Variable =%)
  445.  
  446. %= Escape   =%      for /f "Delims=" %%e in ('Echo Prompt $E^|cmd') Do Set "\E=%%e"
  447. %= Tab  =%      for /f "delims= " %%T in ('robocopy /L . . /njh /njs' )do set "TAB=%%T"
  448. %= Carriage Return =%   for /f %%C in ('copy /Z "%~dpf0" nul') do set "CR=%%C"
  449. %= BackSpace     =% for /F "delims=#" %%B in ('"prompt #$H# &echo on &for %%b in (1) do rem"') do Set "BS=%%B"
  450.                 Set "BS=%BS:~0,1%"
  451. %= SUB  =%      copy nul sub.tmp /a > nul
  452.                 for /F %%a in (sub.tmp) DO (
  453.                     set "sub=%%a"
  454.                 )
  455.                 del sub.tmp
  456. exit /b
  457.  
  458. ===============================================================
  459.  
  460. :GetDelay ReturnVar
  461. Rem counts the number of for /l loops executed per second. Allows For /l loops to be used to implement delays in the millisecond range,
  462. Rem while balancing differences in PC Specs / performance. Routine is executed multiple times on initial run to determine a mean performance baseline.
  463. Rem If The users PC is heavily burdened with other processes, the value this routine returns will be lower than expected resulting in shorter delays /
  464. REM faster gameplay
  465.  
  466.  
  467.  Setlocal EnableDelayedExpansion
  468.  for /f "tokens=1-4 delims=:.," %%a in ("!time: =0!") do set /a "t2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, tDiff=t2-t1"
  469.  Set "%1="
  470.  Set /a t1=t2
  471.  
  472.     For /l %%i in (1 1 1000000)Do (
  473.         for /f "tokens=1-4 delims=:.," %%a in ("!time: =0!") do set /a "t2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, tDiff=t2-t1"
  474.         if !tDiff! lss 0 set /a tDiff+=24*60*60*100
  475.         if !tDiff! geq 100 (
  476.             Endlocal & Set /A "%1=%%i*3/7"
  477.             Exit /b 0
  478.         )
  479.     )
  480.  
  481. ===============================================================
  482.  
  483. :CHOICECONTROL
  484. If not defined QUITKEY Set "QUITKEY=L"
  485. FOR /L %%C in () do (
  486.     FOR /F "tokens=*" %%A in ('%SystemRoot%\System32\choice.exe /C:abcdefghijklmnopqrstuvwxyz0123456789 /N') DO (
  487.         If Exist "%SignalFile:Signal=Stop%" (
  488.             EXIT
  489.         )
  490.         If not "%%A"=="%QUITKEY%" (
  491.             <Nul Set /P ".=%%A"
  492.         ) Else (
  493.             <Nul Set /P ".=quit"
  494.             EXIT
  495. )   )   )
  496. EXIT
  497.  
  498. :XCOPYCONTROL
  499. If not defined QUITKEY Set "QUITKEY=%TAB%"
  500.     Setlocal DISABLEdelayedExpansion
  501.     REM Environment handling allows use of ! key
  502.     For /l %%C in () do (
  503.         If Exist "%SignalFile:Signal=Stop%" (
  504.             EXIT
  505.         )
  506.         Set "Key="
  507.         for /f "delims=" %%A in ('%SystemRoot%\System32\xcopy.exe /w "%~f0" "%~f0" 2^>nul') do If not Defined Key (
  508.             set "key=%%A"
  509.         Setlocal ENABLEdelayedExpansion
  510.             set key=^!KEY:~-1!
  511.         If "!key!" == "!QUITKEY!" (
  512.             <nul Set /P "=quit"
  513.             EXIT
  514.         )
  515.         If not "!Key!" == "%BS%" If not "!Key!" == "!CR!" (%= Echo without Linefeed. Allows output of Key and Space =%
  516.             1> %~n0txt.tmp (echo(!Key!!sub!)
  517.             copy %~n0txt.tmp /a %~n0txt2.tmp /b > nul
  518.             type %~n0txt2.tmp
  519.             del %~n0txt.tmp %~n0txt2.tmp
  520.         )Else (
  521.             If "!Key!" == "%BS%" <nul Set /p "={BACKSPACE}"
  522.             If "!Key!" == "!CR!" <nul Set /p "={ENTER}"
  523.         )
  524.         Endlocal
  525. )   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement