Advertisement
IcarusLives

Game Engine v1.2

Jun 8th, 2017
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 9.88 KB | None | 0 0
  1. @echo off & setlocal enableDelayedExpansion
  2.  
  3. %multithread_dispatcher%
  4.    
  5.     if not exist %temp%\Canvas_3.txt call :map
  6.     call :updateCanvas /f 3
  7.    
  8.     set /a "x=19", "y=21", "m=5"
  9.     for /l %%a in (1,1,%m%) do set /a "m%%a=18 - %%a - 1", "n%%a=20 - %%a - 1"
  10.  
  11. call :multiThread GAME_ENGINE "wasd"
  12. goto :eof
  13.  
  14.  
  15.  
  16. :GAME_ENGINE
  17.  
  18.     (   for /l %%# in () do (       set /a "frame+=1"
  19.        
  20.             :: User Controller
  21.             %Controller% & %move% w a s d x y .
  22.            
  23.             :: NPC Controller
  24.             for /l %%a in (1,1,%m%) do (
  25.                 set /a "com=!random! %% 4" & %move% 3 2 1 0 m%%a n%%a %%a )
  26.            
  27.             call:adjustCamera x y
  28.             call:showCanvas !x! !y! @
  29.             call:updateCanvas /v 3
  30.            
  31.     )   )
  32. exit
  33.  
  34. :checkSpace
  35.     set /a "_x=%~1", "_y=%~2"
  36.    
  37.            if "!_[%_y%]:~%_x%,1!" equ "л" ( exit /b 1
  38.     ) else if "!_[%_y%]:~%_x%,1!" equ "M" ( exit /b 1
  39.     ) else if "!_[%_y%]:~%_x%,1!" equ "D" ( set /a "x=!random! %% (width-10) + 10", "y=!random! %% (height-10) + 10"
  40.     ) else if "!_[%_y%]:~%_x%,1!" equ "T" ( exit /b 1
  41.     )
  42. exit /b 0
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. :canvas
  73. set ^"LF=^
  74.  
  75. ^" Above empty line is required - do not remove
  76. set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
  77.         call:macros
  78.         call:cursorpos 2>nul
  79.         if "%~2" neq "" ( set /a "width=%~1 - 1", "height=%~2 - 1" ) else ( goto :eof )
  80.         if "%~3" neq "" ( set "canvasChar=%~3" ) else ( set "canvasChar=#" )
  81.         if "%~4" neq "" ( set "title=%~4" ) else ( set "title=CANVAS" )
  82.         if "%~7" neq "" ( if /i "%~5" equ "/c" (
  83.                 set "CAM=/c"
  84.                 set /a "CAM_Y=0", "CAM_X=0", "maxX=%~6", "winMaxY=%~7","cols=maxX + 5", "rows=winMaxY + 8"
  85.                 if not defined outerBuffer ( for /l %%a in (-1,1,!maxX!) do (
  86.                     set "outerBuffer=!outerBuffer!%canvasChar%") )
  87.                 if !maxX!    geq %width%  set /a "maxX=width"
  88.                 if !winMaxY! geq %height% set /a "winMaxY=height"
  89.             )
  90.         ) else (
  91.             set /a "cols=width + 5", "rows=height + 8"
  92.             if not defined outerBuffer ( for /l %%a in (-2,1,%width%) do (
  93.                 set "outerBuffer=!outerBuffer!%canvasChar%") )
  94.         )
  95.         if not defined Controller ( set "Controller=set "com="^^& set /p "com="" )
  96.         if not defined multithread_dispatcher ( set "multithread_dispatcher=if "%%~1" neq "" call :%%~1 "%%~2"" )
  97.         for /l %%a in (0,1,%width%)  do set "widthBuffer=!widthBuffer! "
  98.         call:updateCanvas
  99.         if exist "%temp%\cursorpos.exe" (
  100.             set "cls="%temp%\cursorpos.exe" 0 1" ) else ( set "cls=cls" )
  101.         mode con: cols=%cols% lines=%rows%
  102.         title %title%
  103.     goto :eof
  104.    
  105.     :saveCanvas
  106.         if "%~2" neq "" ( if /i "%~1" equ "/f" (
  107.                 if exist "%tmp%\Canvas_%~2.txt" ( del /f /q "%tmp%\Canvas_%~2.txt" 2>nul )
  108.                 for /l %%a in (0,1,%height%) do ( echo="!_[%%a]!">>"%tmp%\Canvas_%~2.txt")
  109.                 <nul set /p ".=:: "%width%+1" "%height%+1" "%canvasChar%" "%title%" "%CAM%" "%maxX%" "%winMaxY%" ">>"%tmp%\Canvas_%~2.txt"  
  110.             ) else if /i "%~1" equ "/v" ( for /l %%a in (0,1,%height%) do ( set "tmp_%~2_[%%a]=!_[%%a]!")
  111.         ) else if /i "%~1" equ "/d" ( if exist "%tmp%\Canvas_%~2.txt" ( del /f /q "%tmp%\Canvas_%~2.txt" 2>nul ) ) )
  112.     :updateCanvas
  113.         if "%~2" neq "" ( if /i "%~1" equ "/f" ( if exist "%tmp%\Canvas_%~2.txt" (
  114.                     set "_=-1"
  115.                     for /f "tokens=*" %%a in (%tmp%\Canvas_%~2.txt) do (
  116.                         set /a "_+=1" & set "tmp_%~2_[!_!]=%%~a"
  117.                         call set "expanded_=%%tmp_%~2_[!_!]%%"
  118.                         if "!expanded_:~0,2!" equ "::" call:canvas !expanded_:~3!
  119.                     )
  120.                     call:updateCanvas /v %~2
  121.                 )
  122.             ) else if /i "%~1" equ "/v" ( for /l %%a in (0,1,%height%) do ( set "_[%%a]=!tmp_%~2_[%%a]!" ) )
  123.         ) else ( for /l %%a in (0,1,%height%) do ( set "_[%%a]=%widthBuffer%" ) )
  124.     goto :eof
  125.  
  126.     :showCanvas
  127.         %cls%
  128.         echo= %outerBuffer%
  129.         if /i "%CAM%" neq "/c" (
  130.             for /l %%a in (0,1,%height%) do ( echo= %canvasChar:~0,1%!_[%%a]!%canvasChar:~0,1%)
  131.         ) else if "%~3" neq "" (
  132.             set /a "maxY=CAM_Y + winMaxY", "_line=%~1 + 1" & if !maxY! gtr %height% set /a "maxY=height"
  133.             for /l %%a in (!CAM_Y!,1,!maxY!) do (
  134.                 set "line=!_[%%a]!"
  135.                 if "%%a" equ "%~2" call set "line=!line:~0,%~1!%~3%%line:~!_line!%%"
  136.                 echo= !canvasChar:~0,1!!line:~%CAM_X%,%maxX%!!canvasChar:~0,1!
  137.             )
  138.         ) else echo Missing Parameters
  139.         echo= %outerBuffer%
  140.     goto :eof
  141.    
  142.     :adjustCamera
  143.         set /a "CAM_X=%~1 - (maxX / 2)", "CAM_Y=%~2 - (winMaxY / 2)"
  144.         if %CAM_X% leq 0 set CAM_X=0
  145.         if %CAM_Y% leq 0 set CAM_Y=0
  146.     goto :eof
  147.    
  148.     :multiThread
  149.         if exist "%temp%\%~n0_signal.txt" del "%temp%\%~n0_signal.txt"
  150.         "%~F0" Controller %~2 >"%temp%\%!!|%~F0" %1 <"%temp%\%~n0_signal.txt"
  151.     goto :eof
  152.    
  153.     :Controller
  154.         ( for /l %%# in () do ( for /f "tokens=*" %%a in ('choice /c:%~1 /n') do ( <nul set /p ".=%%a" ) ) )
  155. goto :eof
  156.  
  157.  
  158. :macros
  159. :: Canvas Macros -------------------------------------------------------------------
  160. set plot=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-3" %%1 in ("^!args^!") do (%\n%
  161.     set /a "_y=%%2", "_x=%%1", "_x2=%%1 + 1"%\n%
  162.     for /f "tokens=1-4" %%a in ("_y ^!_y^! ^!_x^! ^!_x2^!") do set "_[^!%%a^!]=^!_[%%b]:~0,%%c^!%%3^!_[%%b]:~%%d^!"%\n%
  163. )) else set args=
  164.  
  165. :: End Canvas Macros ---------------------------------------------------------------
  166.  
  167. :: Engine Macros -------------------------------------------------------------------
  168. set move=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-7" %%1 in ("^!args^!") do (%\n%
  169.            if /i "^!com^!" equ "%%1" (  call :checkSpace %%5 %%6-1 ^&^& set /a "%%6-=1"%\n%
  170.     ) else if /i "^!com^!" equ "%%2" (  call :checkSpace %%5-1 %%6 ^&^& set /a "%%5-=1"%\n%
  171.     ) else if /i "^!com^!" equ "%%3" (  call :checkSpace %%5 %%6+1 ^&^& set /a "%%6+=1"%\n%
  172.     ) else if /i "^!com^!" equ "%%4" (  call :checkSpace %%5+1 %%6 ^&^& set /a "%%5+=1")%\n%
  173.     if "%%7" neq "" ( ^!plot^! %%5 %%6 %%7 )%\n%
  174. )) else set args=
  175.  
  176. :: End Engine Macros ---------------------------------------------------------------
  177. goto :eof
  178.  
  179. :map
  180. for %%a in ("лллллллллллллллллллллллллллллллллллллллллллллллллл"
  181.             "лллллллллллллллллллллллллллллллллллллллллллллллл л"
  182.             "лллллллллллллллллллллллллллллллллллллллллллллллл л"
  183.             "ллллл        T ллл             ллллллллллллллллл л"
  184.             "ллллл ллллллллл                   лллллллллллллл л"
  185.             "ллллл лллллллл      ллллллллл      ллллллллллллл л"
  186.             "ллллл лллллл     лл           лл     ллллллллллл л"
  187.             "ллллл          л                 л    лллллллллл л"
  188.             "ллллллллл    л                     л    лллллллл л"
  189.             "лллллллл    л                       л    ллллллл л"
  190.             "лллллллл   л                         л   ллллллл л"
  191.             "ллллллл   л                           л   лллллл л"
  192.             "лллллл   л                             л   ллллл л"
  193.             "лллллл  л                               л  ллллл л"
  194.             "ллллл                                       лллл л"
  195.             "лллл   л             ллллллл             л   ллл л"
  196.             "лллл               лл       лл               ллл л"
  197.             "лллл  л           л           л           л  ллл л"
  198.             "ллл   л          л             л          л   лл л"
  199.             "ллл             л               л             лллл"
  200.             "ллл  л          л     ллллл     л          л  лллл"
  201.             "ллл  л         л     лллDллл     л         л  лллл"
  202.             "ллл  л         л    лллл ллл     л         л  лллл"
  203.             "ллл  л         л    лллл лллл              л  лллл"
  204.             "ллл  л         л    лллл                   л  лллл"
  205.             "ллл  л         л    ллллллллл              л  лллл"
  206.             "ллл  л         л    ллллллллл    л         л  лллл"
  207.             "ллл  л         л     ллллллл     л         л  лллл"
  208.             "ллл  л          л     ллллл     л          л  лллл"
  209.             "ллл             л               л             лллл"
  210.             "ллл   л          л             л          л   лл л"
  211.             "лллл  л           л           л           л  ллл л"
  212.             "лллл               лл       лл               ллл л"
  213.             "лллл   л             ллллллл             л   ллл л"
  214.             "ллллл                                       лллл л"
  215.             "лллллл  л                               л  ллллл л"
  216.             "лллллл   л                             л   ллллл л"
  217.             "ллллллл   л                           л   лллллл л"
  218.             "лллллллл   л                         л   ллллллл л"
  219.             "лллллллл    л                       л    ллллллл л"
  220.             "ллллллллл    л                     л    лллллллл л"
  221.             "ллллллллллл    л                 л    лллллллллл л"
  222.             "лллллллллллл     лл           лл     ллллллллллл л"
  223.             "лллллллллллллл      ллллллллл      ллллллллллллл л"
  224.             "ллллллллллллллл                   лллллллллллллл л"
  225.             "лллллллллллллллллл             ллллллллллллллллл л"
  226.             "лллллллллллллллллллллллллллллллллллллллллллллллл л"
  227.             "лллллллллллллллллллллллллллллллллллллллллллллллл л"
  228.             "л                  ллллллллллл                   л"
  229.             "лллллллллллллллллллллллллллллллллллллллллллллллллл"
  230.             ":: "49+1" "49+1" "#" "Game" "/c" "40" "40" "
  231. ) do echo %%~a>>%temp%\Canvas_3.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement