Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & setlocal enableDelayedExpansion
- prompt $g
- if /i "%controller%" equ "enabled" if "%~1" neq "" goto :%~1
- REM INITIALIZE -----------------------------------------------------------------------------
- call :macros
- set /a "hei=50", "wid=50"
- mode %wid%,%hei%
- set "controller=enabled"
- set "controls=WASDE"
- rem initialize your variables here
- set "attack=false"
- set /a "x=25", "y=25", "par=0", "atkFrameGap=160", "attackLeap=1"
- set /a "health=maxhealth=100"
- set /a "mx=45", "my=45"
- rem ------------------------------
- rem Û start multi-thread engine, Piping :controller into :GAME_ENGINE
- REM ----------------------------------------------------------------------------------------
- if /i "%controller%" equ "enabled" (
- if exist "%temp%\%~n0_signal.txt" del "%temp%\%~n0_signal.txt"
- "%~F0" Controller %controls% >"%temp%\%!!|%~F0" GAME_ENGINE <"%temp%\%~n0_signal.txt"
- )
- :GAME_ENGINE
- for /l %%# in () do ( if !frame! leq 10000000 ( set /a "frame+=1" ) else set "frame=0"
- rem User Controller -----------------------------------------------------------------------------
- if /i "%controller%" equ "enabled" set "com=" & set /p "com="
- if "!attack!" neq "true" (
- if /i "!com!" equ "w" ( set /a "par=270", "x+=2 * !cos(x):x=par!", "y+=2 * !sin(x):x=par!"
- ) else if /i "!com!" equ "a" ( set /a "par=180", "x+=2 * !cos(x):x=par!", "y+=2 * !sin(x):x=par!"
- ) else if /i "!com!" equ "s" ( set /a "par=90" , "x+=2 * !cos(x):x=par!", "y+=2 * !sin(x):x=par!"
- ) else if /i "!com!" equ "d" ( set /a "par=0" , "x+=2 * !cos(x):x=par!", "y+=2 * !sin(x):x=par!"
- ) else if /i "!com!" equ "e" (
- set "attack=true"
- set /a "endAtkFrame=frame + atkFrameGap", "pushPos_x=x", "pushPos_y=y", "pushPos_a=par"
- set /a "x+=(attackLeap + 1) * !cos(x):x=par!", "y+=(attackLeap + 1) * !sin(x):x=par!"
- set /a "sx=x + 2 * !cos(x):x=par!", "sy=y + 2 * !sin(x):x=par!", "endSwrdFrame=frame + (atkFrameGap / 2)"
- )
- if !x! leq 0 ( set /a "x=0" ) else if !x! geq %wid% ( set /a "x=wid" )
- if !y! leq 0 ( set /a "y=0" ) else if !y! geq %hei% ( set /a "y=hei" )
- ) else if "!attack!" equ "true" if !frame! equ !endAtkFrame! (
- set /a "x=pushPos_x", "y=pushPos_y", "par=pushPos_a"
- set "attack=false"
- ) else (
- if !frame! lss !endSwrdFrame! ( %plot% !sx! !sy! 7 /
- ) else if !frame! gtr !endSwrdFrame! ( %plot% !sx! !sy! 7 \ )
- )
- %plot% !x! !y! 21 Û
- rem ---------------------------------------------------------------------------------------------
- rem Monster movement ----------------------------------------------------------------------------
- set /a "mm=frame %% 180"
- if !mm! equ 0 ( set /a "rmm=!random! %% 4" ) else set /a "rmm=5"
- if !rmm! equ 0 ( set /a "mx-=1"
- ) else if !rmm! equ 1 ( set /a "mx+=1"
- ) else if !rmm! equ 2 ( set /a "my-=1"
- ) else if !rmm! equ 3 ( set /a "my+=1" )
- if !mx! leq 0 ( set /a "mx=0" ) else if !mx! geq %wid% ( set /a "mx=wid" )
- if !my! leq 0 ( set /a "my=0" ) else if !my! geq %hei% ( set /a "my=hei" )
- %plot% !mx! !my! 9 M
- rem ---------------------------------------------------------------------------------------------
- rem Player - Monster interaction ----------------------------------------------------------------
- %getDistance% mx x my y monsterDistance
- %getDistance% mx sx my sy monsterHitDistance
- set /a "monsterDamageMod=frame %% 10"
- if !monsterDamageMod! equ 0 if !monsterDistance! equ 0 set /a "health-=1"
- if !health! equ 0 <nul set /p "=%esc%[2J%esc%[25;20H YOU DIED" & pause > nul & exit
- if !monsterHitDistance! equ 0 set /a "mx=0", "my=0"
- rem ---------------------------------------------------------------------------------------------
- rem display everything using VT100 2J sequence to clear the screen first. -----------------------
- <nul set /p "=%esc%[2J!screen!%esc%[5;5HHealth = !health!/!maxhealth!" & set "screen="
- rem ---------------------------------------------------------------------------------------------
- )
- pause
- exit
- :Controller
- if /i "%controller%" equ "enabled" (
- for /l %%# in () do for /f "tokens=*" %%a in ('choice /c:%~2 /n') do <nul set /p ".=%%a"
- )
- :macros
- (set \n=^^^
- %= This creates an escaped Line Feed - DO NOT ALTER =%
- )
- for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
- <nul set /p "=!esc![?25l"
- rem %plot% x y 0-255 CHAR
- set plot=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-4" %%1 in ("^!args^!") do (%\n%
- set "screen=^!screen^!!esc![%%2;%%1H!esc![38;5;%%3m%%~4!esc![0m"%\n%
- )) else set args=
- rem %getDistance% x2 x1 y2 y1 RETURNVAR
- set getDistance=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
- 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%
- )) else set args=
- rem line x1 y1 x2 y2 color
- set line=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
- if "%%~5" equ "" ( set "hue=30" ) else ( set "hue=%%~5")%\n%
- set /a "xa=%%~1", "ya=%%~2", "xb=%%~3", "yb=%%~4", "dx=%%~3 - %%~1", "dy=%%~4 - %%~2"%\n%
- for /f "tokens=1-2" %%6 in ("^!dx^! ^!dy^!") do (%\n%
- if %%~7 lss 0 ( set /a "dy=-%%~7", "stepy=-1" ) else ( set "stepy=1" )%\n%
- if %%~6 lss 0 ( set /a "dx=-%%~6", "stepx=-1" ) else ( set "stepx=1" )%\n%
- set /a "dx<<=1", "dy<<=1"%\n%
- )%\n%
- for /f "tokens=1-9" %%a in ("^!dx^! ^!dy^! ^!xa^! ^!xb^! ^!ya^! ^!yb^! ^!stepx^! ^!stepy^! ^!hue^!") do (%\n%
- if %%~a gtr %%~b (%\n%
- set /a "fraction=%%~b - (%%~a >> 1)"%\n%
- for /l %%x in (%%~c,%%~g,%%~d) do (%\n%
- for /f "tokens=1" %%6 in ("^!fraction^!") do if %%~6 geq 0 set /a "ya+=%%~h", "fraction-=%%~a"%\n%
- set /a "fraction+=%%~b"%\n%
- for /f "tokens=1" %%6 in ("^!ya^!") do ^!plot^! %%x %%~6 %%i Û%\n%
- )%\n%
- ) else (%\n%
- set /a "fraction=%%~a - (%%~b >> 1)"%\n%
- for /l %%y in (%%~e,%%~h,%%~f) do (%\n%
- for /f "tokens=1" %%6 in ("^!fraction^!") do if %%~6 geq 0 set /a "xa+=%%~g", "fraction-=%%~b"%\n%
- set /a "fraction+=%%~a"%\n%
- for /f "tokens=1" %%6 in ("^!xa^!") do ^!plot^! %%~6 %%y %%i Û%\n%
- )%\n%
- )%\n%
- )%\n%
- )) else set args=
- 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"
- 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"
- 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"
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement