Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo off
- REM IMPORTANT - script updated for windows 11 compatability.
- ::::::::::::::::::: DO NOT move OR rename OR modify THIS FILE. Filename: Game_EngineDEBUG.bat
- ::: [ * Author: T3RRY * ] Creation Date - 16/12/2020 Developer version
- ::: Border and Sprite Macro definition package for Batch Arcade games
- ::: Purpose: Create a system to convert ASCII Art into sprites that can be moved and interacted with.
- ============================
- ::: COMPLETE archive with the latest updates:
- ::: Games_by_T3RRY: https://drive.google.com/file/d/1cAQLd-f9HN6SuWowBUETccKCZd2dVbWj/view?usp=sharing
- ::: See a DEMO using this engine:
- ::: https://www.youtube.com/watch?v=Wi3izdqbwcw
- ::: Leave a comment if you have any ideas or requests, Share a link if you want to show off your own games.
- ============================
- ::: Additional Accreditation
- ::: Getkey.Exe by Antonio {https://stackoverflow.com/users/778560/aacini}
- ::: * REQUIRED * for Extended key controls.
- ::: Getfontsize.Exe by Antonio {https://stackoverflow.com/users/778560/aacini}
- ::: From: https://stackoverflow.com/a/62087328/12343998
- ::: * REQUIRED * to accurately determine the consoles maximum Y;X values
- ::::::::::::::::::::::::::::
- ::: Sleep.bat by Dave Benham { https://stackoverflow.com/users/1012053/dbenham }
- ::: - Not required; allows for more precise sub second delays than other methods.
- =============================================================================
- ::: Recommended Resources:
- ::: Batch Macro's with Arguments Appended:
- ::: https://www.dostips.com/forum/viewtopic.php?f=3&t=2518
- ::: VT sequence Information:
- ::: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
- ::: 255 bit color chart [ for VT color sequences ]
- ::: https://www.rapidtables.com/web/color/RGB_Color.html
- =============================================================================
- ::: *** Important notes ***
- ::: Game_Engine.bat & Game_EngineDEBUG.bat Macro's:
- ::: - Enable definition; movement; rotation and collision / capture testing of ASCII sprites
- ::: Dev Toolkit - Refer to Game_EngineDEBUG.bat
- ::: - Contains advanced usage information ; performs error testing when Game_EngineDEBUG.bat defines Macros.
- ::: Defines Macro Resources required to run .Bat arcade Games_by_T3RRY
- ::: Game_Engine Macro's act as a whole system; and as such have dependencies on other macro's in the system
- ::: - Background.Border macro should ALWAYS be the first macro expanded; As it defines variables that
- ::: constrain the dimension of the playfield used by all other Sprite macros.
- ::: - Def.Sprite or Def.MultiCol.Sprite must be used to define sprites prior to Move.Sprite or Rotate.Sprite
- ::: being used
- =============================================================================
- :::::::::: Version 2.1 22/01/2022
- ::: Updated for Windows 11 users
- :::::::::: Version 2.0 01/01/2021
- ::: Changes Jan 2021
- ::: *** Updated all .Sprite macros to support definition of sprite cells ***
- ::: using 255 bit Color codes. Ie: 38;2;200;25;100
- ::: Updated Def.Sprite and Def.Multicol.Sprite to define Obj.{l|m|u}{X|Y} variables
- ::: /* Changed Collide.Type Return Var to Obj.Collide.Type /*
- ::: - Object specific prefix allows more sophisticated testing of the collision types that have occured during a game "turn"
- ::: - enables more game design options like pushable sprites.
- ::: - Each sprite now has it's own array for captured / collided cells that can be tested
- :::: WHERE obj = SPRITEVARNAME
- ::: - Array Variables: index var: Array Name: Value:
- ::: Collision: Obj.Coll Obj.Collide.Type[Col][#=index] Collision Character
- ::: Capture : Obj.Capt Obj.Collide.Type[Cap][#=index] Capture Character
- ::: ** Obj.Coll and Obj.Capt return the total number of collisions and captures Obj=SPRITEVARNAME has had after a move.
- ::: - Added Getfontsize.exe to archive and calculation of true max console Dimensions.
- ::: - Expanded Error Testing and Debug output
- ::: - Cloned Game_Engine into Debug and Prodution versions
- ::: - Finished games can obtain a performance advantage by using the production version.
- :::::::::: Version 1.8 28/12/2020
- ::: Renamed to Game_Engine.bat
- ::: Version Changes 28/12/2020:
- ::: Added Play.Music and Stop.Music macro's to
- ::: Added Obj.Collide.Type return var to simplify testing of collision type that has occured within move.sprite macro
- ::: Added calculation of Sprite Mid{y;x} values to allow determination of sprite center
- ::: - Useful for calculating movement directions relevent to other sprites
- ::: - return vars: Obj.mx Obj.my [ Obj substituted with SPRITEVARNAME during Move.Sprite expansion ]
- ::: - Added SnakeSprite.bat to library to demonstrate how to apply sprite chase using these values
- :::::::::::::::::::::::::::::::
- ::: Version Changes 23/12/2020:
- ::: Added Rotate.Sprite Macro
- ::: Added Usage tests and output to Background.Border Def.Sprite Show.Sprite and Move.Sprite Macro's
- :::::::::::::::::::::::::::::::
- ::: Version Changes 19/12/2020:
- ::: Removed Response handling of collision from Move.Sprite macro
- ::: Upgraded move.sprite macro to accept arguments for Collision or Capture Characters
- ::: - return Vars [Collision is True: Valid=0] [Capture is True: Obj.capt=1]
- ::: - Implemented Title based level load indicator during sprite definition
- ::: - Improved modelling of handling game exit / End of level cleanup.
- ::: - Added 7th arg to Background.Border macro for flagging Border collision as Fatal T[0]/F[-1]
- :::::::::::::::
- rem /* Establish and verify required resources. */
- rem /* Game_engine built for use with Getkey.exe ; tests for getkey.exe in subfolders and */
- rem /* Quits if not found ; else ensures folder containing Getkey.exe is named 'Components' */
- If not Exist "%~dp0Components" (
- Setlocal EnableDelayedExpansion
- For /F "Delims=" %%G in (' dir "%~dp0*GetKey.exe" /B /S 2^> nul ')Do Set "MyPath=%%~G"
- If "!MyPath!" == "" (Echo/Critical resources missing^^^!&Endlocal & Pause & Exit)
- Set "MyPath=!MyPath:\=;!"
- Set "MyPath=!MyPath: =[space]!"
- For %%G in (!Mypath!)Do If /I not "%%~G" == "GetKey.exe" Call Set "DirPath=%%G"
- Set "DirPath=!DirPath:[space]= !"
- Ren "!DirPath!" Components
- Endlocal
- )
- rem /* Test Environment is suitable for definition of Macro's */
- If "!![" == "[" (Echo/Delayed expansion Must not be enabled prior to starting %~n0.bat & Pause & Exit /B 0)
- =============================================================================
- ::: CRITICAL RESOURCE DEFINITION AND VALIDATION
- =============================================================================
- CHCP 65001 > nul
- rem /* Titlebar macro */
- Set "MSG=Title ?"
- %MSG:?= Verifying Resources ...%
- rem /* Define Escape character used for console virtual terminal sequences */
- rem - https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
- for /F "delims=" %%e in ('Echo(Prompt $E^|cmd') do set "\E=%%e"
- Call:TestVT || (
- Echo(Vitual terminal sequences not enabled on your system
- Exit /b 1
- )
- rem /* Define Getkey path wit /n no wait parameter */
- For /F "Delims=" %%C in ('dir "%~dp0*GetKey.exe" /B /S') Do If not defined GetKey Set "GetKey="%%C" /n"
- rem /* Test getkey var is defined with valid exe path. Exit with notice if not. */
- 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)
- rem /* Ensure prefix used for Collision detection array unnassigned */
- (For /F "Tokens=1,2 Delims==" %%G in ('Set "}" 2^> Nul ')Do Set "%%~G=") 2> nul
- rem /* If TEMP path not found; Assign Current Directory as ~tmp file output folder */
- If not exist "%TEMP%" (Set "Save.Dir=%~dp0")Else Set "Save.Dir=%TEMP%\"
- rem /* Test write permission in the assigned directory. Exit with notice if no write permission */
- break >"%Save.Dir%%~n0_testpermission.tst" || (
- Echo/Write permission required in %Save.Dir% to continue
- Pause
- Exit /B
- )
- Set Background="%Save.Dir%%~n0_background.~tmp"
- Set Foreground="%Save.Dir%%~n0_foreground.~tmp"
- DEL %Foreground% 2> Nul
- %= --------------------------------------------------------- =%
- ::: MACRO DEFINITIONS
- (Set LF=^
- %= Linefeed var. DO NOT MODIFY =%)
- (Set \n=^^^
- %= Macro newline var. DO NOT MODIFY =%)
- ::: COMMENT macro expands to rem - \n
- ::: allowing for remarks in multiline variables
- ::: Expanded using substring modification with an absent string to ensure comments aren't defined into the macro.
- (Set COMMENT=rem - ^^^
- %= Macro Comment var. DO NOT MODIFY =%)
- =============================================================================
- ::: Screen Formatting and border definiton.
- rem /* Default Width for game control info panel */
- If Not "%~2" == "/N" (
- Set "CNTRL.Width=20"
- Set "}2;!CNTRL!=%\E%[2;!CNTRL!H%\E%[33mControls:"
- Set "}3;!CNTRL!=%\E%[3;!CNTRL!H ▲ - Up"
- Set "}4;!CNTRL!=%\E%[4;!CNTRL!H ◄ - Left"
- Set "}5;!CNTRL!=%\E%[5;!CNTRL!H ▼ - Down"
- Set "}6;!CNTRL!=%\E%[6;!CNTRL!H ► - Right"
- Set "}7;!CNTRL!=%\E%[7;!CNTRL!HSpace - Pause"
- Set "}8;!CNTRL!=%\E%[8;!CNTRL!HEscape - Quit"
- ) Else ( If not "%~3" == "" ( Set /A "CNTRL.Width=%~3" 2> nul ) Else ( Set "CNTRL.Width=20" ))
- ::: Optional Macro providing Supplemental Information panel for game design debug purposes
- 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""
- ::: BACKGROUND.BORDER macro. Define border color;dimensions;character;collision state.
- ::: Resizes console; padding right of the border for Control display
- ::: Defines Critical Variables needed for .sprite + other macro's; using the arguments supplied
- Set "Border.Usage=%%Background.Border:CNTRL.Width=INTEGER%%{VTcolorcode}{.Xmin}{.Xmax}{.Ymin}{.Ymax}{BorderCharacter}{0|-1}"
- Set "error=Echo/Error in level !lvl!.!LF! Arg # for %%Background.Border%%!Border!!LF! Invalid:"
- ::: ***************************************************************
- ::: - Get screen Dimensions
- For /f "delims=" %%# in ('"wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution /format:value"') do (
- Set "%%#">nul
- )
- ::: - Get scale Factor in effect. Registry value requires restart to update if scale has changed.
- For /F "Tokens=3 Delims= " %%A in ('REG QUERY "HKCU\Control Panel\Desktop\WindowMetrics" /V AppliedDPI') Do Set /A SF=%%A / 100 + 1
- ::: - Get Font Size
- (For /F "Delims=" %%S in ('dir GetFontSize.exe /B /S') Do (%%S)) 2> Nul
- Set /A "Font.H=%errorlevel% >> 16, Font.W=%errorlevel% & 0xFF"
- :::::::::: Calculate Max{Y;X} Constraints for Background.Border below
- Set /A "Max{X}= ( CurrentHorizontalResolution / ( Font.W * SF ) )"
- Set /A "Max{Y}= ( ( CurrentVerticalResolution / Font.H ) / SF ) - 4"
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- Set Background.Border=Set "Border=" ^& For %%n in (1 2)Do If %%n==2 ( %\n%
- If "!Border!" == "" ( %\n%
- Mode 1000 %\n%
- Echo/Error in Level !lvl! !LF! Missing Args for: !LF! %%Background.Border%%!Border!!LF! Background.Border USAGE: %\n%
- Echo/!Border.Usage! %\n%
- Pause ^& Endlocal ^& Exit /B 0%\n%
- ) %\n%
- For /F "Tokens=1-7 Delims={}" %%G in ("!Border!")Do If not "%%~M" == "" ( %\n%
- %COMMENT: {i}= Background.Border RETURN VARIABLES \n%
- Set "Border.Color=%%~G" %\n%
- Set ".Xmin=%%~H" %\n%
- Set ".Xmax=%%~I" %\n%
- Set ".Ymin=%%~J" %\n%
- Set ".Ymax=%%~K" %\n%
- Set ".Char=%%~L" %\n%
- Set "?Border.Fatal=%%M" %\n%
- Set /A "CNTRL=!.Xmax!+5,cols=!.Xmax!+CNTRL.Width+5,lines=!.Ymax!+2" 2^> nul %\n%
- Set /A "Max{X}=Max{X}-(CNTRL.Width+5)" 2^> nul %\n%
- Echo/!Border.Color!^| Findstr.exe /RX "[1234567890;]*" ^> nul %\n%
- If Not !Errorlevel!==0 ( %error:#=1% {%%~G} - Accepted - Integer or Integer;Integer ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- Echo/!.Xmin!^| Findstr.exe /RX "[1234567890]*" ^> nul %\n%
- If Not !Errorlevel!==0 ( %error:#=1% {%%~H} - Accepted - Integer GEQ 1 LSS !Max{X}! ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- Echo/!.Xmax!^| Findstr.exe /RX "[1234567890]*" ^> nul %\n%
- If Not !Errorlevel!==0 ( %error:#=1% {%%~I} - Accepted - Integer GEQ 1 LEQ !Max{X}! ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- Echo/!.Ymin!^| Findstr.exe /RX "[1234567890]*" ^> nul %\n%
- If Not !Errorlevel!==0 ( %error:#=1% {%%~J} - Accepted - Integer GEQ 1 LSS !Max{Y}! ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- Echo/!.Ymax!^| Findstr.exe /RX "[1234567890]*" ^> nul %\n%
- If Not !Errorlevel!==0 ( %error:#=1% {%%~K} - Accepted - Integer GEQ 1 LEQ !Max{Y}! ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- If !.Xmin! LEQ 0 ( %error:#=2% {%%~H} - Accepted - Integer GEQ 1 ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- If !.Xmax! GTR !Max{X}! ( %error:#=3% {%%~I} - Accepted - Integer GTR 1 LEQ !Max{X}! ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- If !.Ymin! LEQ 0 ( %error:#=4% {%%~J} - Accepted - Integer GEQ 1 ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- If !.Ymax! GTR !Max{Y}! ( %error:#=5% {%%~K} - Accepted - Integer GTR 1 LEQ !Max{Y}! ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- If Not "!.Char:~1,1!" == "" (%error:#=6% {%%~L} - Accepted - Singular ASCII character ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- If !?Border.Fatal! GTR 0 ( %error:#=7% {%%~M} - Accepted - "0" or "-1" ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- If !?Border.Fatal! LSS -1 ( %error:#=7% {%%~M} - Accepted - "0" or "-1" ^& Pause ^> nul ^& Exit /B ) %\n%
- For %%w in (%%~H %%~I)Do for /L %%h in (%%~J,1,%%~K)Do ( %\n%
- Set "}%%h;%%w=%\E%[%%h;%%wH%\E%[%%~Gm!.Char!" %\n%
- For %%i in (%%~J %%~K)Do If %%h Equ %%i ( %\n%
- For /L %%W in (%%~H 1 %%~I)Do ( %\n%
- Set "}%%h;%%W=%\E%[%%h;%%WH%\E%[%%~Gm!.Char!" %\n%
- ))))Else ( %\n%
- Mode 1000 %\n%
- Echo/Error in Level !lvl! !LF! Missing Args for: !LF! %%Background.Border%%!Border!!LF! Background.Border USAGE: %\n%
- Echo/!Border.Usage! %\n%
- Pause ^& Endlocal ^& Exit /B 0%\n%
- ) %\n%
- %!!%
- mode !Cols!,!lines! %\n%
- )Else Set Border=
- =============================================================================
- 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% > Con"
- =============================================================================
- rem /* Game macro Script timing */
- Set "Delay.Usage=%%Delay:#=Integer%%"
- Set "Delay=If not "#" == "!HASH!" (If exist "%~dp0Components\Sleep.bat" ( Call "%~dp0Components\sleep.bat" # !time! )Else (For /L %%n in (1 1 10)Do ( Call :Delay 2> nul )))Else (Echo/Error in Delay macro - level !lvl!.!LF! Usage: !Delay.Usage!& Pause & Endlocal & Exit)"
- =============================================================================
- ::: *** Key handling Macro's ***
- ::: Use Keytest_Game_Engine.Bat to Identify Ascii Integer values for the keys you wish to define
- Set "Def.Key.Usage=%%Def.Key%%"Ascii.key.Integer=String" "Ascii.key.Integer=String" "Ascii.key.Integers=String""
- 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="
- ::: ?key# macro returns the string value of any key assigned using Def.Key when pressed in Variable: Key
- 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="
- ::: Hash vars used to test / confirm Substring modification is used where needed.
- Set "HASH=#"
- Set "oHASH=Obj"
- =============================================================================
- ::: DEF.SPRITE : Converts Ascii art to objects [ a list ] with Defined Cordinates }Y;H=}Y;XHcharacter
- ::: Stores Arg 2 Vt Color Code to [Arg 1] SPRITEVARNAME.Color variable for use in Move.Sprite and Rotate.Sprite
- Set "Def.Sprite.Usage=%%Def.Sprite:#=lineYpos%%{SPRITEVARNAME}{VTCOLORCODE}{characters for x positions of substituted Y line}"
- :::::::::::::::::::::::::::::::::::::::::::::::::::
- Set Def.Sprite=For %%n in (1 2)Do if %%n==2 ( %\n%
- If "!Cells!" == "" ( %\n%
- CLS ^& Mode 1000 %\n%
- Echo/Error in Level !lvl!!LF!Missing Args for -!LF!%%Def.Sprite%%!Cells!!LF! Def.Sprite USAGE: %\n%
- Echo/!Def.Sprite.Usage!!LF!%%Def.Sprite%%{SPRITEVARNAME}{VTCOLORCODE}{characters for x positions of next Y line}%\n%
- Pause ^& Endlocal ^& Exit /B 0%\n%
- ) %\n%
- Set "tMsg=Title Loading Level !lvl!" %\n%
- !tMsg! %\n%
- If Not "#" == "!HASH!" ( Set "{y}=#" ) %\n%
- Set /A "{y}+=1 + 0" %\n%
- If !{y}! LEQ !.Ymin! (CLS ^& Mode 1000 ^& Echo/Error in Def.Sprite - Level !lvl!!LF!Y Value - [!{y}!] Outside Border Boundary .YMin - [!.Ymin!]!LF! %%Def.Sprite%%!Cells!!LF!%%Background.Border%%!Border!!LF! Def.Sprite Usage:!LF!Echo/!Def.Sprite.Usage! ^& Pause ^& Endlocal ^& Exit /B 0) %\n%
- If !{y}! GEQ !.Ymax! (CLS ^& Mode 1000 ^& Echo/Error in Def.Sprite - Level !lvl!!LF!Y Value - [!{y}!] Exceeds Border Boundary .Ymax - [!.Ymax!]!LF! %%Def.Sprite%%!Cells!!LF!%%Background.border%%!Border! ^& Pause ^& Endlocal ^& Exit /B 0) %\n%
- For /F "Tokens=1,2,3 Delims={}" %%G in ("!Cells!")Do If not "%%~I" == "" ( %\n%
- Set "cell=%%I" %\n%
- Set "%%G.Color=%%~H" %\n%
- For /L %%i in (2 1 !.Xmin!)Do Set "cell= !cell!" %\n%
- For /L %%x in (0 1 !.Xmax!)Do If not "!cell:~%%x,1!" == "" ( %\n%
- If not "!cell:~%%x,1!" == " " ( %\n%
- Set "tMsg=!tMsg!." %\n%
- !tMsg! %\n%
- Set "tCell=!cell:~%%x,1!" %\n%
- If not "!%%G!" == "" ( %\n%
- For %%t in ("!tCell!")Do Set "t.%%G=!%%G:%%~t=!" %\n%
- If "!t.%%G!" == "!%%G!" Set "%%G.C=!%%G.C! "!tCell!"" %\n%
- ) Else (Set "Obj.C=!Obj.C! "!C.Tkn!"") %\n%
- FOR /F "Delims=" %%X in ('Set /A "{x}=%%x+!.Xmin!+1"')Do ( %\n%
- For %%C in ("H" ";" "[")Do If /I "!cell:~%%x,1!" == "%%~C" ( %\n%
- CLS ^& Mode 1000 %\n%
- Echo/Error in: %%Def.Sprite%%!Cells!!LF! [Invalid] - !Cells:%%~C=[%%~C]! %\n%
- Echo/Delim character %%~C cannot be defined to a sprite. ^& Pause ^& Endlocal ^& Exit %\n%
- ) %\n%
- Set "}!{y}!;%%X=!{y}!;%%XH!cell:~%%x,1!" %\n%
- %COMMENT:{i}= Define Sprite variable Arg 1 with converted Coordinates for non whitespace cells from Arg 2 \n%
- Set "%%G=!%%G!"!{y}!;%%XH!cell:~%%x,1!"," %\n%
- ))) %\n%
- Set /A "%%G.lX=!.Xmax!,%%G.uX=!.Xmin!,%%G.lY=!.Ymax!,%%G.uY=!.Ymin!" %\n%
- For %%S in (!%%G!)Do ( %\n%
- For /F "tokens=1,2 Delims=;H" %%3 in ("%%~S") Do (%\n%
- If %%3 GTR !%%G.uY! (Set "%%G.uY=%%3") %\n%
- If %%3 LSS !%%G.lY! (Set "%%G.lY=%%3") %\n%
- If %%4 GTR !%%G.uX! (Set "%%G.uX=%%4") %\n%
- If %%4 LSS !%%G.lX! (Set "%%G.lX=%%4") %\n%
- ) %\n%
- ) %\n%
- Set /A "%%G.mY=(!%%G.lY!+!%%G.uY!)/2,%%G.mX=(!%%G.lX!+!%%G.uX!)/2" %\n%
- Set /A "%%G.Width=(!%%G.uX!-!%%G.lX!) + 1" %\n%
- )Else ( %\n%
- CLS ^& Mode 1000 %\n%
- Echo/Error in Level !lvl!!LF!Missing Args for -!LF!%%Def.Sprite%%=!Cells!!LF! Def.Sprite USAGE: %\n%
- Echo/!Def.Sprite.Usage!!LF!%%Def.Sprite%%{SPRITEVARNAME}{VTCOLORCODE}{characters for x positions of next Y line}%\n%
- Pause ^& Endlocal ^& Exit /B 0%\n%
- ) %\n%
- )Else Set Cells=
- =============================================================================
- ::: Def.Multicol.Sprite : Converts list of strings to sprite Ascii art with Defined Cordinates }Y;H=}Y;XHVTCOLORCODEcharacter
- ::: Stores last supplied VTCOLORCODE to SPRITEVARNAME.Color
- ::: Defines Cell as }Y;X=Y;XH%\E%[VTCOLORCODEmCHARACTER
- Set "Def.MC.Sprite.Usage=%%Def.Multicol.Sprite:Obj=SPRITEVARNAME%%"Y;XHVTCOLORCODECHARACTER" "Y;XHVTCOLORCODECHARACTER" "Y;XHVTCOLORCODECHARACTER" "
- Set Def.Multicol.Sprite=For %%n in (1 2) Do if %%n==2 ( %\n%
- If /I "!oHASH!" == "Obj" ( %\n%
- Mode 1000 %\n%
- Echo/Error in Level !lvl!!LF!Missing Substituion for -!LF! %%Def.MultiCol.Sprite:!oHASH!=obj%%!Sprite.String! !LF! Def.Multicol.Sprite USAGE: %\n%
- Echo/!Def.MC.Sprite.Usage! %\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- ) %\n%
- Set "Obj=" %\n%
- For %%G in (!Sprite.String!)Do ( %\n%
- Set "c.Tkn=%%~G" %\n%
- For %%C in ("H" ";" "[")Do If /I "!c.Tkn:~-1!" == "%%~C" ( %\n%
- CLS ^& Mode 1000 %\n%
- Echo/Error in: %%Def.MultiCol.Sprite%%!Sprite.String!!LF! [Invalid] - !C.Tkn:~0,-1![%%~C]! %\n%
- Echo/Delim character %%~C cannot be defined to a sprite. ^& Pause ^& Endlocal ^& Exit %\n%
- ) %\n%
- For /F "Tokens=1,2,3* Delims=;[H" %%1 in ("%%~G")Do ( %\n%
- If "%%3" == "" (CLS ^& Mode 1000 ^& Echo/Missing Arg for Def.Multicol.Sprite.!LF! - Accepted - Integer;IntegerHIntegerCharacter!LF! Usage:!Def.MC.Sprite.Usage! ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- Set "Obj.Color=%%~G" %\n%
- Set "c.Tkn=!Obj.Color:~-1!" %\n%
- Set "Obj.Color=!Obj.Color:*H=!" %\n%
- Set "Obj.Color=!Obj.Color:~0,-1!" %\n%
- If not "!Obj.C!" == "" ( %\n%
- For %%t in ("!c.Tkn!")Do Set "t.Obj=!Obj:%%~t=!" %\n%
- If "!t.Obj!" == "!Obj!" Set "Obj.C=!Obj.C! "!C.Tkn!"" %\n%
- ) Else (Set "Obj.C="!C.Tkn!"") %\n%
- Echo/!Obj.Color!^| Findstr.exe /RX "[1234567890;]*" ^> nul %\n%
- If Not !Errorlevel!==0 ( CLS ^& Mode 1000 ^& Echo/Invalid VTColorCode:!Obj.Color! !LF! for Def.Multicol.Sprite.!LF! - Accepted - Integer or Integer;Integer ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- Echo/%%1;%%2^| Findstr.exe /RX "[1234567890;]*[;][1234567890]*" ^> nul %\n%
- If Not !Errorlevel!==0 ( CLS ^& Mode 1000 ^& Echo/Invalid Y;X - %%1;%%2 in:!LF! %%Def.Multicol.Sprite%%!Sprite.String! !LF! Accepted - Integer;Integer!LF! ^& Pause ^> nul ^& Pause ^> nul ^& Exit /B ) %\n%
- Set "}%%1;%%2=%%1;%%2H%\E%[!Obj.Color!m!C.Tkn!" %\n%
- Set "Obj=!Obj!,"%%1;%%2H%\E%[!Obj.Color!m!C.Tkn!"" %\n%
- ) %\n%
- ) %\n%
- Set /A "Obj.lX=!.Xmax!,Obj.uX=!.Xmin!,Obj.lY=!.Ymax!,Obj.uY=!.Ymin!" %\n%
- For %%S in (!Obj!)Do ( %\n%
- For /F "tokens=1,2 Delims=;H" %%3 in ("%%~S") Do (%\n%
- If %%3 GTR !Obj.uY! (Set "Obj.uY=%%3") %\n%
- If %%3 LSS !Obj.lY! (Set "Obj.lY=%%3") %\n%
- If %%4 GTR !Obj.uX! (Set "Obj.uX=%%4") %\n%
- If %%4 LSS !Obj.lX! (Set "Obj.lX=%%4") %\n%
- ) %\n%
- ) %\n%
- Set /A "obj.mY=(!obj.lY!+!obj.uY!)/2,obj.mX=(!obj.lX!+!obj.uX!)/2" %\n%
- Set /A "Obj.Width=!Obj.uX!-!Obj.lX!+1" %\n%
- )Else Set Sprite.String=
- =============================================================================
- ::: SHOW : Iterates over the list value of a substituted sprite variable and outputs value.
- =============================================================================
- rem /* USAGE: %Show:obj=SpriteVARNAME% */ [ Displays spritenames cells ]
- Set Show=If /I "!oHASH!" == "Obj" (%\n%
- ^<nul Set /P "=%\E%[!.End!;1HError in level !lvl!. Unknown Sprite not displayed.!LF!Usage: %%Show:!oHASH!=SpriteVARNAME%%"%\n%
- )Else (%\n%
- (For %%g in (!obj!)Do (%\n%
- Set "oStr=%%~g"%\n%
- ^< nul Set /P "=%\E%[?25l%\E%[!Obj.Color!m%\E%[!oStr!%\E%[0m"%\n%
- )) ^>"%TEMP%\_Obj_.dat" %\n%
- Type "%TEMP%\_Obj_.dat" ^> Con%\n%
- )
- rem /* Variables used to convert Direction to Vector in Move.Sprite Macro*/
- =============================================================================
- rem /* Inverse Player movements for lazy AI control */
- Set ".Left=Right"&Set ".Right=Left"&Set ".Up=Down"&Set ".Down=Up"
- rem /* Clockwise rotation for use with rotate.sprite macro */
- Set "rLeft=up"&Set "rRight=down"&Set "rUp=right"&Set "rDown=left"
- Set "Left={x}{-}"& Set "Right={x}{+}"& Set "Up={y}{-}"& Set "Down={y}{+}"
- Set "{x}{-}=Left"& Set "{x}{+}=Right"& Set "{y}{-}=Up"& Set "{y}{+}=Down"
- ::: Move.Sprite macro will slow a gameloop cycle more as Sprite size and quantity of sprites to be moved increases.
- ::: rem /* Move.Sprite macro. Usage:
- Set "Move.Sprite.Usage=%%Move.Sprite:Obj=SPRITEVARNAME%%{Y|X}{-|+}{Optional-Collision Chars}{Optional-Capture Characters}"
- ::: User info:
- ::: ** Collision Detection is CASE INSENSITIVE as substring modification is used to compare Characters assigned to
- ::: }Y;X array against Args for Collision and capture and the Border Character.
- ::: Y;X format of cmd.exe uses 1;1 as screen home
- ::: Moving a sprite adjusts the sprite 0;0 position along Y or X axis in +1|-1 increments for each cell
- ::: - 2 lists of cells are maintained with the obj {spritevarname} being iterated over to undefine each old cell after a valid move.
- :: The Sub list is then iterated over, redefining each new cell with its value
- ::: Movement is constrained by the .Ymin;.Xmin amd .Ymax;.Xmax boundaries defined within the Background.Border macro.
- ::: When adjusting a sprites 0;0 Each cell is adjusted In accordance with:
- ::: Increase Y ; Move Down
- ::: Decreases Y ; Move Up
- ::: Increase X ; Moving Right
- ::: Decreases X ; Move Left
- ::: Movement is rejected if a collision character is encountered ; Valid=0 ; Obj.Coll=1 ; Obj.Coll=n number of collisions
- ::: Movement is allowed if only empty cells are encountered ; Valid=1
- ::: Movement is allowed if empty cells or Capture characters encountered ; Obj.capt=1 ; Obj.capt=n number of captures
- ::: Args 3 and 4 are optional; Allowing sprites that don't need collision or capture testing to be moved
- ::: To ensure correct results; Characters for {Collision}{Capture} testing should be unique to a single test {Collision} OR {Capture}
- ::: - Duplicate Characters are rejected.
- %=== Move.Sprite RETURN VARIABLES ==========================================%
- ::: Return Varname : Source : true : false : reference value / Description
- =============================================================================
- ::: Valid : Arg 3 : 1 : 0 : Move Valid [No Collisions] / Invalid [ Obj.Coll GEQ 1 ]
- ::: Obj.Coll : Arg 3 : 1;n : 0 : If true ; Move Invalid - Number of Collision characters Object collided with
- ::: Obj.Capt : Arg 4 : 1;n : 0 : Number of Capture characters Object captured
- ::: Obj.on.surface : Arg 3 : 1 : 0 : Object is positioned immediately above a collision character
- ::: : : : : - Can be used to enact Gravity
- ::: Obj.Collide.Type : Args 3+4 : N/A : Last Character Obj.Coll with / capture in defined cell
- ::: Obj.Collide.Type[Col][#] : Arg 3 : N/A : Nth Character collided with in defined cell
- ::: Obj.Collide.Type[Cap][#] : Arg 4 : N/A : Nth Character captured in defined cell
- ::: *** The following return values can be used to guide an NPC sprite to a PC's position
- ::: - values are unique to each sprite with the sprites name [ supplied via substring modification ]
- ::: used as a perfix
- ::: SPRITEVARNAME.mY : Obj=SPRITEVARNAME : : Sprite Median Y position of all cells
- ::: SPRITEVARNAME.mX : Obj=SPRITEVARNAME : : Sprite Median X position of all cells
- ::: SPRITEVARNAME.lY : Obj=SPRITEVARNAME : : Sprite lowest Y position of all cells
- ::: SPRITEVARNAME.lX : Obj=SPRITEVARNAME : : Sprite lowest X position of all cells
- ::: SPRITEVARNAME.uY : Obj=SPRITEVARNAME : : Sprite upper Y position of all cells
- ::: SPRITEVARNAME.uX : Obj=SPRITEVARNAME : : Sprite upper X position of all cells
- =============================
- :::: Notes regarding GRAVITY:
- =============================
- :::: Gravity is not built into move.sprite macro as the way gravity is implemented differs depending on a games design
- ::: A basic way to enact gravity [ Fall until a surface is encountered ] is supported using the return var SPRITEVARNAME.on.surface
- ::: Macros use collision character args of move.sprite and rotate.sprite and Obj.uY+1 position to test if a collision character is
- ::: immediately below the sprite and returns 1 {true} or 0 {false}
- ::: USAGE example:
- ::: Set "SPRITEVARNAME.prv.Dir=!SPRITEVARNAME.Dir!"
- ::: If !SPRITEVARNAME.on.Surface! EQU 0 %Move.Sprite:obj=SPRITEVARNAME%!down!{"collision" "characters"}{"capture" "characters"}
- ::: Set "SPRITEVARNAME.Dir=!SPRITEVARNAME.prv.Dir!"
- ::: saving / restoring sprite direction prior to enacting gravity allows horizontal momentum to be preserved
- Set Move.Sprite=For %%n in (1 2) Do if %%n==2 ( %\n%
- If /I "!Move.Args!" == "" ( %\n%
- Mode 1000 %\n%
- Echo/Error in Level !lvl!!LF!Missing Args for -!LF! %%move.Sprite:!oHASH!=obj%% !LF! Move.Sprite USAGE: %\n%
- Echo/!Move.Sprite.Usage! %\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- ) %\n%
- If /I "!oHASH!" == "Obj" ( %\n%
- Mode 1000 %\n%
- Echo/Error in Level !lvl!!LF!Missing Substituion for -!LF! %%move.Sprite:!oHASH!=obj%%!Move.Args! !LF! Move.Sprite USAGE: %\n%
- Echo/!Move.Sprite.Usage! %\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- ) %\n%
- If /I "!Obj!" == "" ( %\n%
- Mode 1000 %\n%
- Echo/Error in Level !lvl!!LF!Sprite: Obj Is not defined. !LF! %%move.Sprite:!oHASH!=obj%%!Move.Args! !LF! Move.Sprite USAGE: %\n%
- Echo/!Move.Sprite.Usage! %\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- ) %\n%
- Set "Sub=" %\n%
- (For /F "Tokens=1 Delims==" %%l in ('Set Obj.Collide.Type')Do Set "%%l=") 2^> nul %\n%
- Set /A "valid=1,Obj.capt=0,Obj.Coll=0" %\n%
- For /F "Tokens=1,2,3,4,5 Delims={}" %%G in ("!Move.Args!")Do ( %\n%
- Set "axis=%%~G" %\n%
- If "%%~H" == "" ( %\n%
- CLS ^& Mode 1000 %\n%
- Echo/Error in Level !lvl!!LF!Missing Args for - !LF! %%move.Sprite:!oHASH!=Obj%%!Move.Args! !LF! Move.Sprite USAGE: %\n%
- Echo/!Move.Sprite.Usage!%\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- ) %\n%
- Set "vector=%%~H" %\n%
- Set "nDir=!{%%~G}{%%~H}!" %\n%
- If not "%%~I" == "" (Set "Collide=%%I")Else ( Set "Collide=" ) %\n%
- If not "%%~J" == "" (Set "Flag=%%J")Else ( Set "Flag=" ) %\n%
- If not "%%~k" == "" (Set "restore=%%~K")Else ( Set "restore=" ) %\n%
- ) %\n%
- For %%V in (!Collide!)Do For %%T in (!Flag!)Do If "%%~V" == "%%~T" ( %\n%
- CLS ^& Mode 1000 %\n%
- Echo/Error in Level !lvl! - duplicates NOT Permitted. Args 3 and 4 invalid for:!LF! %%move.Sprite:!oHASH!=obj%%!Move.Args!!LF!Arg 3:{!Collide!}!LF!Arg 4:{!Flag!}!LF! Move.Sprite USAGE: %\n%
- Echo/!Move.Sprite.Usage!%\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- ) %\n%
- Set "tArg=!Move.Args:~0,3!" %\n%
- For %%r in ("x" "y")Do Set "tArg=!tArg:%%~r=!" %\n%
- If not "!tArg!" == "{}" ( %\n%
- CLS ^& Mode 1000 %\n%
- Echo/Error in Level !lvl! - Arg 1 Move Axis - !Move.Args:~0,3! invalid for:!LF! %%move.Sprite:!oHASH!=Obj%%!Move.Args!!LF!Invalid Arg 1: {!Axis!}!LF! Move.Sprite USAGE: %\n%
- Echo/!Move.Sprite.Usage! %\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- )%\n%
- Set "tArg=!Move.Args:~3,3!" %\n%
- For %%r in ("-" "+")Do Set "tArg=!tArg:%%~r=!" %\n%
- If not "!tArg!" == "{}" ( %\n%
- CLS ^& Mode 1000 %\n%
- Echo/Error in Level !lvl! - Arg 2 Move Vector - !Move.Args:~0,3! invalid for:!LF! %%move.Sprite:!oHASH!=Obj%%!Move.Args!!LF!Invalid - Arg 2: {!Vector!}!LF! Move.Sprite USAGE: %\n%
- Echo/!Move.Sprite.Usage! %\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- ) %\n%
- If /I "!axis!" == "X" ( %\n%
- For %%g in (!obj!) Do ( %\n%
- For /F "Tokens=1,2,3 Delims=;H" %%i in ("%%~g") Do ( %\n%
- Set /A "cx=%%j!vector!1,oy=%%i,ox=%%j" %\n%
- Set "cTkn=%%~g" %\n%
- Set "cTkn=!cTkn:*H=!" %\n%
- For /F "Delims=" %%o in ("!cx!") Do ( %\n%
- Set "q.cell=" %\n%
- Set "q.cell=!}%%i;%%o!" %\n%
- If not "!q.Cell!" == "" (Set "q.Cell=!q.cell:~-1!") %\n%
- For /F "Delims=" %%K in ("!q.Cell!") Do ( %\n%
- If not "!Collide:%%K=!" == "!Collide!" ( %\n%
- Set "Valid=0" %\n%
- Set /A "Obj.Coll+=1 + 0" %\n%
- Set "Obj.Collide.Type[Col][!Obj.Coll!]=%%K" %\n%
- Set "Obj.Collide.Type=%%~K" %\n%
- ) %\n%
- If "%%K" == "!.Char!" ( %\n%
- Set "Valid=!?Border.Fatal!" %\n%
- Set /A "Obj.Coll+=1 + 0" %\n%
- Set "Obj.Collide.Type[Col][!Obj.Coll!]=%%K" %\n%
- Set "Obj.Collide.Type=%%K" %\n%
- ) %\n%
- If not "!Flag:%%K=!" == "!Flag!" ( %\n%
- %COMMENT:{i}= Resets capture variable to no capture if collision true ; move was rejected \n%
- If "!Valid!" == "1" ( %\n%
- Set /A "Obj.Capt+=1 + 0" %\n%
- Set "Obj.Collide.Type[Cap][!Obj.Capt!]=%%K" %\n%
- Set "Obj.Collide.Type=%%K" %\n%
- )Else ( %\n%
- Set "Obj.Capt=0" %\n%
- (For /F "tokens=1,2 Delims==" %%1 in ('Set Obj.Collide.Type[Cap]')Do Set "%%1=") 2^> nul %\n%
- ) %\n%
- ) %\n%
- ) %\n%
- If "!valid!" == "1" (Set "Sub=!Sub!"%%i;%%oH!cTKN!",") %\n%
- )))) ELSE ( %\n%
- For %%g in (!obj!) Do ( %\n%
- For /F "Tokens=1,2,3 Delims=;H" %%i in ("%%~g") Do ( %\n%
- Set /A "cy=%%i!vector!1,oy=%%i,ox=%%j" %\n%
- Set "cTkn=%%~g" %\n%
- Set "cTkn=!cTkn:*H=!" %\n%
- For /F "Delims=" %%o in ("!cy!") Do ( %\n%
- Set "q.cell=" %\n%
- Set "q.cell=!}%%o;%%j!" %\n%
- If not "!q.Cell!" == "" (Set "q.Cell=!q.cell:~-1!") %\n%
- For /F "Delims=" %%K in ("!q.Cell!") Do ( %\n%
- If not "!Collide:%%K=!" == "!Collide!" ( %\n%
- Set "Valid=0" %\n%
- Set /A "Obj.Coll+=1 + 0" %\n%
- Set "Obj.Collide.Type[Col][!Obj.Coll!]=%%K" %\n%
- Set "Obj.Collide.Type=%%~K" %\n%
- ) %\n%
- If "%%K" == "!.Char!" ( %\n%
- Set "Valid=!?Border.Fatal!" %\n%
- Set /A "Obj.Coll+=1 + 0" %\n%
- Set "Obj.Collide.Type[Col][!Obj.Coll!]=%%K" %\n%
- Set "Obj.Collide.Type=%%K" %\n%
- ) %\n%
- If not "!Flag:%%K=!" == "!Flag!" ( %\n%
- If "!Valid!" == "1" ( %\n%
- Set /A "Obj.Capt+=1 + 0" %\n%
- Set "Obj.Collide.Type[Cap][!Obj.Capt!]=%%K" %\n%
- Set "Obj.Collide.Type=%%K" %\n%
- )Else ( %\n%
- Set "Obj.Capt=0" %\n%
- (For /F "tokens=1,2 Delims==" %%1 in ('Set Obj.Collide.Type[Cap]')Do Set "%%1=") 2^> nul %\n%
- ) %\n%
- ) %\n%
- ) %\n%
- If "!valid!" == "1" (Set "Sub=!Sub!"%%o;%%jH!cTKN!",") %\n%
- ))))%\n%
- If "!valid!" == "1" (%\n%
- Set /A "Obj.lX=!.Xmax!,Obj.uX=!.Xmin!,Obj.lY=!.Ymax!,Obj.uY=!.Ymin!" %\n%
- (For %%Q in (!obj!)Do ( %\n%
- For /F "tokens=1,2 Delims=;H" %%1 in ("%%~Q") Do (%\n%
- If not "!}%%~1;%%~2:~-1!" == "!Restore:~-1!" (%\n%
- Set "}%%~1;%%~2=" %\n%
- ^< nul Set /P "=%\E%[%%~1;%%~2H %\E%[0m" %\n%
- )Else ( %\n%
- Set "}%%~1;%%~2=%%~1;%%~2H!Restore!" %\n%
- ^< nul Set /P "=%\E%[%%~1;%%~2H%\E%[!Restore!" %\n%
- ) %\n%
- )))^>%Foreground% %\n%
- Set "Obj.on.surface=0" %\n%
- Set "Obj.Surface=" %\n%
- Set "obj.on.fatal=" %\n%
- (For %%S in (!Sub!)Do ( %\n%
- For /F "tokens=1,2,3* Delims=;H" %%3 in ("%%~S") Do (%\n%
- If %%3 GTR !Obj.uY! (Set "Obj.uY=%%3") %\n%
- If %%3 LSS !Obj.lY! (Set "Obj.lY=%%3") %\n%
- If %%4 GTR !Obj.uX! (Set "Obj.uX=%%4") %\n%
- If %%4 LSS !Obj.lX! (Set "Obj.lX=%%4") %\n%
- Set "cTKN=%%~S" %\n%
- Set "cTKN=!cTKN:*H=!" %\n%
- Set "}%%~3;%%~4=%%~3;%%~4H!cTKN!" %\n%
- Echo/%\E%[%%~3;%%~4H%\E%[!Obj.Color!m!cTKN!%\E%[0m%\n%
- ))) ^>^>%Foreground% %\n%
- Set /A Below.Sprite=!Obj.uY!+1 %\n%
- For /L %%a in (!Obj.lX! 1 !Obj.uX!)Do For %%b in (!Below.Sprite!)Do For %%c in (!.Char! !Collide! !Flag!)Do ( %\n%
- If /I "!}%%b;%%a:~-1!" == "%%~c" ( %\n%
- Set "Obj.on.surface=1" %\n%
- %COMMENT:{i}= All cells sprite rests on returned in list var below. Use list to differentiate surface types - IE ground ; lava ; water \n%
- Set "Obj.surface=!Obj.surface!"!}%%b;%%a!"," %\n%
- %!!%
- If "!fatal.%%c!" == "1" (Set /A "obj.on.fatal+=1 + 0") %\n%
- ) %\n%
- ) %\n%
- If "!Obj.on.Fatal!" == "!Obj.Width!" (Set "obj.State=dead") %\n%
- TYPE %Foreground% %\n%
- If not "!Obj.Collide.Type!" == "!.Char!" Set "obj=!Sub!" %\n%
- Set /A "obj.mY=(!obj.lY!+!obj.uY!)/2,obj.mX=(!obj.lX!+!obj.uX!)/2" %\n%
- Set "Obj.Dir=!nDir!" %\n%
- ) %\n%
- )Else Set Move.Args=
- =============================================================================
- Set Get.Cell.Adjacent=For %%n in (1)Do ( %\n%
- If /I "!oHASH!" == "Obj" ( %\n%
- Mode 1000 %\n%
- Echo/Error in Level !lvl!!LF!Missing Substituion for -!LF! %%Get.Cell.Adjacent:!oHASH!=Obj%% !LF! Usage: %%Get.Cell.Adjacent:!oHASH!=SPRITEVARNAME%% %\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- ) %\n%
- Set "Obj.Left=" %\n%
- Set "Obj.Right=" %\n%
- Set "Obj.Up=" %\n%
- Set "Obj.Down=" %\n%
- For %%z in (!Obj!)Do For /F "Tokens=1,2 Delims=;H" %%K in ("%%~z")Do ( %\n%
- Set /A "alX=%%L-1,arX=%%L+1,auY=%%K-1,adY=%%K+1" %\n%
- For %%v in ("%%K;!alX!")Do if not "!}%%~v!" == "" (Set "Obj.Left=!}%%~v:~-1!") %\n%
- For %%v in ("%%K;!arX!")Do if not "!}%%~v!" == "" (Set "Obj.Right=!}%%~v:~-1!") %\n%
- For %%v in ("!auY!;%%L")Do if not "!}%%~v!" == "" (Set "Obj.Up=!}%%~v:~-1!") %\n%
- For %%v in ("!adY!;%%L")Do if not "!}%%~v!" == "" (Set "Obj.Down=!}%%~v:~-1!") %\n%
- ) %\n%
- )
- =============================================================================
- ::: Rotate.Sprite Macro - rotates a sprite cells and direction clockwise
- rem --- [ Horizontal flip followed by mirror to simulate 90 degree rotation. ]
- Set "Rotate.Sprite.Usage=For %%%%D in ('!SPRITEVARNAME.Dir!')Do %%Rotate.Sprite:Obj=SPRITEVARNAME%%{!r%%%%D!}{Collision character list}{capture character list}"
- Set Rotate.Sprite=For %%n in (1 2) Do if %%n==2 ( %\n%
- (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%
- If /I "!oHASH!" == "Obj" ( %\n%
- Mode 1000 %\n%
- Echo/Error in Level !lvl!!LF!Missing Substituion for -!LF! %%Rotate.Sprite:!oHASH!=Obj%%!rVector! !LF! Rotate.Sprite USAGE: %\n%
- Echo/!Rotate.Sprite.Usage! %\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- ) %\n%
- If /I "!Obj!" == "" ( %\n%
- Mode 1000 %\n%
- Echo/Error in Level !lvl!!LF!Sprite: Obj Is not defined. !LF! %%Rotate.Sprite:!oHASH!=obj%%!rVector! !LF! Move.Sprite USAGE: %\n%
- Echo/!Rotate.Sprite.Usage! %\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- ) %\n%
- If /I "!Obj.Dir!" == "" ( %\n%
- CLS ^& Mode 1000 %\n%
- Echo/Error in Level !lvl!!LF! Rotate.Sprite requires Obj.Dir to be defined prior to expansion!LF! %%Rotate.Sprite:!oHASH!=obj%%!rVector! !LF! Rotate.Sprite USAGE: %\n%
- Echo/!Rotate.Sprite.Usage! %\n%
- Pause ^& Endlocal ^& Exit /B 0 %\n%
- ) %\n%
- Set "Sub=" %\n%
- %COMMENT:{i}= Determine lower mid and upper median values for each cells position in the sprite \n%
- %COMMENT:{i}= Determine sprite centre offset according to odd / even spritewidth \n%
- Set /A "midX=500,midY=500,{I}=0,rValid=1,Obj.Coll=0,Obj.capt=0" %\n%
- For %%g in (!obj!) Do If not "%%~g" == "" ( %\n%
- Set /A "{I}+=1 + 0" %\n%
- For /F "Tokens=1,2,3* Delims=;H" %%I in ("%%~g") Do ( %\n%
- Set /A "iy!{I}!=%%~I" %\n%
- Set /A "ix!{I}!=%%~J" %\n%
- Set "cTKN!{I}!=%%~g" %\n%
- For %%z in (!{I}!)Do Set "cTKN!{I}!=!cTKN%%z:*H=!" %\n%
- ) %\n%
- ) %\n%
- For /L %%i in (1 1 !{I}!) do For %%A in ("!iy%%i!;!ix%%i!")Do ( %\n%
- For /F "Tokens=1,2 Delims=;" %%X in ("%%~A") Do ( %\n%
- Set /A "oY=%%~X" %\n%
- Set /A "oX=%%~Y" %\n%
- ) %\n%
- If !oY! LSS !midY! Set /A "midY=!oY!" %\n%
- If !oX! LSS !midX! Set /A "midX=!oX!" %\n%
- ) %\n%
- Set "pixel=0" %\n%
- For /L %%i in (1 1 !{I}!) do For %%B in ("!iy%%i!;!ix%%i!")Do ( %\n%
- Set /A "pixel+=1" %\n%
- For /F "Tokens=1,2 Delims=;" %%r in ("%%~B") Do ( %\n%
- Set /A "ny!pixel!=(%%~s-!midX!)+!midY!,nx!pixel!=(%%~r-!midY!)+!midX!" %\n%
- ) %\n%
- ) %\n%
- Set "pixel=0" %\n%
- Set /A "lmidX=500,umidX=0" %\n%
- For /L %%i in (1 1 !{I}!) do For %%C in (!nx%%i!) Do ( %\n%
- If %%C LSS !lmidX! (Set /A "lmidX=%%C") %\n%
- If %%C GTR !umidX! (Set /A "umidX=%%C") %\n%
- ) %\n%
- Set /A "Obj.Width=!umidX!-!lmidX!" %\n%
- For /L %%i in (1 2 19)Do If !Obj.Width! EQU %%i Set "Centre=0" %\n%
- For /L %%i in (0 2 20)Do If !Obj.Width! EQU %%i Set "Centre=1" %\n%
- Set /A "Obj.Width+=1" %\n%
- if !umidX!==!lmidX! Set "Centre=0" %\n%
- Set /A "Mid.X=( !lmidX! + !umidX! ) / 2" %\n%
- For /L %%i in (1 1 !{I}!) do For %%X in (!nx%%i!) Do ( %\n%
- Set /A "pixel=!pixel! + 1" %\n%
- Set /A "nx!pixel!=%%X + !centre!" %\n%
- IF %%X LSS !Mid.X! (Set /A "nx!pixel!= %%X + ((!Mid.X!-%%X) * 2) + !centre!") %\n%
- IF %%X GTR !Mid.X! (Set /A "nx!pixel!= %%X - ((%%X-!Mid.X!) * 2) + !centre!") %\n%
- ) %\n%
- For /F "Tokens=1,2,3,4 Delims={}" %%o in ("!rVector!") Do ( %\n%
- Set "cDir=%%o" %\n%
- Set "Flag=%%q" %\n%
- ) %\n%
- For /L %%i in (1 1 !{I}!)Do ( %\n%
- for %%c in ("!ny%%i!;!nx%%i!")Do If not "!}%%~c!" == "" ( %\n%
- %COMMENT:{i}= Perform collision arg character testing \n%
- %COMMENT:{i}= Collision Character Args should be doubleqouted \n%
- For /F "Tokens=2 Delims={}" %%m in ("!rVector!")Do Set "Collide=%%m" %\n%
- For %%v in (!Collide!) Do If not "!}%%~c!" == "" ( %\n%
- Set "KO=!}%%~c:%%~v=!" %\n%
- If Not "!}%%~c!" == "!KO!" (%\n%
- Set "rValid=0" %\n%
- Set "Obj.Collide.Type=%%~v" %\n%
- Set /A "Obj.Coll+=1" %\n%
- Set "Obj.Collide.Type[Col][!Obj.Coll!]=%%~v" %\n%
- ) %\n%
- ) %\n%
- ) %\n%
- ) %\n%
- If "!rValid!" == "1" ( %\n%
- Set "Obj.Dir=!cDir!"%\n%
- %COMMENT:{i}= Rebuild Object cell string on succesful move ; test cells for flagged capture characters \n%
- For /L %%i in (1 1 !{I}!) do ( %\n%
- Set "Sub=!Sub!"!ny%%i!;!nx%%i!H!cTkn%%i!"," %\n%
- %COMMENT:{i}= Perform capture arg character testing \n%
- For %%P in (!Flag!)Do for %%v in ("!ny%%i!;!nx%%i!")Do If Not "!}%%~v!" == "" ( %\n%
- Set "flag.C=!}%%~v:%%~P=!" %\n%
- Set "flag.Cell=!}%%~v!" %\n%
- If Not "!flag.Cell!" == "!flag.C!" ( %\n%
- Set /A "Obj.capt+=1 + 0" %\n%
- Set "Obj.Collide.Type=!cTkn%%i:~-1!" %\n%
- Set "Obj.Collide.Type[Cap][!Obj.capt!]=!cTkn%%i:~-1!" %\n%
- ) %\n%
- ) %\n%
- ) %\n%
- %COMMENT:{i}= Output whitespace to clear Objects previous cell positions from screen to foreground file [overwrite] \n%
- (For %%Q in (!obj!)Do ( %\n%
- For /F "tokens=1,2 Delims=;H" %%1 in ("%%~Q") Do (%\n%
- Set "}%%1;%%2=" %\n%
- Echo/%\E%[%%1;%%2H %\n%
- )))^>%Foreground% %\n%
- Set "Obj.on.surface=0" %\n%
- Set "Obj.Surface=" %\n%
- Set "obj.on.fatal=" %\n%
- %COMMENT:{i}= Output [append] Objects new Cell positions to foreground file \n%
- (For %%S in (!Sub!)Do ( %\n%
- For /F "tokens=1,2,3 Delims=;H" %%3 in ("%%~S") Do (%\n%
- Set "cTKN=%%~S" %\n%
- Set "cTKN=!cTKN:*H=!" %\n%
- Set "}%%3;%%4=%%3%!!%%4H!cTKN!" %\n%
- Echo/%\E%[%%3;%%4H%\E%[!Obj.Color!m!cTKN!%\E%[0m%\n%
- ))) ^>^>%Foreground% %\n%
- %COMMENT:{i}= type the output file to console \n%
- TYPE %Foreground% %\n%
- Set /A Below.Sprite=!Obj.uY!+1 %\n%
- For /L %%a in (!Obj.lX! 1 !Obj.uX!)Do For %%b in (!Below.Sprite!)Do For %%c in (!.Char! !Collide! !Flag!)Do ( %\n%
- If /I "!}%%b;%%a:~-1!" == "%%~c" ( %\n%
- Set "Obj.on.surface=1" %\n%
- %COMMENT:{i}= All cells sprite rests on returned in list var below. Use list to differentiate surface types - IE ground ; lava ; water \n%
- Set "Obj.surface=!Obj.surface!"!}%%b;%%a!"," %\n%
- %!!%
- If "!fatal.%%c!" == "1" (Set /A "obj.on.fatal+=1 + 0") %\n%
- ) %\n%
- ) %\n%
- If "!Obj.on.Fatal!" == "!Obj.Width!" (Set "obj.State=dead") %\n%
- %COMMENT:{i}= Update Object value \n%
- Set "obj=!Sub!" %\n%
- Set "Sub=" %\n%
- ) %\n%
- )Else Set rVector=
- ========================================================================================================
- ::: Macro's for using the Music system included in the Games_By_T3RRY archive
- ::: PlayMusic.Bat creates a vbs file to launch music files using valid parameters for track path, volume and loop t/f [1/0]
- ::: StopMusic.Bat uses taskkill to end any active vbs Wscripts
- ::: GameMonitor.bat creates a vbs that monitors the cmd.exe process and launches StopMusic.Bat when the console is closed
- ::: ensuring the music is stopped even when the user closes the console with the close button
- ::: Once launched, StopMusic.bat Deletes any vbs scripts in the game folder, except Monitor.vbs if the game is still running
- 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="
- Set "Stop.Music=If Exist "%~dp0Components\StopMusic.bat" (Call "%~dp0Components\StopMusic.Bat" running 2> nul )"
- Set "Monitor.Game=Call "%~dp0Components\Gamemonitor.bat" start 2> nul"
- ========================================================================================================
- ::: Coming Soon?
- ::: Set "Sprite.Shoot.Usage=%%Sprite.Shoot:Obj=SPRITEVARNAME%%{Y|X}{-|+}{INTEGER-Shot.Len}{Collision Characters}{ASCII_Character}"
- ::: Use Array Macros to define Bullet Origin ; Vector. IE... For %%D in (!Dir!)Do !Shot.%%D!
- :# Shot is orientation dependent ; Shoots along Arg 1 {Y|X} from:
- :# Up = {Obj.lY - 1;Obj.mX} ; Down = {Obj.uY + 1;Obj.mX} ; Left = {Obj.uX - 1;Obj.mY} ; Right = {Obj.uX + 1;Obj.mX}
- :# Test macro input and substitution
- :# Clear definitions of l} ; r} ; Shot.Obj.Collide.Type ; Collide
- :# For each cell in shot.len Do If not collide = true ;
- :# If defined l}Y;X assign to r}Y;X ; clone next }Y;X in dir to l}Y;X
- :# Advance shot and display of Arg 5 character ; replace r}Y;X cell output [ previous cells state ] ; define l}Y;X
- :# test collision against arg 4 characters ; Flag if true
- :# ;Else Return Shot.Obj.Collide.Type
- ::: Alternate approach create a macro that on keypress for shoot is expanded to:
- ::: Calculate a positive offset according to the above orientation
- ::: Use Calculated Y;X offset to define a Bullet Sprite with Def.Multicol.Sprite
- ::: Use a loop... :
- ::: For /L in (1 1 Shot.Len)Do If not "!Valid!" == "0" (
- ::: Test next Cell Coordinates ; Flag - Valid - Obj.capt - Obj.Coll states
- ::: %Move.Sprite:Obj=Bullet%!SHOOTINGSPRITESVARNAME.Dir!{Collide Characters}{Capture Characters}
- ::: If Not "!Obj.capt!" == "" (
- ::: REM ON CAPTURE COMMANDS
- ::: REM The bullet has hit a capture target
- ::: REM ? options:
- ::: - Terminate bullet travel ?
- ::: - Continue travel up to ? 2 cells [ piercing fire ]
- ::: - Flag Capture cell as hit [ Cell specific hit count ; Flag shot.capture = true ]
- ::: - Flag Collide cell as hit [ Cell specific hit count ; Flag shot.collide = true ]
- ::: - ? Modify Move.Sprite / Rotate.Sprite to test Cell hit state and transfer state to new cell
- ::: )
- ::: ) Else ( REM ON COLLIDE COMMANDS - [ The bullet Can Travel no futher. Undefine Bullet Sprite ; Clear Cell ] )
- ::: ... to Move.Sprite Obj=Bullet n times supplying collision / capture args
- ::: Within the for /L loop enact conditional tests on Obj.Collide.Type variable
- ========================================================================================================
- If "%~1" == "/Q" Exit /B 0
- CLS & Mode 1000 & Title %~n0 by T3RRY
- Echo/%\E%[7;33m%~1%\E%[0m%\E%!!%\E%!!%\E%!!%~nx0%\E%[0m%\E%[48;2;100;0;70m by T3RRY.%\E%[K
- Echo/%\E%[31m%\E%[48;2;0;120;60m ** An object oriented Game engine for Batch games **%\E%[K
- Echo/%\E%[0m %\E%[37myoutube: %\E%[36mhttps://www.youtube.com/channel/UCo3tS26Eg-ITbdNgWhB0MRQ
- Echo/ %\E%[37mDosTips: %\E%[34mhttps://www.dostips.com/forum/memberlist.php?mode=viewprofile^&u=10296
- Echo/ %\E%[37mStackoveflow: %\E%[36mhttps://stackoverflow.com/users/12343998/t3rr0r
- Echo/ %\E%[37mpastebin: %\E%[34mhttps://pastebin.com/u/T3RRYT3RR0R%\E%[0m
- Endlocal
- Timeout /T 3 /Nobreak > nul
- Pause
- ::: Errorlevel must be reset to 0 when exiting after Getfontsize is invoked
- Exit /B 0
- :TestVT
- Set "VTsupport="
- 2> nul (
- More < "%~f0:VTsupport" > nul && (
- Exit /b 0
- ) || (
- <Nul Set /P "=Verifying Compatability %\E%[2D"
- for /F "delims=" %%a in ('"PowerShell $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 (
- Cls
- If "%%a" == "y" (
- (Echo(true) >"%~f0:VTsupport"
- Exit /b 0
- )else (
- Echo(Virtual terminal sequences not enabled on your system. This program will not execute as intended.
- Exit /b 1
- ))))
- Exit /b 2
Add Comment
Please, Sign In to add comment