T3RRYT3RR0R

Batch Game Escape the Warping Ampersands

Feb 18th, 2020
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 10.50 KB | None | 0 0
  1. @ECHO OFF & TITLE Escape the Ampersands
  2. REM ::: Batch Minigame Tutorial By T3RRY
  3.  
  4. REM ::: Youtube : https://youtu.be/4j1myFxh8xc
  5.  
  6. :start
  7.     CLS
  8. ::: REM EXIT /B 0 is used to return from Functions with a Zero Errorlevel. This is done due to the frequent use of Choice Command with Errorlevel.
  9.  
  10. ::: REM Define 'Play Field' Parameters. Allows Play Field Characteristics to be easily Changed. Only Hieght and Width need changing
  11. :: Outer Border
  12. REM Hieght Max = 38 Min = 20
  13. REM Width Max = 150 Min =35
  14.     Set "Hieght=25"
  15.     Set "Width=35"
  16.  
  17.     Set /A Score=(%Hieght% * %Width%) * 2
  18.  
  19.     Set "Lines=%Hieght%"
  20.     Set /a "Lines+=5"
  21.     Set "Columns=%Width%"
  22.  
  23. ::: Establish Screen size. Larger screen sizes will result in slower Load times and Gameplay.
  24.  
  25. cls & Mode Con cols=%Columns% Lines=%Lines%
  26.  
  27. :: Inner Border
  28.     Set "Axis_mins=2"
  29.     Set /A "X_Axis_Boundary=%Width% - 1"
  30.     Set /A "Y_Axis_Boundary=%Hieght% - 1"
  31. :: Move Limits within Borders
  32.     Set "Limit_Axis_Min=3"
  33.     Set /A "Limit_X_Max=%X_Axis_Boundary% - 1"
  34.     Set /A "Limit_Y_Max=%Y_Axis_Boundary% - 1"
  35. :: Character Displayed as Outside Border
  36.     Set "space= "
  37. :: Character Displayed as Enenmy
  38.     Set "P_C=@"
  39.     Set "E_C=^&"
  40.     Set "Esc=^"
  41.     Set "ENEMY=%E_C%"
  42. :: Instruction Line Pos - Line number that information is displayed to the player on
  43.     Set /A Instructions=%hieght% + 2
  44.     Set "Game_Over=Goto :end"
  45.  
  46. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Macro Definition
  47.  
  48.  
  49. setlocal DisableDelayedExpansion
  50. set LF=^
  51.  
  52.  
  53. ::Above 2 blank lines are required - do not remove
  54. set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
  55.  
  56.  
  57. Set @COL=for /L %%n in (1 1 2) do if %%n==2 (%\n%
  58.       for /F "tokens=1 delims=," %%G in ("!argv!") do (%\n%
  59.     Set /a "Rand_Col=!random! * 5 / 32768 + 1" %\n%
  60.     IF !Rand_Col!==5 (Set "%%G=!E_C!") %\n%
  61.     IF !Rand_Col!==4 (Set "%%G=!E_C!") %\n%
  62.     IF !Rand_Col!==3 (Set "%%G=!E_C!") %\n%
  63.     IF !Rand_Col!==2 (Set "%%G=!E_C!") %\n%
  64.     IF !Rand_Col!==1 (Set "%%G=!E_C!") %\n%
  65.       ) %\n%
  66. ) ELSE setlocal enableDelayedExpansion ^& set argv=,
  67.  
  68. Set @POS=for /L %%n in (1 1 2) do if %%n==2 (%\n%
  69.       for /F "tokens=1 delims=, " %%G in ("!argv!") do (%\n%
  70.     ECHO([!L_Y_Pos!;!L_X_Pos!H.%\n%
  71.     ECHO([!L_AI_Y!;!L_AI_X!H.%\n%
  72.     ECHO([!L_AI2_Y!;!L_AI2_X!H.%\n%
  73.     ECHO([!Y_Pos!;!X_Pos!H!P_C!%\n%
  74.       ) %\n%
  75. ) ELSE setlocal enableDelayedExpansion ^& set argv=,
  76.  
  77.  
  78. Set @REFRESH=for /L %%n in (1 1 2) do if %%n==2 (%\n%
  79.       for /F "tokens=1 delims=, " %%G in ("!argv!") do (%\n%
  80.     IF "!L_X_Pos!"=="!X_Pos!" IF "!L_Y_Pos!"=="!Y_Pos!" ECHO([!Y_Pos!;!X_Pos!H!P_C!%\n%
  81.     IF "!X_Pos!"=="!AI_X!" IF "!Y_Pos!"=="!AI_Y!" (%\n%
  82.         ECHO([!Y_Pos!;!X_Pos!HX%\n%
  83.         Set "G_Over=[!Instructions!;1HYou were Nommed by the AI"%\n%
  84.         !Game_Over!%\n%
  85.     ) %\n%
  86.     IF "!X_Pos!"=="!AI2_X!" IF "!Y_Pos!"=="!AI2_Y!" (%\n%
  87.         ECHO([!Y_Pos!;!X_Pos!HX%\n%
  88.         Set "G_Over=[!Instructions!;1HYou were Nommed by the AI"%\n%
  89.         !Game_Over!%\n%
  90.     ) %\n%
  91.     IF "!X_Pos!"=="!X_B!" IF "!Y_Pos!"=="!Y_B!" (%\n%
  92.         ECHO([!Y_Pos!;!X_Pos!HX%\n%
  93.         Set "G_Over=[!Instructions!;1HYou Hit the Bomb"%\n%
  94.         !Game_Over!%\n%
  95.     ) %\n%
  96.     IF "!X_Pos!"=="!X_Esc!" IF "!Y_Pos!"=="!Y_Esc!" (%\n%
  97.         ECHO([!Y_Pos!;!X_Pos!H!Esc!%\n%
  98.         ECHO([!AI_Y!;!AI_X!H!space!%\n%
  99.         ECHO([!AI2_Y!;!AI2_X!H!space!%\n%
  100.         Set "G_Over=[!Instructions!;1HYou've Escaped with !Score! points"%\n%
  101.         !Game_Over!%\n%
  102.     ) %\n%
  103.       ) %\n%
  104. ) ELSE setlocal enableDelayedExpansion ^& set argv=,
  105.  
  106. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: End Macro's
  107.  
  108. ::: REM Build Screen Background using for /L loop to repeat action for the desired number of times in each Line and Column Position
  109. ::: REM (cont) Defined within the Nested Loops.
  110.  
  111.     For /L %%A IN (1,1,%Width%) DO (
  112.         For /L %%B IN (1,1,%hieght%) DO (
  113.             ECHO([%%B;%%AHX
  114.         )
  115.     )
  116.  
  117.     For /L %%A IN (1,1,%hieght%) DO (
  118.         For %%B IN (%Axis_mins%,%X_Axis_Boundary%) DO (
  119.             ECHO([%%A;%%BH+
  120.         )
  121.     )
  122.  
  123.     For /L %%A IN (1,1,%Width%) DO (
  124.         For %%B IN (%Axis_mins%,%Y_Axis_Boundary%) DO (
  125.             ECHO([%%B;%%AH+
  126.         )
  127.     )
  128.  
  129.     For /L %%A IN (1,1,%hieght%) DO (
  130.         ECHO([%%A;1H%space%
  131.         ECHO([%%A;%Width%H%space%
  132.     )
  133.  
  134.     For /L %%A IN (1,1,%Width%) DO (
  135.         ECHO([1;%%AH%space%
  136.         ECHO([%hieght%;%%AH%space%
  137.     )
  138.  
  139. REM Define Starting Positions
  140. :startpos
  141.     Set /A "X_Pos=%random% %%%Limit_X_Max% + 2"
  142.     Set /A "Y_Pos=%random% %%%Limit_Y_Max% + 2"
  143.     Set /A "AI_X=%random% %%%Limit_X_Max% + 2"
  144.     Set /A "AI_Y=%random% %%%Limit_Y_Max% + 2"
  145.     Set /A "AI2_X=%random% %%%Limit_X_Max% + 2"
  146.     Set /A "AI2_Y=%random% %%%Limit_Y_Max% + 2"
  147.  
  148.     IF "%X_Pos%"=="%AI_X%" IF "%Y_Pos%"=="%AI_Y%" GOTO :startpos
  149.     IF "%X_Pos%"=="%AI2_X%" IF "%Y_Pos%"=="%AI2_Y%" GOTO :startpos
  150.     IF "%AI2_X%"=="%AI_X%" IF "%AI2_Y%"=="%AI_Y%" GOTO :startpos
  151.  
  152.     FOR %%A in (%X_Pos%,%AI_X%,%AI2_X%) Do (
  153.         IF %%A LSS %Limit_Axis_Min% GOTO :startpos
  154.         IF %%A GEQ %Limit_X_Max% GOTO :startpos
  155.     )
  156.    
  157.     FOR %%A in (%Y_Pos%,%AI_Y%,%AI2_Y%) Do (
  158.         IF %%A LSS %Limit_Axis_Min% GOTO :startpos 
  159.         IF %%A GEQ %Limit_Y_Max% GOTO :startpos
  160.     )
  161.  
  162. REM Initialise Last Position variables
  163.     Set "L_Y_Pos=%Y_Pos%"
  164.     Set "L_X_Pos=%X_Pos%"
  165.     Set "L_AI_X=%AI2_X%"
  166.     Set "L_AI_Y=%AI2_Y%"
  167.     Set "L_AI2_X=%AI_X%"
  168.     Set "L_AI2_Y=%AI_Y%"
  169.  
  170. ::: REM initialise Jump properties. Jump properties are calculated based on starting score, which is double the playfield Area
  171.     Set Jump=0
  172.     Set /A "Jump_Freq=%score% / 100"
  173.     Set /A "Jump_Reset=%Jump_Freq% * 5"
  174.  
  175. :bomb
  176.  
  177. REM Define Random Position For "Bomb" as loss condition, ensuring value within 'play field'
  178.     Set /a "Y_B=%random% %%%Limit_Y_Max% + 1"
  179.     Set /a "X_B=%random% %%%Limit_X_Max% + 1"
  180.     For %%A in (%Y_B%,%X_B%) Do (
  181.         IF %%A GEQ %Limit_Y_Max% (GOTO :bomb)
  182.         IF %%A LSS %Limit_Axis_Min% (GOTO :bomb)
  183.     )
  184.     IF "%X_B%"=="%X_Pos%" IF "%Y_B%"=="%Y_Pos%" (GOTO :bomb)
  185.  
  186. ::: REM Define Random Position For "Escape" as win condition, ensuring value within 'play field', and Different to "bomb" position
  187.  
  188. :escape
  189.     Set /a "Y_Esc=%random% %%%Limit_Y_Max% + 1"
  190.     Set /a "X_Esc=%random% %%%Limit_X_Max% + 1"
  191.  
  192.     For %%A in (%Y_Esc%,%X_Esc%) Do (
  193.         IF %%A GEQ %Limit_Y_Max% (GOTO :escape)
  194.         IF %%A LSS %Limit_Axis_Min% (GOTO :escape)
  195.     )
  196.     IF "%X_Esc%"=="%X_Pos%" IF %Y_Esc%=="%Y_Pos%" (GOTO :escape)
  197.     IF "%X_Esc%"=="%X_B%" IF "%Y_Esc%"=="%Y_B%" (GOTO :escape)
  198.  
  199. ::: REM Call refresh Function to Display initial Position, and Update Position after Movement within 'move' loop, Update Last X and Y Positions prior to Movement
  200.  
  201. :Move
  202.     Set /A Jump+=1
  203.     %@POS% refresh
  204.     Endlocal
  205.     %@COL% ENEMY
  206.     ECHO([%AI_Y%;%AI_X%H%ENEMY%
  207.     Endlocal
  208.     %@COL% ENEMY
  209.     ECHO([%AI2_Y%;%AI2_X%H%ENEMY%
  210.     Endlocal
  211.     %@REFRESH% screen
  212.     Endlocal
  213.  
  214.     Set /A Score-=1
  215.     Set "L_AI_X=%AI_X%"
  216.     Set "L_AI_Y=%AI_Y%"
  217.     Set "L_AI2_X=%AI2_X%"
  218.     Set "L_AI2_Y=%AI2_Y%"
  219.     Set "L_Y_Pos=%Y_Pos%"
  220.     Set "L_X_Pos=%X_Pos%"
  221.  
  222.     ECHO([%instructions%;1H Escape the Ampersands [W A S D]
  223.  
  224. REM :: Default switch results in a Free Move for the AI
  225.  
  226.     CHOICE /T 1 /N /C wasd0 /M "" /D 0 >nul
  227.     CALL :Direction%ERRORLEVEL%
  228.  
  229.     Set /a AI_Move=%random% %%2 +1
  230.     Set /a AI2_Move=%random% %%2 +1
  231.  
  232. REM Warp the enemy characters to a new position Only if they are not on the same X axis at defined intervals
  233.  
  234.     For /L %%A in (%Jump_Freq%,%Jump_Freq%,%Jump_Reset%) Do (
  235.         IF %Jump%==%%A (
  236.             IF Not "%X_Pos%"=="%AI_X%" Call :Jump
  237.             IF Not "%X_Pos%"=="%AI2_X%" Call :Jump2
  238.             IF "%%A"=="%Jump_Reset%" (Set /A "Score+=%Jump_Reset%" && Set "Jump=0")
  239.         )
  240.     )
  241.     IF Not Errorlevel 1 (
  242.         CALL :AImove%AI_Move%
  243.         CALL :AI2move%AI2_Move%
  244.     )
  245.     GOTO :Move
  246.  
  247. ::::::::::::::::::::::::::::::::::::::::::::::::::: Script break
  248.  
  249. :AImove1
  250.    
  251.     IF "%AI_X%"=="%X_Pos%" (
  252.         IF %AI_Y% LSS %Y_POS% (Set /a "AI_Y+=1")
  253.         IF %AI_Y% GTR %Y_POS% (Set /a "AI_Y-=1")
  254.     ) else (
  255.         IF %AI_X% LSS %X_POS% (Set /a "AI_X+=1")
  256.         IF %AI_X% GTR %X_POS% (Set /a "AI_X-=1")
  257.     )
  258.     EXIT /B 0
  259.  
  260. :AI2move1
  261.  
  262.     IF "%AI2_X%"=="%X_Pos%" (
  263.         IF %AI2_Y% LSS %Y_POS% (Set /a "AI2_Y+=1")
  264.         IF %AI2_Y% GTR %Y_POS% (Set /a "AI2_Y-=1")
  265.     ) else (
  266.         IF %AI2_X% LSS %X_POS% (Set /a "AI2_X+=1")
  267.         IF %AI2_X% GTR %X_POS% (Set /a "AI2_X-=1")
  268.     )
  269.     EXIT /B 0
  270.  
  271. :AImove2
  272.  
  273. ::: REM Y Pos Equal Comparison Disabled to Balance AI Tracking Ability. Remove ::: In Function to Make AI more Challenging
  274.  
  275.     IF "%AI_Y%"=="%Y_Pos%" (
  276.         IF %AI_X% LSS %X_POS% (Set /a "AI_X+=1")
  277.         IF %AI_X% GTR %X_POS% (Set /a "AI_X-=1")
  278.     ) else (
  279.         IF %AI_Y% LSS %Y_POS% (Set /a "AI_Y+=1")
  280.         IF %AI_Y% GTR %Y_POS% (Set /a "AI_Y-=1")
  281.     )
  282.     EXIT /B 0
  283.  
  284. :AI2move2
  285.  
  286.     IF "%AI2_Y%"=="%Y_Pos%" (
  287.         IF %AI2_X% LSS %X_POS% (Set /a "AI2_X+=1")
  288.         IF %AI2_X% GTR %X_POS% (Set /a "AI2_X-=1")
  289.     ) else (
  290.         IF %AI2_Y% LSS %Y_POS% (Set /a "AI2_Y+=1")
  291.         IF %AI2_Y% GTR %Y_POS% (Set /a "AI2_Y-=1")
  292.     )
  293.     EXIT /B 0
  294.  
  295. REM :: AI Advance
  296. :Direction5
  297.     EXIT /B 0
  298.  
  299. REM :: Right    Test If at Rightmost Limit of X axis before allowing Movement, By Increasing Y axis count by one.
  300. :Direction4
  301.  
  302.     IF NOT "%X_Pos%"=="%Limit_X_Max%" (Set /a "X_Pos+=1")
  303.     EXIT /B 0
  304.  
  305. REM :: Down Test If at Lower Limit of Y axis before allowing Movement, By Increasing Y axis count by one.
  306. :Direction3
  307.  
  308.     IF NOT "%Y_Pos%"=="%Limit_Y_Max%" (Set /a "Y_Pos+=1")
  309.     EXIT /B 0
  310.  
  311. REM :: Left Test If at Leftmost Limit of X axis before allowing Movement, By reducing X axis count by one.
  312. :Direction2
  313.  
  314.     IF NOT "%X_Pos%"=="%Limit_Axis_Min%" (Set /a "X_Pos-=1")
  315.     EXIT /B 0
  316.    
  317. REM :: Up.  Test If at Upper Limit of Y axis before allowing Movement, By reducing Y axis count by one.
  318. :Direction1
  319.  
  320.     IF NOT "%Y_Pos%"=="%Limit_Axis_Min%" (Set /a "Y_Pos-=1")
  321.     EXIT /B 0
  322.  
  323. :Jump
  324.     Set /A AI_X=%random% %%%Limit_X_Max% + 2
  325.     Set /A AI_Y=%random% %%%Limit_Y_Max% + 2
  326.     FOR %%A in (%AI_Y%) Do (
  327.         IF %%A LSS %Limit_Axis_Min% GOTO :Jump 
  328.         IF %%A GEQ %Limit_Y_Max% GOTO :Jump
  329.     )
  330.     FOR %%A in (%AI_X%) Do (
  331.         IF %%A LSS %Limit_Axis_Min% GOTO :Jump
  332.         IF %%A GEQ %Limit_X_Max% GOTO :Jump
  333.     )
  334.     IF %X_Pos%==%AI_X% IF %Y_Pos%==%AI_Y% GOTO :Jump
  335.     Exit /B 1
  336.  
  337. :Jump2
  338.     Set /A AI2_X=%random% %%%Limit_X_Max% + 2
  339.     Set /A AI2_Y=%random% %%%Limit_Y_Max% + 2
  340.     FOR %%A in (%AI2_Y%) Do (
  341.         IF %%A LSS %Limit_Axis_Min% GOTO :Jump2
  342.         IF %%A GEQ %Limit_Y_Max% GOTO :Jump2
  343.     )
  344.     FOR %%A in (%AI2_X%) Do (
  345.         IF %%A LSS %Limit_Axis_Min% GOTO :Jump2
  346.         IF %%A GEQ %Limit_X_Max% GOTO :Jump2
  347.     )
  348.     IF %X_Pos%==%AI2_X% IF %Y_Pos%==%AI2_Y% GOTO :Jump2
  349.     Exit /B 1
  350.  
  351. :end
  352.     ECHO(%G_over%
  353. Set /A Instructions+=1
  354.     ECHO([%Instructions%;1H[E]xit [R]eplay
  355. CHOICE /N /C re /M "" >nul
  356.     IF %ERRORLEVEL%==2 (EXIT)
  357.  
  358.     ENDLOCAL & GOTO :start
Advertisement
Add Comment
Please, Sign In to add comment