Dec 19, 2016 08:37 PM
(This post was last modified: Apr 21, 2017 10:39 PM by ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™.)
IMPORTANT: Make sure to save your encoding as ANSI to display the characters correctly.
Spoiler (Click to View)
![[Image: c3199ad685544e66789a5c2188d14386.gif]](https://gyazo.com/c3199ad685544e66789a5c2188d14386.gif)
GAME
Library.bat
Current release:
GIF 1
Spoiler (Click to View)![[Image: 4c40dcfd9c9397d0a3b516c8dff844e0.gif]](https://i.gyazo.com/4c40dcfd9c9397d0a3b516c8dff844e0.gif)
GIF 2
Spoiler (Click to View)![[Image: 4095ceea3f803e44caac77cf27228b85.gif]](https://gyazo.com/4095ceea3f803e44caac77cf27228b85.gif)
GIF 3
Spoiler (Click to View)![[Image: 20b8451d7081343a21135d5caa9c370a.gif]](https://gyazo.com/20b8451d7081343a21135d5caa9c370a.gif)
Hello all ^-^
I have been working on a neat project lately. It started with experimentation using an external library, which I will be posting below. Using this library has actually made scripts substantially easier to read. The library itself consist of nothing but functions. In the script that uses it, it swaps names with it, and is able to use all the functions on the inside AND continue coding as normal. This library has to be initialized, and then used as if they were parenthesis.
Spoiler (Click to View)
Then I ended up turning this into a multi threaded roguelike game ^_^ This is a BETA if it's anything at all. But it's quite neat ^-^
Library.bat
Spoiler (Click to View)
Beta.bat ( See Lines 34,35,48-63 for use of Library)
Spoiler (Click to View)
Spoiler (Click to View)
![[Image: c3199ad685544e66789a5c2188d14386.gif]](https://gyazo.com/c3199ad685544e66789a5c2188d14386.gif)
GAME
Code
@echo off & setlocal enableDelayedExpansion
prompt %g
REM set /a "skip+=1"
REM if "%skip%" equ "1" goto :getDifficulty
if not "%~1" equ "" goto :%1
( start /b cmd /c "%~nx0" main_2 ) | "%~nx0" init_main
goto :eof
:init_main
call :init
:main
call :display
call :moveMonsters
if exist "thread2.txt" call :getPlayerInfo
call :calcFPS
goto :main
:main_2
set "playerMove="
for /f "tokens=*" %%a in ('choice /c:wasd /n') do set "playerMove=%%a"
(
echo !playerMove!
)>"thread2.txt"
goto :main_2
:init
set LF=^
::above 2 blank lines are critical - do not remove.
set "openLib=( ren "%~nx0" orig-main.bat & ren library.bat "%~nx0""
set "closeLib=ren "%~nx0" library.bat & ren orig-main.bat "%~nx0" )"
set /a "maxLife=3", "life[I]=maxLife"
set "wall=Û"
set "monster=M"
set "coin=$"
call :hexPrint 0x03 life
call :hexPrint 0x06 potion
call :hexPrint 0x04 diamond
:reset
%openLib%
call :emptyVarEnviornment "tmp xPos yPos wall coin life potion monster maxLife life[I] points pb FF BS BEL pbb"
call :specialChars
call :drawMap_2_init 94 34
set /a "xPos=42", "yPos=4"
call :drawMap_2 "Û" "36,1,12,5" "n,n,6,n" /s
call :drawMap_2 "Û" "0,3,8,16" "n,n,n,8"
call :drawMap_2 "Û" "0,1,30,6" "n,n,4,n"
call :drawMap_2 "Û" "40,18,17,13" "10,9,n,10"
call :drawMap_2 "Û" "0,14,45,10" "4,n,23,n"
call :drawMap_2 "Û" "53,1,12,23" "n,10,n,n"
call :drawMap_2 "Û" "68,3,22,6" "n,n,14,n"
call :placeObjects 70 "%wall%"
call :placeObjects 20 "%coin%"
call :placeObjects 5 "%diamond%"
call :placeObjects 7 "%potion%"
call :placeObjects 20 "%monster%" /r
for /l %%a in (47,1,52) do call :changePixel "Û" %%a 25
for /l %%a in (10,1,52) do call :changePixel "+" %%a 11
for /l %%a in (23,1,39) do call :changePixel "+" %%a 27
for /l %%a in (59,1,81) do call :changePixel "+" %%a 28
for /l %%a in (11,1,28) do call :changePixel "+" 82 %%a
for /l %%a in (11,1,17) do call :changePixel "+" 50 %%a
for /l %%a in (11,1,17) do call :changePixel "+" 50 %%a
for /l %%a in (8,1,11) do call :changePixel "+" 42 %%a
call :changePixel "+" 23 26
set /a "lifeChance=!random! %% 100 + 1"
if !lifeChance! lss 20 call :changePixel "%life%" 90 4
call :getBuffer "1,1,5" " " push
call :getBuffer "1,1,6" " " pb
call :getBuffer "1,1,%life[I]%" "%life%" life[D]
%closeLib%
for %%a in ("CAM_minY=1" "CAM_maxY=10" "CAM_minX=26" "CAM_maxX=32") do set "%%~a"
set /a "defCAM_minY=1", "defCAM_maxY=dispNo", "defCAM_minX=1", "defCAM_maxX=(conBuff / 2) + CAM_maxX - 9"
set box[ >vars.txt
set "lifeChance="
call :prep_calcFPS 10
mode con: cols=35 lines=20
color F0
goto :eof
:display
cls
echo W,A,S,D to move
echo. & echo %push%Life: %life[D]%
<nul set /p ".=.%bs%%push%Key =
if "%gotKey%" equ "true" ( <nul set /p ".=.%bs%%FF%" & echo !pb!%bs%Points = !points!) else echo !pb!Points = !points!
echo ----------------------------------
set /a "addOne=xPos + 1"
(
for /l %%a in (!CAM_minY!,1,!CAM_maxY!) do (
set "line=!L[%%a]!"
if "%%a" equ "!yPos!" set "line=!line:~0,%xPos%!!line:~%addOne%!"
echo=^|!line:~%CAM_minX%,%CAM_maxX%!^|
)
)
echo ----------------------------------
echo X %xPos%
echo min X %CAM_minX%
echo max X %defCAM_maxX%
goto :eof
:getPlayerInfo
< thread2.txt ( set /p "playerMove=" )
if defined playerMove call :controls !playerMove!
set "playerMove="
del /f /q "thread2.txt"
goto :eof
::------------------------------------------------------------------------------
:controls
(
if /i "%1" equ "W" (
set /a "testY=yPos - 1"
call :collisionCheck !testY! !xPos!
if !error! equ 0 (
set /a "yPos-=1"
set /a "CAM_minY-=1", "CAM_maxY-=1"
if !CAM_minY! lss !defCAM_minY! set /a "CAM_maxY+=1", "CAM_minY=!defCAM_minY!"
)
)
if /i "%1" equ "S" (
set /a "testY=yPos + 1"
call :collisionCheck !testY! !xPos!
if !error! equ 0 (
set /a "yPos+=1"
set /a "CAM_minY+=1", "CAM_maxY+=1"
if !CAM_maxY! gtr !defCAM_maxY! set /a "CAM_minY-=1", "CAM_maxY=!defCAM_maxY!"
)
)
if /i "%1" equ "A" (
set /a "testX=xPos - 1"
call :collisionCheck !yPos! !testX!
if !error! equ 0 (
set /a "xPos-=1"
set /a "CAM_minX-=1"
if !CAM_minX! leq 0 set "CAM_minX=0"
)
)
if /i "%1" equ "D" (
set /a "testX=xPos + 1"
call :collisionCheck !yPos! !testX!
if !error! equ 0 (
REM if !CAM_minX! equ 0 if !xPos! lss 17 (
REM set /a "xPos+=1"
REM ) else (
set /a "xPos+=1"
set /a "CAM_minX+=1"
)
if !CAM_minX! geq !defCAM_maxX! set "CAM_minX=!defCAM_maxX!"
)
)
)
set "error=0"& set "testY=" & set "testX="
goto :eof
::------------------------------------------------------------------------------
:collisionCheck
set /a "Y=%1", "X=%2", "error=0"
(
if "!L[%Y%]:~%X%,1!" equ "%wall%" (
set error=1
goto :eof
)
if "!L[%Y%]:~%X%,1!" equ "K" (
call :replacePixel !x! !y!
set "gotKey=true"
goto :eof
)
if "!L[%Y%]:~%X%,1!" equ "%coin%" (
echo %bel%
set /a "points+=1"
call :replacePixel !x! !y!
goto :eof
)
if "!L[%Y%]:~%X%,1!" equ "D" (
if "!gotKey!" equ "true" (
goto :reset
goto :eof
) else (
echo You need a key
%openLib% & call :delay 60 & %closeLib%
goto :eof
)
)
if "!L[%Y%]:~%X%,1!" equ "%life%" (
set /a "maxLife+=1", "life[I]=!maxLife!"
set "life[D]=!life[D]!%life%"
call :replacePixel !x! !y!
goto :eof
)
if "!L[%Y%]:~%X%,1!" equ "%potion%" (
if !life[I]! lss %maxLife% (
set /a "life[I]+=1"
set "life[D]=!life[D]!%life%"
call :replacePixel !x! !y!
goto :eof
)
)
if "!L[%Y%]:~%X%,1!" equ "%diamond%" (
echo %bel%
set /a "points+=10"
call :replacePixel !x! !y!
goto :eof
)
if "!L[%Y%]:~%X%,1!" equ "M" (
set /a "life[I]-=1"
set "life[D]=!life[D]:~0,-1!"
if !life[I]! equ 0 (
echo You have died.
%openLib% & call :delay 20 & %closeLib%
exit
)
call :replacePixel !x! !y!
goto :eof
)
)
goto :eof
::------------------------------------------------------------------------------
:moveMonsters
( for /l %%a in (1,1,%pOCount%) do (
for /f "tokens=1,2 delims=," %%1 in ("!pO[M][%%a]!") do (
set /a "monsterMove=!random! %% 4 + 1", "aOmM=%%1 + 1"
call :replacePixel %%1 %%2
if "!monsterMove!" equ "1" (
set /a "mUpTest=%%2 - 1"
call :M_collisionCheck %%1 !mUpTest!
if "!mError!" equ "0" (
set "pO[M][%%a]=%%1,!mUpTest!"
call set "L[!mUpTest!]=%%L[!mUpTest!]:~0,%%1%%M%%L[!mUpTest!]:~!aOmM!%%"
)
) else if "!monsterMove!" equ "2" (
set /a "mDownTest=%%2 + 1"
call :M_collisionCheck %%1 !mDownTest!
if "!mError!" equ "0" (
set "pO[M][%%a]=%%1,!mDownTest!"
call set "L[!mDownTest!]=%%L[!mDownTest!]:~0,%%1%%M%%L[!mDownTest!]:~!aOmM!%%"
)
) else if "!monsterMove!" equ "3" (
set /a "mRightTest=%%1 + 1"
set /a "aOmM=mRightTest + 1"
call :M_collisionCheck !mRightTest! %%2
if "!mError!" equ "0" (
set "pO[M][%%a]=!mRightTest!,%%2"
call set "L[%%2]=%%L[%%2]:~0,!mRightTest!%%M%%L[%%2]:~!aOmM!%%"
)
) else if "!monsterMove!" equ "4" (
set /a "mLeftTest=%%1 - 1"
set /a "aOmM=mLeftTest + 1"
call :M_collisionCheck !mLeftTest! %%2
if "!mError!" equ "0" (
set "pO[M][%%a]=!mLeftTest!,%%2"
call set "L[%%2]=%%L[%%2]:~0,!mLeftTest!%%M%%L[%%2]:~!aOmM!%%"
)
)
)
) )
for %%a in (mDownTest mRightTest mUpTest mLeftTest aOmM monsterMove) do set "%%a="
goto :eof
:M_collisionCheck
set /a "mX=%1", "mY=%2", "mError=0"
if "!L[%mY%]:~%mX%,1!" equ "%wall%" set "mError=1" & goto :eof
if "!L[%mY%]:~%mX%,1!" equ "%coin%" set "mError=1" & goto :eof
if "!L[%mY%]:~%mX%,1!" equ "K" set "mError=1" & goto :eof
if "!L[%mY%]:~%mX%,1!" equ "O" set "mError=1" & goto :eof
if "!L[%mY%]:~%mX%,1!" equ "D" set "mError=1" & goto :eof
goto :eof
:length
set "str=0%~1"
set "%2=0"
for /L %%a in (8,-1,0) do (
set /A "newLen=%2+(1<<%%a)"
for %%b in (!newLen!) do if "!str:~%%b,1!" neq "" set "%2=%%b"
)
goto :eof
:replacePixel
set /a "aorp=%1 + 1"
set "L[%2]=!L[%2]:~0,%1! !L[%~2]:~%aorp%!"
set "aorp="
goto :eof
:hexPrint string [rtnVar]
for /f eol^=^%LF%%LF%^ delims^= %%A in (
'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
) do if "%~2" neq "" (set %~2=%%A) else echo(%%A
goto :eof
:prep_calcFPS
set /A cs=100/%~1
set t=!time: =0!
goto :eof
:calcFPS
(
set tc=!time: =0!
for /F "tokens=1-8 delims=:.," %%a in ("!t!:!tc!") do (
set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000"
)
if !a! lss !cs! goto :calcFPS
if !a! gtr !cs! set /a a-=1
set t=!tc!
if !a! neq 0 (set /A fps=100/a) else set fps=?
title FPS:!fps!/s
)
goto :eofLibrary.bat
Code
@echo off & setlocal enableDelayedExpansion
::------------------------------------------------------------------------------
:: obtain special characters BS, FF, BEL
::------------------------------------------------------------------------------
:specialChars
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
>con ( for /f %%a in ('cls') do ( set "FF=%%a") )
for /f %%i in ('forfiles /m "%~nx0" /c "cmd /c echo 0x07"') do set "BEL=%%i"
goto :eof
::------------------------------------------------------------------------------
::------------------------------------------------------------------------------
:emptyVarEnviornment
set "preserve= path preserve openLib closeLib %~1 "
for /f "delims==" %%v in ('set') do if "!preserve: %%v =!" equ "!preserve!" set "%%v="
set "preserve="
goto :eof
::------------------------------------------------------------------------------
:getBuffer
for /l %%a in (%~1) do set "x=!x!%~2"
set "%3=%x%" & set "x="
goto :eof
::------------------------------------------------------------------------------
:placeObjects
set "countDown=%1"
:poL
set /a "rndX=!random! %% %conBuff% + 1", "rndY=!random! %% %dispNo% + 1"
set /a "po=!rndX! + 1"
for /l %%b in (1,1,%numberOfBoxes%) do (
for /f "tokens=1-4 delims=," %%1 in ("!box[%%b]!") do (
set /a "xl=%%1 + %%3", "yl=%%2 + %%4"
if %rndX% gtr %%1 if %rndX% lss !xl! (
if %rndY% gtr %%2 if %rndY% lss !yl! (
if "!L[%rndY%]:~%rndX%,1!" equ " " (
call set "L[!rndY!]=%%L[!rndY!]:~0,!rndX!%%%~2%%L[!rndY!]:~!po!%%"
set /a "countDown-=1"
if "%~3" equ "/r" (
set /a "pOCount+=1"
set "pO[%~2][!pOCount!]=%rndX%,%rndY%"
)
)
)
)
)
)
if !countDown! equ 0 (goto :eof ) else goto :poL
goto :eof
::------------------------------------------------------------------------------
:drawMap_2_init
set /a "conWidth=%1", "conHeight=%2", "dispNo=conHeight - 2", "conBuff=conWidth - 3"
for /l %%a in (1,1,%conBuff%) do set "buffer=!buffer! "
for /l %%a in (1,1,%dispNo%) do set "L[%%a]=%buffer%"
goto :eof
:drawMap_2
set "wall=%~1
set "doorCount=-1"
for /f "tokens=1-4 delims=,_" %%1 in ("%~2") do (
set /a "boxpos_X=%%1", "boxpos_Y=%%2", "boxLength=%%3", "boxWidth=%%4 + %%2"
if "%4" neq "/s" (
set /a "numberOfBoxes+=1"
set "box[!numberOfBoxes!]=%%1,%%2,%%3,%%4"
)
)
for /f "tokens=1-4 delims=," %%1 in ("%~3") do (
set "topPosition=%%1" & set "leftPosition=%%2"
set "bottomPosition=%%3" & set "rightPosition=%%4"
)
set /a "top=boxLength + 2", "bottom=boxWidth + 1"
if /i "%topPosition%" neq "N" (
set /a "dLP1=top - topPosition - 1"
for /l %%a in (1,1,%topPosition%) do set "top_t1=!top_t1!%wall%"
for /l %%a in (1,1,!dLP1!) do set "top_t2=!top_t2!%wall%"
)
if /i "%bottomPosition%" neq "N" (
set /a "dLP2=top - bottomPosition - 1"
for /l %%a in (1,1,%bottomPosition%) do set "bottom_t1=!bottom_t1!%wall%"
for /l %%a in (1,1,!dLP2!) do set "bottom_t2=!bottom_t2!%wall%"
)
for /l %%a in (1,1,%top%) do set "_t=!_t!%wall%"
for %%a in (t b) do set "%%a=%_t%"
if /i "%topPosition%" neq "N" set "t=%top_t1%O%top_t2%"
if /i "%bottomPosition%" neq "N" set "b=%bottom_t1%O%bottom_t2%"
for /l %%a in (1,1,%boxLength%) do set "O=!O! "
call :length "%wall%%O%%wall%" dO
set /a "defOut=boxpos_X + dO"
for /l %%a in (%boxpos_Y%,1,%boxWidth%) do (
set "L[%%a]=!L[%%a]:~0,%boxpos_X%!%wall%%O%%wall%!L[%%a]:~%defOut%!"
set /a "doorCount+=1"
if "!doorCount!" equ "%leftPosition%" (
if /i "%boxSide%" neq "N" set "L[%%a]=!L[%%a]:~0,%boxpos_X%!O%O%%wall%!L[%%a]:~%defOut%!"
)
if "!doorCount!" equ "%rightPosition%" (
if /i "%boxSide%" neq "N" set "L[%%a]=!L[%%a]:~0,%boxpos_X%!%wall%%O%O!L[%%a]:~%defOut%!"
)
)
set "L[%boxpos_Y%]=!L[%boxpos_Y%]:~0,%boxpos_X%!%t%!L[%boxpos_Y%]:~%defOut%!"
set "L[%bottom%]=!L[%bottom%]:~0,%boxpos_X%!%b%!L[%bottom%]:~%defOut%!"
for %%a in (boxpos_X boxposY boxLength boxWidth top bottom dlP1 dlP2 t b t1 t2 _t O dO defOut topPosition bottomPosition leftPosition rightPosition top_t1 top_t2 bottom_t1 bottom_t2 ) do set "%%a="
goto :eof
::------------------------------------------------------------------------------
::------------------------------------------------------------------------------
:delay
for /f "tokens=2 delims=." %%a in ("%time%") do (set "c=%%a")
if "%c:~0,1%" == "0" set "c=%c:~1%"
set /a l=%c% + %~1
:wait
set "cPrev=%c%"
for /f "tokens=2 delims=." %%a in ("%time%") do (set "c=%%a")
if "%c:~0,1%" == "0" set "c=%c:~1%"
if %cPrev% GTR %c% set /a l-=100
if %c% LSS %l% goto :wait
goto :eof
:color
set "param=^%~3" !
set "param=!param:"=\"!"
findstr /p /A:%2 "." "!param!\..\X" nul
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
if %~1 equ 1 echo.
exit /b
:length
set "str=0%~1"
set "%2=0"
for /L %%a in (8,-1,0) do (
set /A "newLen=%2+(1<<%%a)"
for %%b in (!newLen!) do if "!str:~%%b,1!" neq "" set "%2=%%b"
)
goto :eof
:changePixel
call :length %1 plusOne
set /a "x=%2", "y=%3","aorp=%2 + plusOne"
set "L[%y%]=!L[%y%]:~0,%x%!%~1!L[%y%]:~%aorp%!"
for %%a in (x y aorp plusOne) do set "%%a="
goto :eofCurrent release:
GIF 1
Spoiler (Click to View)
![[Image: 4c40dcfd9c9397d0a3b516c8dff844e0.gif]](https://i.gyazo.com/4c40dcfd9c9397d0a3b516c8dff844e0.gif)
GIF 2
Spoiler (Click to View)
![[Image: 4095ceea3f803e44caac77cf27228b85.gif]](https://gyazo.com/4095ceea3f803e44caac77cf27228b85.gif)
GIF 3
Spoiler (Click to View)
![[Image: 20b8451d7081343a21135d5caa9c370a.gif]](https://gyazo.com/20b8451d7081343a21135d5caa9c370a.gif)
Hello all ^-^
I have been working on a neat project lately. It started with experimentation using an external library, which I will be posting below. Using this library has actually made scripts substantially easier to read. The library itself consist of nothing but functions. In the script that uses it, it swaps names with it, and is able to use all the functions on the inside AND continue coding as normal. This library has to be initialized, and then used as if they were parenthesis.
Spoiler (Click to View)
Code
set "openLib=( ren "%~nx0" orig-main.bat & ren library.bat "%~nx0""
set "closeLib=ren "%~nx0" library.bat & ren orig-main.bat "%~nx0" )"
%openLib%
call :LibFunction_1 "x"
call :LibFunction_2 "x"
rem etc...
%closeLib%Then I ended up turning this into a multi threaded roguelike game ^_^ This is a BETA if it's anything at all. But it's quite neat ^-^
Library.bat
Spoiler (Click to View)
Beta.bat ( See Lines 34,35,48-63 for use of Library)
Spoiler (Click to View)


