Advertisement
T3RRYT3RR0R

Batch game engine Production version

Dec 22nd, 2020 (edited)
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 26.91 KB | None | 0 0
  1. @Echo off
  2. ::::::::::::::::::: DO NOT move OR rename OR modify THIS FILE. Filename: Game_Engine.bat
  3. ::: [ * Author: T3RRY * ] Creation Date - 16/12/2020                     Developer version
  4. :::            Border and Sprite Macro definition package for Batch Arcade games
  5. :::            Purpose: Create a system to convert ASCII Art into sprites that can be moved and interacted with.
  6. ============================
  7. ::: COMPLETE archive with the latest updates:
  8. ::: Games_by_T3RRY: https://drive.google.com/file/d/1cAQLd-f9HN6SuWowBUETccKCZd2dVbWj/view?usp=sharing
  9. ::: See a DEMO using this engine:
  10. ::: https://www.youtube.com/watch?v=Wi3izdqbwcw
  11. ::: Leave a comment if you have any ideas or requests, Share a link if you want to show off your own games.
  12. ============================
  13. ::: Additional Accreditation
  14. ::: Getkey.Exe by Antonio {https://stackoverflow.com/users/778560/aacini}
  15. ::: * REQUIRED * for Extended key controls.
  16. ::: Getfontsize.Exe by Antonio {https://stackoverflow.com/users/778560/aacini}
  17. ::: From: https://stackoverflow.com/a/62087328/12343998
  18. ::: * REQUIRED * to accurately determine the consoles maximum Y;X values
  19. ::::::::::::::::::::::::::::
  20. ::: Sleep.bat by Dave Benham { https://stackoverflow.com/users/1012053/dbenham }
  21. ::: - Not required; allows for more precise sub second delays than other methods.
  22. =============================================================================
  23. ::: Recommended Resources:
  24. ::: Batch Macro's with Arguments Appended:
  25. ::: https://www.dostips.com/forum/viewtopic.php?f=3&t=2518
  26. ::: VT sequence Information:
  27. ::: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
  28. ::: 255 bit color chart [ for VT color sequences ]
  29. ::: https://www.rapidtables.com/web/color/RGB_Color.html
  30. =============================================================================
  31. :::                                          *** Important notes ***
  32. ::: Game_Engine.bat & Game_EngineDEBUG.bat Macro's:
  33. :::  - Enable definition; movement; rotation and collision / capture testing of ASCII sprites
  34. ::: Dev Toolkit - Refer to Game_EngineDEBUG.bat
  35. :::  - Contains advanced usage information ; performs error testing when Game_EngineDEBUG.bat defines Macros.
  36. :::    Defines Macro Resources required to run .Bat arcade Games_by_T3RRY
  37. ::: Game_Engine Macro's act as a whole system; and as such have dependencies on other macro's in the system
  38. :::  - Background.Border macro should ALWAYS be the first macro expanded; As it defines variables that
  39. :::    constrain the dimension of the playfield used by all other Sprite macros.
  40. :::  - Def.Sprite or Def.MultiCol.Sprite must be used to define sprites prior to Move.Sprite or Rotate.Sprite
  41. :::    being used
  42. =============================================================================
  43. :::::::::: Version 2.0 01/01/2021
  44. ::: Changes Jan 2021
  45. ::: *** Updated all .Sprite macros to support definition of sprite cells ***
  46. :::     using 255 bit Color codes. Ie: 38;2;200;25;100
  47. ::: Updated Def.Sprite and Def.Multicol.Sprite to define Obj.{l|m|u}{X|Y} variables
  48. ::: /* Changed Collide.Type Return Var to Obj.Collide.Type  /*
  49. ::: - Object specific prefix allows more sophisticated testing of the collision types that have occured during a game "turn"
  50. :::   - enables more game design options like pushable sprites.
  51. :::   - Each sprite now has it's own array for captured / collided cells that can be tested
  52. :::: WHERE obj =  SPRITEVARNAME
  53. :::   - Array Variables:   index var:  Array Name:                    Value:
  54. :::           Collision:   Obj.Coll    Obj.Collide.Type[Col][#=index] Collision Character
  55. :::           Capture  :   Obj.Capt    Obj.Collide.Type[Cap][#=index] Capture Character
  56. :::   ** Obj.Coll and Obj.Capt return the total number of collisions and captures Obj=SPRITEVARNAME has had after a move.
  57. :::  - Added Getfontsize.exe to archive and calculation of true max console Dimensions.
  58. :::  - Expanded Error Testing and Debug output
  59. :::  - Cloned Game_Engine into Debug and Prodution versions
  60. :::  - Finished games can obtain a performance advantage by using the production version.
  61. :::::::::: Version 1.8 28/12/2020
  62. ::: Renamed to Game_Engine.bat
  63. ::: Version Changes 28/12/2020:
  64. ::: Added Play.Music and Stop.Music macro's to
  65. ::: Added Obj.Collide.Type return var to simplify testing of collision type that has occured within move.sprite macro
  66. ::: Added calculation of Sprite Mid{y;x} values to allow determination of sprite center
  67. ::: - Useful for calculating movement directions relevent to other sprites
  68. ::: - return vars: Obj.mx Obj.my [ Obj substituted with SPRITEVARNAME during Move.Sprite expansion ]
  69. ::: - Added SnakeSprite.bat to library to demonstrate how to apply sprite chase using these values
  70. :::::::::::::::::::::::::::::::
  71. ::: Version Changes 23/12/2020:
  72. ::: Added Rotate.Sprite Macro
  73. ::: Added Usage tests and output to Background.Border Def.Sprite Show.Sprite and Move.Sprite Macro's
  74. :::::::::::::::::::::::::::::::
  75. ::: Version Changes 19/12/2020:
  76. ::: Removed Response handling of collision from Move.Sprite macro
  77. ::: Upgraded move.sprite macro to accept arguments for Collision or Capture Characters
  78. ::: - return Vars [Collision is True: Valid=0] [Capture is True: Obj.capt=1]
  79. ::: - Implemented Title based level load indicator during sprite definition
  80. ::: - Improved modelling of handling game exit / End of level cleanup.
  81. ::: - Added 7th arg to Background.Border macro for flagging Border collision as Fatal T[0]/F[-1]
  82. :::::::::::::::
  83. rem /* Establish and verify required resources. Clearly separate script elements */
  84. rem /* Test Environment is suitable for definition of Macro's */
  85.  If "!![" == "[" (Echo/Delayed expansion Must not be enabled prior to starting %~n0.bat & Pause & Exit /B 0)
  86. =============================================================================
  87. ::: CRITICAL RESOURCE DEFINITION AND VALIDATION
  88. =============================================================================
  89.  CHCP 65001 > nul
  90.  Set "MSG=Title ?"
  91.  %MSG:?= Verifying Resources ...%
  92. rem /* use wmic output with find to test if system is windows 10. Exit with notice if not */
  93.  wmic OS get OSArchitecture,caption | FIND "10" > nul || (ECHO/Windows 10 required for ascii escape codes & Exit /B)
  94. rem /* Define Escape character used for console virtual terminal sequences */
  95. rem - https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
  96.  for /F "delims=#" %%a in ('"prompt #$E# & for %%a in (1) do rem"') do set "\E=%%a"
  97. rem /* Define Getkey path wit /n no wait parameter */
  98.  For /F "Delims=" %%C in ('dir "%~dp0*GetKey.exe" /B /S') Do If not defined GetKey Set "GetKey="%%C" /n"
  99. rem /* Test getkey var is defined with valid exe path. Exit with notice if not. */
  100.  Echo/%GetKey%|findstr.exe /LIC:"GetKey.exe" > nul || (Echo/GetKey.Exe not found in Directory. Game cannot be played without GetKey.exe &Pause &Exit /B 0)
  101. rem /* Ensure prefix used for Collision detection array unnassigned */
  102.  (For /F "Tokens=1,2 Delims==" %%G in ('Set "}" 2^> Nul ')Do Set "%%~G=") 2> nul
  103. rem /* If TEMP path not found; Assign Current Directory as ~tmp file output folder */
  104.  If not exist "%TEMP%" (Set "Save.Dir=%~dp0")Else Set "Save.Dir=%TEMP%\"
  105. rem /* Test write permission in the assigned directory. Exit with notice if no write permission */
  106.  break >"%Save.Dir%%~n0_testpermission.com" || (
  107.   Echo/Write permission required in %Save.Dir% to continue
  108.   Pause
  109.   Exit /B
  110.  )
  111.  Set Background="%Save.Dir%%~n0_background.~tmp"
  112.  Set Foreground="%Save.Dir%%~n0_foreground.~tmp"
  113.  DEL %Foreground% 2> Nul
  114.  %= --------------------------------------------------------- =%
  115. ::: MACRO DEFINITIONS
  116. (Set LF=^
  117.  
  118.  
  119. %= Linefeed var. DO NOT MODIFY =%)
  120. (Set \n=^^^
  121.  
  122. %= Macro newline var. DO NOT MODIFY =%)
  123. (Set COMMENT=rem - ^^^
  124.  
  125. %= Macro Comment var. DO NOT MODIFY =%)
  126. =============================================================================
  127. ::: Screen Formatting and border definiton.
  128. rem /* Default Width for game control info panel */
  129.  Set "CNTRL.Width=20"
  130.  Set "}2;!CNTRL!=%\E%[2;!CNTRL!H%\E%[33mControls:"
  131.  Set "}3;!CNTRL!=%\E%[3;!CNTRL!H  ▲    - Up"
  132.  Set "}4;!CNTRL!=%\E%[4;!CNTRL!H  ◄    - Left"
  133.  Set "}5;!CNTRL!=%\E%[5;!CNTRL!H  ▼    - Down"
  134.  Set "}6;!CNTRL!=%\E%[6;!CNTRL!H  ►    - Right"
  135.  Set "}7;!CNTRL!=%\E%[7;!CNTRL!HSpace  - Pause"
  136.  Set "}8;!CNTRL!=%\E%[8;!CNTRL!HEscape - Quit"
  137. ::: Optional Macro providing Supplemental Information panel for game design debug purposes
  138.  Set "Debug.Sprite=< nul Set /P "=%\E%[14;!CNTRL!H%\E%[38;2;0;60;70mObj.Coll - !Obj.Coll! %\E%[15;!CNTRL!HObj.Capt - !Obj.Capt! %\E%[16;!CNTRL!HType - !Obj.Collide.Type! %\E%[17;!CNTRL!HGrounded - !Obj.On.Surface! %\E%[18;!CNTRL!H{lmu}X - !Obj.lX!;!Obj.mX!;!Obj.uX!    %\E%[19;!CNTRL!H{lmu}Y - !Obj.lY!;!Obj.mY!;!Obj.uY!    %\E%[20;!CNTRL!Hwidth - !Obj.width! %\E%[0m""
  139. ::: BACKGROUND.BORDER macro. Define border color;dimensions;character;collision state.
  140. ::: Resizes console; padding right of the border for Control display
  141. ::: Defines Critical Variables needed for .sprite + other macro's; using the arguments supplied
  142. ::: - Get screen Dimensions
  143.     For /f "delims=" %%# in  ('"wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution /format:value"') do (
  144.         Set "%%#">nul
  145.     )
  146. ::: - Get scale Factor in effect. Registry value requires restart to update if scale has changed.
  147.     For /F "Tokens=3 Delims= " %%A in ('REG QUERY "HKCU\Control Panel\Desktop\WindowMetrics" /V AppliedDPI') Do Set /A SF=%%A / 100 + 1
  148. ::: - Get Font Size
  149.     (For /F "Delims=" %%S in ('dir GetFontSize.exe /B /S') Do (%%S)) 2> Nul
  150.     Set /A "Font.H=%errorlevel% >> 16, Font.W=%errorlevel% & 0xFF"
  151. :::::::::: Calculate Max{Y;X} Constraints for Background.Border below
  152.     Set /A "Max{X}= ( CurrentHorizontalResolution / ( Font.W * SF ) )"
  153.     Set /A "Max{Y}= ( ( CurrentVerticalResolution / Font.H ) / SF ) - 4"
  154. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  155.  Set Background.Border=Set "Border=" ^& For %%n in (1 2)Do If %%n==2 ( %\n%
  156.   For /F "Tokens=1-7 Delims={}" %%G in ("!Border!")Do If not "%%~M" == "" ( %\n%
  157.    Set "Border.Color=%%~G" %\n%
  158.    Set ".Xmin=%%~H" %\n%
  159.    Set ".Xmax=%%~I" %\n%
  160.    Set ".Ymin=%%~J" %\n%
  161.    Set ".Ymax=%%~K" %\n%
  162.    Set ".Char=%%~L" %\n%
  163.    Set "?Border.Fatal=%%M" %\n%
  164.    Set /A "CNTRL=!.Xmax!+5,cols=!.Xmax!+CNTRL.Width+5,lines=!.Ymax!+2" 2^> nul %\n%
  165.    Set /A "Max{X}=Max{X}-(CNTRL.Width+5)" 2^> nul %\n%
  166.    For %%w in (%%~H %%~I)Do for /L %%h in (%%~J,1,%%~K)Do ( %\n%
  167.     Set "}%%h;%%w=%\E%[%%h;%%wH%\E%[%%~Gm!.Char!" %\n%
  168.     For %%i in (%%~J %%~K)Do If %%h Equ %%i ( %\n%
  169.      For /L %%W in (%%~H 1 %%~I)Do ( %\n%
  170.       Set "}%%h;%%W=%\E%[%%h;%%WH%\E%[%%~Gm!.Char!" %\n%
  171.   )))) %\n%
  172.   mode !Cols!,!lines! %\n%
  173.  )Else Set Border=
  174. =============================================================================
  175.  Set "UPDATE.Background=Set /A ".End=!.Ymax! + 1" & ((For /F "Tokens=2* Delims==" %%G in ('Set "}"')Do (< nul Set /P "=%%~G%\E%[0m") & < nul Set /P "=%\E%[!.END!;1H%\E%[0m%\E%[?25l")) >%Background% & Type %Background%"
  176. =============================================================================
  177. rem /* Game macro Script timing */
  178.  Set "Delay=If exist "%~dp0Components\Sleep.bat" ( Call "%~dp0Components\sleep.bat" # !time! )Else (For /L %%n in (1 1 10)Do ( Call :Delay 2> nul )))"
  179. =============================================================================
  180. ::: *** Key handling Macro's ***
  181. ::: Use Keytest_Game_Engine.Bat to Identify Ascii Integer values for the keys you wish to define
  182.  Set "Def.Key.Usage=%%Def.Key%%"Ascii.key.Integer=String" "Ascii.key.Integer=String" "Ascii.key.Integers=String""
  183.  Set "Def.Key=Set "input="&For %%n in (1 2)Do if %%n==2 (If "!input!" == "" (CLS & Mode 1000 & Echo/Echo/Error in Def.Key usage; Level !lvl!. Usage:!LF! !Def.Key.Usage! & Pause > nul & Endlocal & Exit )Else For %%I in (!input!)Do Set "k%%~I")Else Set input="
  184. ::: ?key# macro returns the string value of any key assigned using Def.Key when pressed in Variable: Key
  185.  Set "?Key#=For %%n in (1 2)Do if %%n==2 (For %%E in (!Errorlevel!) Do If not "!k%%E!" == "" (Set "Key=!k%%E!" & (If /I "!Key!" == "space" ( Pause > nul )) & (For %%d in (left right up down)Do If /I "!Key!" == "%%d" (Set "Obj.Dir=%%d")))Else If not "%%E" == "0" ( If /I "mode" == "dev" (TITLE Key Errorcode - %%E & Pause > nul )))Else Set Obj.prv.Dir="
  186.  Set "HASH=#"& Set "oHASH=Obj"
  187. =============================================================================
  188. ::: DEF.SPRITE : Converts Ascii art to objects [ a list ] with Defined Cordinates }Y;H=}Y;XHcharacter
  189.  Set Def.Sprite=For %%n in (1 2)Do if %%n==2 ( %\n%
  190.   Set "tMsg=Title Loading Level !lvl!" %\n%
  191.   !tMsg! %\n%
  192.   If Not "#" == "!HASH!" ( Set "{y}=#" ) %\n%
  193.   Set /A "{y}+=1 + 0" %\n%
  194.   For /F "Tokens=1,2,3 Delims={}" %%G in ("!Cells!")Do If not "%%~I" == "" ( %\n%
  195.    Set "cell=%%I" %\n%
  196.    Set "%%G.Color=%%~H" %\n%
  197.    For /L %%i in (2 1 !.Xmin!)Do Set "cell= !cell!" %\n%
  198.    For /L %%x in (0 1 !.Xmax!)Do If not "!cell:~%%x,1!" == "" ( %\n%
  199.     If not "!cell:~%%x,1!" == " " ( %\n%
  200.     Set "tMsg=!tMsg!." %\n%
  201.     !tMsg! %\n%
  202.     Set "tCell=!cell:~%%x,1!" %\n%
  203.     If not "!%%G!" == "" ( %\n%
  204.      For %%t in ("!tCell!")Do Set "t.%%G=!%%G:%%~t=!" %\n%
  205.      If "!t.%%G!" == "!%%G!" Set "%%G.C=!%%G.C! "!tCell!"" %\n%
  206.     ) Else (Set "Obj.C=!Obj.C! "!C.Tkn!"") %\n%
  207.      FOR /F "Delims=" %%X in ('Set /A "{x}=%%x+!.Xmin!+1"')Do ( %\n%
  208.       Set "}!{y}!;%%X=!{y}!;%%XH!cell:~%%x,1!" %\n%
  209.       Set "%%G=!%%G!"!{y}!;%%XH!cell:~%%x,1!"," %\n%
  210.    ))) %\n%
  211.    Set /A "%%G.lX=!.Xmax!,%%G.uX=!.Xmin!,%%G.lY=!.Ymax!,%%G.uY=!.Ymin!" %\n%
  212.    For %%S in (!%%G!)Do ( %\n%
  213.     For /F "tokens=1,2 Delims=;H" %%3 in ("%%~S") Do (%\n%
  214.      If %%3 GTR !%%G.uY! (Set "%%G.uY=%%3") %\n%
  215.      If %%3 LSS !%%G.lY! (Set "%%G.lY=%%3") %\n%
  216.      If %%4 GTR !%%G.uX! (Set "%%G.uX=%%4") %\n%
  217.      If %%4 LSS !%%G.lX! (Set "%%G.lX=%%4") %\n%
  218.     ) %\n%
  219.    ) %\n%
  220.    Set /A "%%G.mY=(!%%G.lY!+!%%G.uY!)/2,%%G.mX=(!%%G.lX!+!%%G.uX!)/2" %\n%
  221.    Set /A "%%G.Width=(!%%G.uX!-!%%G.lX!) + 1" %\n%
  222.   ) %\n%
  223.  )Else Set Cells=
  224. =============================================================================
  225. ::: Def.Multicol.Sprite : Converts list of strings to sprite Ascii art with Defined Cordinates }Y;H=}Y;XHVTCOLORCODEcharacter
  226. ::: Stores last supplied VTCOLORCODE to SPRITEVARNAME.Color
  227. ::: Defines Cell as }Y;X=Y;XH%\E%[VTCOLORCODEmCHARACTER
  228.  Set Def.Multicol.Sprite=For %%n in (1 2) Do if %%n==2 ( %\n%
  229.   Set "Obj=" %\n%
  230.   For %%G in (!Sprite.String!)Do ( %\n%
  231.    Set "c.Tkn=%%~G" %\n%
  232.    For /F "Tokens=1,2,3* Delims=;[H" %%1 in ("%%~G")Do ( %\n%
  233.     Set "Obj.Color=%%~G" %\n%
  234.     Set "c.Tkn=!Obj.Color:~-1!" %\n%
  235.     Set "Obj.Color=!Obj.Color:*H=!" %\n%
  236.     Set "Obj.Color=!Obj.Color:~0,-1!" %\n%
  237.     If not "!Obj.C!" == "" ( %\n%
  238.      For %%t in ("!c.Tkn!")Do Set "t.Obj=!Obj:%%~t=!" %\n%
  239.      If "!t.Obj!" == "!Obj!" Set "Obj.C=!Obj.C! "!C.Tkn!"" %\n%
  240.     ) Else (Set "Obj.C="!C.Tkn!"") %\n%
  241.     Set "}%%1;%%2=%%1;%%2H%\E%[!Obj.Color!m!C.Tkn!" %\n%
  242.     Set "Obj=!Obj!,"%%1;%%2H%\E%[!Obj.Color!m!C.Tkn!"" %\n%
  243.    ) %\n%
  244.   ) %\n%
  245.   Set /A "Obj.lX=!.Xmax!,Obj.uX=!.Xmin!,Obj.lY=!.Ymax!,Obj.uY=!.Ymin!" %\n%
  246.   For %%S in (!Obj!)Do ( %\n%
  247.    For /F "tokens=1,2 Delims=;H" %%3 in ("%%~S") Do (%\n%
  248.     If %%3 GTR !Obj.uY! (Set "Obj.uY=%%3") %\n%
  249.     If %%3 LSS !Obj.lY! (Set "Obj.lY=%%3") %\n%
  250.     If %%4 GTR !Obj.uX! (Set "Obj.uX=%%4") %\n%
  251.     If %%4 LSS !Obj.lX! (Set "Obj.lX=%%4") %\n%
  252.    ) %\n%
  253.   ) %\n%
  254.   Set /A "obj.mY=(!obj.lY!+!obj.uY!)/2,obj.mX=(!obj.lX!+!obj.uX!)/2" %\n%
  255.   Set /A "Obj.Width=!Obj.uX!-!Obj.lX!+1" %\n%
  256.  )Else Set Sprite.String=
  257. =============================================================================
  258. ::: SHOW : Iterates over the list value of a substituted sprite variable and outputs value.
  259. =============================================================================
  260. rem /* USAGE: %Show:obj=SpriteVARNAME% */ [ Displays spritenames cells ]
  261.  Set "Show=If /I "!oHASH!" == "Obj" (<nul Set /P "=%\E%[!.End!;1HError in level !lvl!. Unknown Sprite not displayed^^^!.!LF! Usage: %%Show:!oHASH!=SpriteVARNAME%%")Else For %%g in (!obj!)Do ((Set "oStr=%%~g") & < nul Set /P "=%\E%[!Obj.Color!m%\E%[!oStr!%\E%[0m")"
  262. rem /* Variables used to convert Direction to Vector in Move.Sprite Macro*/
  263. =============================================================================
  264. rem /* Inverse Player movements for lazy AI control */
  265.  Set ".Left=Right"&Set ".Right=Left"&Set ".Up=Down"&Set ".Down=Up"
  266. rem /* Clockwise rotation for use with rotate.sprite macro */
  267.  Set "rLeft=up"&Set "rRight=down"&Set "rUp=right"&Set "rDown=left"
  268.  Set "Left={x}{-}"& Set "Right={x}{+}"& Set "Up={y}{-}"& Set "Down={y}{+}"
  269.  Set "{x}{-}=Left"& Set "{x}{+}=Right"& Set "{y}{-}=Up"& Set "{y}{+}=Down"
  270.  Set Move.Sprite=For %%n in (1 2) Do if %%n==2 ( %\n%
  271.   Set "Sub=" %\n%
  272.   (For /F "Tokens=1 Delims==" %%l in ('Set Obj.Collide.Type')Do Set "%%l=") 2^> nul %\n%
  273.   Set /A "valid=1,Obj.capt=0,Obj.Coll=0" %\n%
  274.   For /F "Tokens=1,2,3,4 Delims={}" %%G in ("!Move.Args!")Do ( %\n%
  275.    Set "axis=%%~G" %\n%
  276.    Set "vector=%%~H" %\n%
  277.    Set "nDir=!{%%~G}{%%~H}!" %\n%
  278.    If not "%%~I" == "" (Set "Collide=%%I")Else ( Set "Collide=" ) %\n%
  279.    If not "%%~J" == "" (Set "Flag=%%J")Else ( Set "Flag=" ) %\n%
  280.   ) %\n%
  281.   If /I "!axis!" == "X" ( %\n%
  282.    For %%g in (!obj!) Do ( %\n%
  283.     For /F "Tokens=1,2,3 Delims=;H" %%i in ("%%~g") Do ( %\n%
  284.      Set /A "cx=%%j!vector!1,oy=%%i,ox=%%j" %\n%
  285.      Set "cTkn=%%~g" %\n%
  286.      Set "cTkn=!cTkn:*H=!" %\n%
  287.      For /F "Delims=" %%o in ("!cx!") Do ( %\n%
  288.       Set "q.cell=" %\n%
  289.       Set "q.cell=!}%%i;%%o!" %\n%
  290.       If not "!q.Cell!" == "" (Set "q.Cell=!q.cell:~-1!") %\n%
  291.       For /F "Delims=" %%K in ("!q.Cell!") Do ( %\n%
  292.        If not "!Collide:%%K=!" == "!Collide!" ( %\n%
  293.         Set "Valid=0" %\n%
  294.         Set /A "Obj.Coll+=1 + 0" %\n%
  295.         Set "Obj.Collide.Type[Col][!Obj.Coll!]=%%K" %\n%
  296.         Set "Obj.Collide.Type=%%~K" %\n%
  297.        ) %\n%
  298.        If "%%K" == "!.Char!" ( %\n%
  299.         Set "Valid=!?Border.Fatal!" %\n%
  300.         Set /A "Obj.Coll+=1 + 0" %\n%
  301.         Set "Obj.Collide.Type[Col][!Obj.Coll!]=%%K" %\n%
  302.         Set "Obj.Collide.Type=%%K" %\n%
  303.        ) %\n%
  304.        If not "!Flag:%%K=!" == "!Flag!" ( %\n%
  305.         If "!Valid!" == "1" ( %\n%
  306.          Set /A "Obj.Capt+=1 + 0" %\n%
  307.          Set "Obj.Collide.Type[Cap][!Obj.Capt!]=%%K" %\n%
  308.          Set "Obj.Collide.Type=%%K" %\n%
  309.         )Else ( %\n%
  310.          Set "Obj.Capt=0" %\n%
  311.          (For /F "tokens=1,2 Delims==" %%1 in ('Set Obj.Collide.Type[Cap]')Do Set "%%1=") 2^> nul %\n%
  312.         ) %\n%
  313.        ) %\n%
  314.       ) %\n%
  315.       If "!valid!" == "1" (Set "Sub=!Sub!"%%i;%%oH!cTKN!",") %\n%
  316.    )))) ELSE ( %\n%
  317.    For %%g in (!obj!) Do ( %\n%
  318.     For /F "Tokens=1,2,3 Delims=;H" %%i in ("%%~g") Do ( %\n%
  319.      Set /A "cy=%%i!vector!1,oy=%%i,ox=%%j" %\n%
  320.      Set "cTkn=%%~g" %\n%
  321.      Set "cTkn=!cTkn:*H=!" %\n%
  322.      For /F "Delims=" %%o in ("!cy!") Do ( %\n%
  323.       Set "q.cell=" %\n%
  324.       Set "q.cell=!}%%o;%%j!" %\n%
  325.       If not "!q.Cell!" == "" (Set "q.Cell=!q.cell:~-1!") %\n%
  326.       For /F "Delims=" %%K in ("!q.Cell!") Do ( %\n%
  327.        If not "!Collide:%%K=!" == "!Collide!" ( %\n%
  328.         Set "Valid=0" %\n%
  329.         Set /A "Obj.Coll+=1 + 0" %\n%
  330.         Set "Obj.Collide.Type[Col][!Obj.Coll!]=%%K" %\n%
  331.         Set "Obj.Collide.Type=%%~K" %\n%
  332.        ) %\n%
  333.        If "%%K" == "!.Char!" ( %\n%
  334.         Set "Valid=!?Border.Fatal!" %\n%
  335.         Set /A "Obj.Coll+=1 + 0" %\n%
  336.         Set "Obj.Collide.Type[Col][!Obj.Coll!]=%%K" %\n%
  337.         Set "Obj.Collide.Type=%%K" %\n%
  338.        ) %\n%
  339.        If not "!Flag:%%K=!" == "!Flag!" ( %\n%
  340.         If "!Valid!" == "1" ( %\n%
  341.          Set /A "Obj.Capt+=1 + 0" %\n%
  342.          Set "Obj.Collide.Type[Cap][!Obj.Capt!]=%%K" %\n%
  343.          Set "Obj.Collide.Type=%%K" %\n%
  344.         )Else ( %\n%
  345.          Set "Obj.Capt=0" %\n%
  346.          (For /F "tokens=1,2 Delims==" %%1 in ('Set Obj.Collide.Type[Cap]')Do Set "%%1=") 2^> nul %\n%
  347.         ) %\n%
  348.        ) %\n%
  349.       ) %\n%
  350.       If "!valid!" == "1" (Set "Sub=!Sub!"%%o;%%jH!cTKN!",") %\n%
  351.   ))))%\n%
  352.   If "!valid!" == "1" (%\n%
  353.    Set /A "Obj.lX=!.Xmax!,Obj.uX=!.Xmin!,Obj.lY=!.Ymax!,Obj.uY=!.Ymin!" %\n%
  354.    (For %%Q in (!obj!)Do ( %\n%
  355.     For /F "tokens=1,2 Delims=;H" %%1 in ("%%~Q") Do (%\n%
  356.      Set "}%%~1;%%~2=" %\n%
  357.      Echo/%\E%[%%1;%%2H %\n%
  358.    )))^>%Foreground% %\n%
  359.    Set "Obj.on.surface=0" %\n%
  360.    Set "Obj.Surface=" %\n%
  361.    Set "obj.on.fatal=" %\n%
  362.    Set "Obj.Base.I=0" %\n%
  363.    (For %%S in (!Sub!)Do ( %\n%
  364.     For /F "tokens=1,2,3* Delims=;H" %%3 in ("%%~S") Do (%\n%
  365.      If %%3 GTR !Obj.uY! (Set "Obj.uY=%%3") %\n%
  366.      If %%3 LSS !Obj.lY! (Set "Obj.lY=%%3") %\n%
  367.      If %%4 GTR !Obj.uX! (Set "Obj.uX=%%4") %\n%
  368.      If %%4 LSS !Obj.lX! (Set "Obj.lX=%%4") %\n%
  369.      Set "cTKN=%%~S" %\n%
  370.      Set "cTKN=!cTKN:*H=!" %\n%
  371.      Set "}%%~3;%%~4=%%~3;%%~4H!cTKN!" %\n%
  372.      Echo/%\E%[%%~3;%%~4H%\E%[!Obj.Color!m!cTKN!%\E%[0m%\n%
  373.    ))) ^>^>%Foreground% %\n%
  374.    Set /A Below.Sprite=!Obj.uY!+1 %\n%
  375.    For %%k in (!Obj.uY!)Do For /L %%a in (!Obj.lX! 1 !Obj.uX!)Do If not "!}%%k;%%a!" == "" ( %\n%
  376.     For %%b in (!Below.Sprite!)Do For %%c in (!.Char! !Collide! !Flag!)Do ( %\n%
  377.      If /I "!}%%b;%%a:~-1!" == "%%~c" ( %\n%
  378.       Set "Obj.on.surface=1" %\n%
  379.       %COMMENT:{i}= All cells sprite rests on returned in list var below. Use list to differentiate surface types - IE ground ; lava ; water \n%
  380.       Set "Obj.surface=!Obj.surface!"!}%%b;%%a!"," %\n%
  381.       %!!%
  382.       If "!fatal.%%c!" == "1" (Set /A "obj.on.fatal+=1 + 0") %\n%
  383.      ) %\n%
  384.      Set /A "Obj.Base.I+=1" %\n%
  385.     ) %\n%
  386.    ) %\n%
  387.    If "!Obj.on.Fatal!" == "!Obj.Base.I!" (Set "obj.State=dead") %\n%
  388.    TYPE %Foreground% %\n%
  389.    If not "!Obj.Collide.Type!" == "!.Char!" Set "obj=!Sub!" %\n%
  390.    Set /A "obj.mY=(!obj.lY!+!obj.uY!)/2,obj.mX=(!obj.lX!+!obj.uX!)/2" %\n%
  391.    Set "Obj.Dir=!nDir!" %\n%
  392.   ) %\n%
  393.  )Else Set Move.Args=
  394. =============================================================================
  395. ::: Rotate.Sprite Macro - rotates a sprite cells and direction clockwise
  396.  Set Rotate.Sprite=For %%n in (1 2) Do if %%n==2 ( %\n%
  397.   (For %%s in ("cTkn" "ny" "nx" "oy" "ox" "iy" "ix" "Obj.Collide.Type") Do For /F "Tokens=1,2 Delims==" %%G in ('Set "%%~s"')Do Set "%%~G=") 2^> nul %\n%
  398.   Set "Sub=" %\n%
  399.   Set /A "midX=500,midY=500,{I}=0,rValid=1,Obj.Coll=0,Obj.capt=0" %\n%
  400.   For %%g in (!obj!) Do If not "%%~g" == "" ( %\n%
  401.    Set /A "{I}+=1 + 0" %\n%
  402.    For /F "Tokens=1,2,3* Delims=;H" %%I in ("%%~g") Do ( %\n%
  403.     Set /A "iy!{I}!=%%~I" %\n%
  404.     Set /A "ix!{I}!=%%~J" %\n%
  405.     Set "cTKN!{I}!=%%~g" %\n%
  406.     For %%z in (!{I}!)Do Set "cTKN!{I}!=!cTKN%%z:*H=!" %\n%
  407.    ) %\n%
  408.   ) %\n%
  409.   For /L %%i in (1 1 !{I}!) do For %%A in ("!iy%%i!;!ix%%i!")Do ( %\n%
  410.    For /F "Tokens=1,2 Delims=;" %%X in ("%%~A") Do ( %\n%
  411.     Set /A "oY=%%~X" %\n%
  412.     Set /A "oX=%%~Y" %\n%
  413.    ) %\n%
  414.    If !oY! LSS !midY! Set /A "midY=!oY!" %\n%
  415.    If !oX! LSS !midX! Set /A "midX=!oX!" %\n%
  416.   ) %\n%
  417.   Set "pixel=0" %\n%
  418.   For /L %%i in (1 1 !{I}!) do For %%B in ("!iy%%i!;!ix%%i!")Do ( %\n%
  419.    Set /A "pixel+=1" %\n%
  420.    For /F "Tokens=1,2 Delims=;" %%r in ("%%~B") Do ( %\n%
  421.     Set /A "ny!pixel!=(%%~s-!midX!)+!midY!,nx!pixel!=(%%~r-!midY!)+!midX!" %\n%
  422.    ) %\n%
  423.   ) %\n%
  424.   Set "pixel=0" %\n%
  425.   Set /A "lmidX=500,umidX=0" %\n%
  426.   For /L %%i in (1 1 !{I}!) do For %%C in (!nx%%i!) Do ( %\n%
  427.    If %%C LSS !lmidX! (Set /A "lmidX=%%C") %\n%
  428.    If %%C GTR !umidX! (Set /A "umidX=%%C") %\n%
  429.   ) %\n%
  430.   Set /A "Obj.Width=!umidX!-!lmidX!" %\n%
  431.   For /L %%i in (1 2 19)Do If !Obj.Width! EQU %%i Set "Centre=0" %\n%
  432.   For /L %%i in (0 2 20)Do If !Obj.Width! EQU %%i Set "Centre=1" %\n%
  433.   Set /A "Obj.Width+=1" %\n%
  434.   if !umidX!==!lmidX! Set "Centre=0" %\n%
  435.   Set /A "Mid.X=( !lmidX! + !umidX! ) / 2" %\n%
  436.   For /L %%i in (1 1 !{I}!) do For %%X in (!nx%%i!) Do ( %\n%
  437.    Set /A "pixel=!pixel! + 1" %\n%
  438.    Set /A "nx!pixel!=%%X + !centre!" %\n%
  439.    IF %%X LSS !Mid.X! (Set /A "nx!pixel!= %%X + ((!Mid.X!-%%X) * 2) + !centre!") %\n%
  440.    IF %%X GTR !Mid.X! (Set /A "nx!pixel!= %%X - ((%%X-!Mid.X!) * 2) + !centre!") %\n%
  441.   ) %\n%
  442.   For /F "Tokens=1,2,3,4 Delims={}" %%o in ("!rVector!") Do ( %\n%
  443.    Set "cDir=%%o" %\n%
  444.    Set "Flag=%%q" %\n%
  445.   ) %\n%
  446.   For /L %%i in (1 1 !{I}!)Do ( %\n%
  447.    for %%c in ("!ny%%i!;!nx%%i!")Do If not "!}%%~c!" == "" ( %\n%
  448.     For /F "Tokens=2 Delims={}" %%m in ("!rVector!")Do Set "Collide=%%m" %\n%
  449.     For %%v in (!Collide!) Do If not "!}%%~c!" == "" ( %\n%
  450.      Set "KO=!}%%~c:%%~v=!" %\n%
  451.      If Not "!}%%~c!" == "!KO!" (%\n%
  452.       Set "rValid=0" %\n%
  453.       Set "Obj.Collide.Type=%%~v" %\n%
  454.       Set /A "Obj.Coll+=1" %\n%
  455.       Set "Obj.Collide.Type[Col][!Obj.Coll!]=%%~v" %\n%
  456.      ) %\n%
  457.     ) %\n%
  458.    ) %\n%
  459.   ) %\n%
  460.   If "!rValid!" == "1" ( %\n%
  461.    Set "Obj.Dir=!cDir!"%\n%
  462.    For /L %%i in (1 1 !{I}!) do ( %\n%
  463.     Set "Sub=!Sub!"!ny%%i!;!nx%%i!H!cTkn%%i!"," %\n%
  464.     For %%P in (!Flag!)Do for %%v in ("!ny%%i!;!nx%%i!")Do If Not "!}%%~v!" == "" ( %\n%
  465.      Set "flag.C=!}%%~v:%%~P=!" %\n%
  466.      Set "flag.Cell=!}%%~v!" %\n%
  467.      If Not "!flag.Cell!" == "!flag.C!" ( %\n%
  468.       Set /A "Obj.capt+=1 + 0" %\n%
  469.       Set "Obj.Collide.Type=!cTkn%%i:~-1!" %\n%
  470.       Set "Obj.Collide.Type[Cap][!Obj.capt!]=!cTkn%%i:~-1!" %\n%
  471.      ) %\n%
  472.     ) %\n%
  473.    ) %\n%
  474.    (For %%Q in (!obj!)Do ( %\n%
  475.     For /F "tokens=1,2 Delims=;H" %%1 in ("%%~Q") Do (%\n%
  476.      Set "}%%1;%%2=" %\n%
  477.      Echo/%\E%[%%1;%%2H %\n%
  478.    )))^>%Foreground% %\n%
  479.    Set "Obj.on.surface=0" %\n%
  480.    Set "Obj.Surface=" %\n%
  481.    Set "obj.on.fatal=" %\n%
  482.    Set "obj.Base.I=" %\n%
  483.    (For %%S in (!Sub!)Do ( %\n%
  484.     For /F "tokens=1,2,3 Delims=;H" %%3 in ("%%~S") Do (%\n%
  485.      Set "cTKN=%%~S" %\n%
  486.      Set "cTKN=!cTKN:*H=!" %\n%
  487.      Set "}%%3;%%4=%%3%!!%%4H!cTKN!" %\n%
  488.      Echo/%\E%[%%3;%%4H%\E%[!Obj.Color!m!cTKN!%\E%[0m%\n%
  489.    ))) ^>^>%Foreground% %\n%
  490.    TYPE %Foreground% %\n%
  491.    Set /A Below.Sprite=!Obj.uY!+1 %\n%
  492.    For %%k in (!Obj.uY!)Do For /L %%a in (!Obj.lX! 1 !Obj.uX!)Do If not "!}%%k;%%a!" == "" ( %\n%
  493.     For %%b in (!Below.Sprite!)Do For %%c in (!.Char! !Collide! !Flag!)Do ( %\n%
  494.      If /I "!}%%b;%%a:~-1!" == "%%~c" ( %\n%
  495.       Set "Obj.on.surface=1" %\n%
  496.       Set "Obj.surface=!Obj.surface!"!}%%b;%%a!"," %\n%
  497.       If "!fatal.%%c!" == "1" (Set /A "obj.on.fatal+=1 + 0") %\n%
  498.      ) %\n%
  499.      Set /A "Obj.Base.I+=1" %\n%
  500.     ) %\n%
  501.    ) %\n%
  502.    If "!Obj.on.Fatal!" == "!Obj.Base.I!" (Set "obj.State=dead") %\n%
  503.    Set "obj=!Sub!" %\n%
  504.    Set "Sub=" %\n%
  505.   ) %\n%
  506.  )Else Set rVector=
  507. ========================================================================================================
  508. ::: Macro's for using the Music system included in the Games_By_T3RRY archive
  509.  Set "Play.Music=If Exist "%~dp0Components\PlayMusic.bat" For %%n in (1 2)Do if %%n==2 (For /F "Tokens=1,2,3 Delims={}" %%G in ("!Music.Args!")Do (Call "%~dp0Components\PlayMusic.bat" "%%~G" %%H %%I ))else Set Music.Args="
  510.  Set "Stop.Music=If Exist "%~dp0Components\StopMusic.bat" (Call "%~dp0Components\StopMusic.Bat" running 2> nul )"
  511.  Set "Monitor.Game=Call "%~dp0Components\Gamemonitor.bat" start 2> nul"
  512. Exit /B 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement