Advertisement
IcarusLives

Game Skeleton

Sep 8th, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 6.97 KB | None | 0 0
  1. @echo off & setlocal enableDelayedExpansion
  2. prompt $g
  3.  
  4. if /i "%controller%" equ "enabled" if "%~1" neq "" goto :%~1
  5.  
  6. REM INITIALIZE -----------------------------------------------------------------------------
  7. call :macros
  8.  
  9. set /a "hei=50", "wid=50"
  10.  
  11. mode %wid%,%hei%
  12. set "controller=enabled"
  13. set "controls=WASDE"
  14.  
  15.  
  16. rem initialize your variables here
  17.  
  18.     set "attack=false"
  19.     set /a "x=25", "y=25", "par=0", "atkFrameGap=160", "attackLeap=1"
  20.     set /a "health=maxhealth=100"
  21.    
  22.     set /a "mx=45", "my=45"
  23.  
  24. rem ------------------------------
  25.  
  26.  
  27.  
  28.  
  29. rem Û start multi-thread engine, Piping :controller into :GAME_ENGINE
  30. REM ----------------------------------------------------------------------------------------
  31. if /i "%controller%" equ "enabled" (
  32.     if exist "%temp%\%~n0_signal.txt" del "%temp%\%~n0_signal.txt"
  33.     "%~F0" Controller %controls% >"%temp%\%!!|%~F0" GAME_ENGINE <"%temp%\%~n0_signal.txt"
  34. )
  35. :GAME_ENGINE
  36.     for /l %%# in () do (       if !frame! leq 10000000 ( set /a "frame+=1" ) else set "frame=0"
  37.    
  38.         rem User Controller -----------------------------------------------------------------------------
  39.             if /i "%controller%" equ "enabled" set "com=" & set /p "com="
  40.    
  41.             if "!attack!" neq "true" (
  42.                        if /i "!com!" equ "w" ( set /a "par=270", "x+=2 * !cos(x):x=par!", "y+=2 * !sin(x):x=par!"
  43.                 ) else if /i "!com!" equ "a" ( set /a "par=180", "x+=2 * !cos(x):x=par!", "y+=2 * !sin(x):x=par!"
  44.                 ) else if /i "!com!" equ "s" ( set /a "par=90" , "x+=2 * !cos(x):x=par!", "y+=2 * !sin(x):x=par!"
  45.                 ) else if /i "!com!" equ "d" ( set /a "par=0"  , "x+=2 * !cos(x):x=par!", "y+=2 * !sin(x):x=par!"
  46.                 ) else if /i "!com!" equ "e" (
  47.                     set "attack=true"
  48.                     set /a "endAtkFrame=frame + atkFrameGap", "pushPos_x=x", "pushPos_y=y", "pushPos_a=par"
  49.                     set /a "x+=(attackLeap + 1) * !cos(x):x=par!", "y+=(attackLeap + 1) * !sin(x):x=par!"
  50.                     set /a "sx=x + 2 * !cos(x):x=par!", "sy=y + 2 * !sin(x):x=par!", "endSwrdFrame=frame + (atkFrameGap / 2)"
  51.                 )
  52.                 if !x! leq 0 ( set /a "x=0" ) else if !x! geq %wid% ( set /a "x=wid" )
  53.                 if !y! leq 0 ( set /a "y=0" ) else if !y! geq %hei% ( set /a "y=hei" )
  54.             ) else if "!attack!" equ "true" if !frame! equ !endAtkFrame! (
  55.                 set /a "x=pushPos_x", "y=pushPos_y", "par=pushPos_a"
  56.                 set "attack=false"
  57.             ) else (
  58.                        if !frame! lss !endSwrdFrame! ( %plot% !sx! !sy! 7 /
  59.                 ) else if !frame! gtr !endSwrdFrame! ( %plot% !sx! !sy! 7 \ )
  60.             )
  61.            
  62.             %plot% !x! !y! 21 Û
  63.         rem ---------------------------------------------------------------------------------------------
  64.            
  65.         rem Monster movement ----------------------------------------------------------------------------
  66.             set /a "mm=frame %% 180"
  67.             if !mm! equ 0 ( set /a "rmm=!random! %% 4" ) else set /a "rmm=5"
  68.                    if !rmm! equ 0 ( set /a "mx-=1"
  69.             ) else if !rmm! equ 1 ( set /a "mx+=1"
  70.             ) else if !rmm! equ 2 ( set /a "my-=1"
  71.             ) else if !rmm! equ 3 ( set /a "my+=1" )
  72.             if !mx! leq 0 ( set /a "mx=0" ) else if !mx! geq %wid% ( set /a "mx=wid" )
  73.             if !my! leq 0 ( set /a "my=0" ) else if !my! geq %hei% ( set /a "my=hei" )
  74.             %plot% !mx! !my! 9 M
  75.         rem ---------------------------------------------------------------------------------------------
  76.        
  77.         rem Player - Monster interaction ----------------------------------------------------------------
  78.             %getDistance% mx x my y monsterDistance
  79.             %getDistance% mx sx my sy monsterHitDistance
  80.            
  81.             set /a "monsterDamageMod=frame %% 10"
  82.             if !monsterDamageMod! equ 0 if !monsterDistance! equ 0 set /a "health-=1"
  83.             if !health! equ 0 <nul set /p "=%esc%[2J%esc%[25;20H YOU DIED" & pause > nul & exit
  84.             if !monsterHitDistance! equ 0 set /a "mx=0", "my=0"
  85.         rem ---------------------------------------------------------------------------------------------
  86.  
  87.         rem display everything using VT100 2J sequence to clear the screen first. -----------------------
  88.             <nul set /p "=%esc%[2J!screen!%esc%[5;5HHealth = !health!/!maxhealth!" & set "screen="
  89.         rem ---------------------------------------------------------------------------------------------
  90.        
  91.     )
  92.     pause
  93. exit
  94.  
  95. :Controller
  96.     if /i "%controller%" equ "enabled" (
  97.         for /l %%# in () do for /f "tokens=*" %%a in ('choice /c:%~2 /n') do <nul set /p ".=%%a"
  98.     )
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. :macros
  108. (set \n=^^^
  109. %= This creates an escaped Line Feed - DO NOT ALTER =%
  110. )
  111. for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
  112. <nul set /p "=!esc![?25l"
  113.  
  114. rem %plot% x y 0-255 CHAR
  115. set plot=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-4" %%1 in ("^!args^!") do (%\n%
  116.   set "screen=^!screen^!!esc![%%2;%%1H!esc![38;5;%%3m%%~4!esc![0m"%\n%
  117. )) else set args=
  118.  
  119. rem %getDistance% x2 x1 y2 y1 RETURNVAR
  120. set getDistance=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
  121.    set /a "%%5=( ?=((((((%%1 - %%2))>>31|1)*((%%1 - %%2)))-((((%%3 - %%4))>>31|1)*((%%3 - %%4))))>>31)+1, ?*(2*((((%%1 - %%2))>>31|1)*((%%1 - %%2)))-((((%%3 - %%4))>>31|1)*((%%3 - %%4)))-(((((%%1 - %%2))>>31|1)*((%%1 - %%2)))-((((%%3 - %%4))>>31|1)*((%%3 - %%4))))) + ^^^!?*(((((%%1 - %%2))>>31|1)*((%%1 - %%2)))-((((%%3 - %%4))>>31|1)*((%%3 - %%4)))-(((((%%1 - %%2))>>31|1)*((%%1 - %%2)))-((((%%3 - %%4))>>31|1)*((%%3 - %%4)))*2)) )"%\n%
  122. )) else set args=
  123.  
  124. rem line x1 y1 x2 y2 color
  125. set line=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
  126.     if "%%~5" equ "" ( set "hue=30" ) else ( set "hue=%%~5")%\n%
  127.     set /a "xa=%%~1", "ya=%%~2", "xb=%%~3", "yb=%%~4", "dx=%%~3 - %%~1", "dy=%%~4 - %%~2"%\n%
  128.     for /f "tokens=1-2" %%6 in ("^!dx^! ^!dy^!") do (%\n%
  129.         if %%~7 lss 0 ( set /a "dy=-%%~7", "stepy=-1" ) else ( set "stepy=1" )%\n%
  130.         if %%~6 lss 0 ( set /a "dx=-%%~6", "stepx=-1" ) else ( set "stepx=1" )%\n%
  131.         set /a "dx<<=1", "dy<<=1"%\n%
  132.     )%\n%
  133.     for /f "tokens=1-9" %%a in ("^!dx^! ^!dy^! ^!xa^! ^!xb^! ^!ya^! ^!yb^! ^!stepx^! ^!stepy^! ^!hue^!") do (%\n%
  134.         if %%~a gtr %%~b (%\n%
  135.             set /a "fraction=%%~b - (%%~a >> 1)"%\n%
  136.             for /l %%x in (%%~c,%%~g,%%~d) do (%\n%
  137.                 for /f "tokens=1" %%6 in ("^!fraction^!") do if %%~6 geq 0 set /a "ya+=%%~h", "fraction-=%%~a"%\n%
  138.                 set /a "fraction+=%%~b"%\n%
  139.                 for /f "tokens=1" %%6 in ("^!ya^!") do ^!plot^! %%x %%~6 %%i Û%\n%
  140.             )%\n%
  141.         ) else (%\n%
  142.             set /a "fraction=%%~a - (%%~b >> 1)"%\n%
  143.             for /l %%y in (%%~e,%%~h,%%~f) do (%\n%
  144.                 for /f "tokens=1" %%6 in ("^!fraction^!") do if %%~6 geq 0 set /a "xa+=%%~g", "fraction-=%%~b"%\n%
  145.                 set /a "fraction+=%%~a"%\n%
  146.                 for /f "tokens=1" %%6 in ("^!xa^!") do ^!plot^! %%~6 %%y %%i Û%\n%
  147.             )%\n%
  148.         )%\n%
  149.     )%\n%
  150. )) else set args=
  151.  
  152. set "_SIN=a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000"
  153. set "SIN(x)=(a=(x * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832)  +  (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a)  ), %_SIN%) / 10000"
  154. set "COS(x)=(a=(15708 - x * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832)  +  (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a)  ), %_SIN%) / 10000"
  155. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement