need help with roguelike game in batch

November 6, 2013 at 15:14:59
Specs: Windows 7
here is my code...so far ive got a good start to this test game now I was just wondering if someone could add entities to the code...that follow the character around...or kill the character by getting right next to it...please feel free to ask any questions that may help you in finding the answer to my problem
here it is---don't worry about the basement just add the entity to the first room... or nextroom
@echo off

:nextroom
set VALUE=143
call :template
set g143=@
goto display2

:nextroomone
set VALUE=50
call :template
set g50=@
goto display2

:template
set bvalue=0
set g1=#
set g2=#
set g3=#
set g4=#
set g5=#
set g6=#
set g7=#
set g8=#
set g9=#
set g10=#
set g11=#
set g12=#
set g13=#
set g14=#
set g15=#
set g16=#
set g17=#
set g18=#
set g19=#
set g20=#
set g21=#
set g22=.
set g23=.
set g24=.
set g25=.
set g26=.
set g27=.
set g28=.
set g29=.
set g30=_
set g31=.
set g32=.
set g33=.
set g34=.
set g35=.
set g36=.
set g37=.
set g38=.
set g39=.
set g40=#
set g41=#
set g42=.
set g43=.
set g44=.
set g45=.
set g46=.
set g47=.
set g48=.
set g49=#
set v49=49
set g50=V
set g51=#
set v51=51
set g52=.
set g53=.
set g54=.
set g55=.
set g56=.
set g57=.
set g58=.
set g59=.
set g60=#
set g61=#
set g62=.
set g63=.
set g64=.
set g65=.
set g66=.
set g67=.
set g68=.
set g69=#
set v69=69
set g70=#
set v70=70
set g71=#
set v71=71
set g72=.
set g73=.
set g74=.
set g75=.
set g76=.
set g77=.
set g78=.
set g79=.
set g80=#
set g81=#
set g82=.
set g83=.
set g84=.
set g85=.
set g86=.
set g87=.
set g88=.
set g89=.
set g90=.
set g91=.
set g92=.
set g93=.
set g94=.
set g95=.
set g96=.
set g97=.
set g98=.
set g99=.
set g100=#
set g101=#
set g102=.
set g103=_
set g104=.
set g105=.
set g106=.
set g107=.
set g108=.
set g109=.
set g110=.
set g111=.
set g112=.
set g113=.
set g114=.
set g115=.
set g116=.
set g117=.
set g118=.
set g119=.
set g120=#
set g121=#
set g122=[
set g123=.
set g124=]
set g125=.
set g126=.
set g127=.
set g128=.
set g129=.
set g130=.
set g131=.
set g132=.
set g133=.
set g134=.
set g135=.
set g136=.
set g137=.
set g138=.
set g139=.
set g140=#
set g141=#
set g142=[
set g143=.
set g144=]
set g145=.
set g146=.
set g147=.
set g148=.
set g149=.
set g150=.
set g151=.
set g152=.
set g153=.
set g154=.
set g155=.
set g156=.
set g157=.
set g158=.
set g159=.
set g160=#
set g161=#
set g162=#
set g163=#
set g164=#
set g165=#
set g166=#
set g167=#
set g168=#
set g169=#
set g170=#
set g171=#
set g172=#
set g173=#
set g174=#
set g175=#
set g176=#
set g177=#
set g178=#
set g179=#
set g180=#
goto :EOF

:display
cls
echo hello, this is motion test 2!!!
echo use wasd to move or e to exit
echo %value%
echo.
echo.
echo %g1%%g2%%g3%%g4%%g5%%g6%%g7%%g8%%g9%%g10%%g11%%g12%%g13%%g14%%g15%%g16%%g17%%g18%%g19%%g20%
echo %g21%%g22%%g23%%g24%%g25%%g26%%g27%%g28%%g29%%g30%%g31%%g32%%g33%%g34%%g35%%g36%%g37%%g38%%g39%%g40%
echo %g41%%g42%%g43%%g44%%g45%%g46%%g47%%g48%%g49%%g50%%g51%%g52%%g53%%g54%%g55%%g56%%g57%%g58%%g59%%g60%
echo %g61%%g62%%g63%%g64%%g65%%g66%%g67%%g68%%g69%%g70%%g71%%g72%%g73%%g74%%g75%%g76%%g77%%g78%%g79%%g80%
echo %g81%%g82%%g83%%g84%%g85%%g86%%g87%%g88%%g89%%g90%%g91%%g92%%g93%%g94%%g95%%g96%%g97%%g98%%g99%%g100%
echo %g101%%g102%%g103%%g104%%g105%%g106%%g107%%g108%%g109%%g110%%g111%%g112%%g113%%g114%%g115%%g116%%g117%%g118%%g119%%g120%
echo %g121%%g122%%g123%%g124%%g125%%g126%%g127%%g128%%g129%%g130%%g131%%g132%%g133%%g134%%g135%%g136%%g137%%g138%%g139%%g140%
echo %g141%%g142%%g143%%g144%%g145%%g146%%g147%%g148%%g149%%g150%%g151%%g152%%g153%%g154%%g155%%g156%%g157%%g158%%g159%%g160%
echo %g161%%g162%%g163%%g164%%g165%%g166%%g167%%g168%%g169%%g170%%g171%%g172%%g173%%g174%%g175%%g176%%g177%%g178%%g179%%g180%
goto :EOF

:display1
if %value% LSS 21 set /a VALUE=%value%+20
if %value% GTR 160 set /a VALUE=%value%-20
if %value% EQU 21 set /a VALUE=22
if %value% EQU 40 set /a VALUE=39
if %value% EQU 41 set /a VALUE=42
if %value% EQU 60 set /a VALUE=59
if %value% EQU 61 set /a VALUE=62
if %value% EQU 80 set /a VALUE=79
if %value% EQU 81 set /a VALUE=82
if %value% EQU 100 set /a VALUE=99
if %value% EQU 101 set /a VALUE=102
if %value% EQU 120 set /a VALUE=119
if %value% EQU 121 set /a VALUE=122
if %value% EQU 140 set /a VALUE=139
if %value% EQU 141 set /a VALUE=142
if %value% EQU 160 set /a VALUE=159
if %value% EQU %v51% set /a VALUE=%bvalue%
if %value% EQU %v49% set /a VALUE=%bvalue%
if %value% EQU %v69% set /a VALUE=%bvalue%
if %value% EQU %v70% set /a VALUE=%bvalue%
if %value% EQU %v71% set /a VALUE=%bvalue%
if %value% EQU 50 goto basement
call :template
set G%value%=@
goto display2

:display2
call :display
goto prompt

:prompt
set /a bvalue=%VALUE%
choice /c:wsade /N
if %errorlevel% EQU 1 set /a VALUE=%VALUE%-20
if %errorlevel% EQU 2 set /a VALUE=%VALUE%+20
if %errorlevel% EQU 3 set /a VALUE=%VALUE%-1
if %errorlevel% EQU 4 set /a VALUE=%VALUE%+1
if %errorlevel% EQU 5 goto END
goto display1

:END
cls
echo are you sure you want to quit the game?
echo (y/n)
choice /C:yn /N
if %errorlevel% EQU 1 exit
if %errorlevel% EQU 2 goto display2


:basement
set VALUE=12
call :templatebase
set g12=@
goto display2base
:templatebase
set bvalue=0
set rock=26
set v27=27
set g1=#
set g2=#
set g3=#
set g4=/
set g5=#
set g7=#
set g8=#
set g9=#
set g10=.
set g11=.
set g12=.
set g13=.
set g14=.
set g15=#
set g16=#
set g17=.
set g18=.
set g19=.
set g20=.
set g21=.
set g22=#
set g23=#
set g24=.
set g25=.
set g26=#
set g27=#
set g28=.
set g29=#
set g30=#
set g31=.
set g32=.
set g33=.
set g34=.
set g35=.
set g36=#
set g37=#
set g38=#
set g39=#
set g40=#
set g41=#
set g42=#
set g43=#
goto :EOF
:displaybase
cls
echo i made this...hahahahahahahaha!!!
echo use wasd to move or e to exit the program
echo %value%
echo.

echo %g1%%g2%%g3%%g4%%g5%%g7%%g8%
echo %g9%%g10%%g11%%g12%%g13%%g14%%g15%
echo %g16%%g17%%g18%%g19%%g20%%g21%%g22%
echo %g23%%g24%%g25%%g26%%g27%%g28%%g29%
echo %g30%%g31%%g32%%g33%%g34%%g35%%g36%
echo %g37%%g38%%g39%%g40%%g41%%g42%%g43%
goto :EOF

:display1base
if %value% GEQ 44 goto displayonebase
if %value% EQU 5 goto nextroomone
if %value% EQU %rock% set /a value=%bvalue%
if %value% EQU %v27% set /a value=%bvalue%
if %value% LSS 9 set /a VALUE=%VALUE%+7
if %value% GTR 36 set /a VALUE=%VALUE%-7
if %value% EQU 2 set VALUE=10
if %Value% EQU 9 set VALUE=10
if %value% EQU 3 set VALUE=11
if %value% EQU 4 set VALUE=12
if %value% EQU 5 set VALUE=13
if %value% EQU 6 set VALUE=14
if %value% EQU 7 set VALUE=14
if %value% EQU 15 set VALUE=14
if %value% EQU 16 set VALUE=17
if %value% EQU 22 set VALUE=21
if %value% EQU 23 set VALUE=24
if %value% EQU 29 set VALUE=28
if %value% EQU 30 set VALUE=31
if %value% EQU 36 set VALUE=35
if %value% EQU 38 set VALUE=31
if %value% EQU 39 set VALUE=32
if %value% EQU 40 set VALUE=33
if %value% EQU 41 set VALUE=34
if %value% EQU 42 set VALUE=35
call :templatebase
set G%value%=@
goto display2base

:display2base
call :displaybase
if %value% LEQ 35 goto promptbase

:promptbase

set /a bvalue=%VALUE%
choice /c:wsade /N
if %errorlevel% EQU 1 set /a VALUE=%VALUE%-7
if %errorlevel% EQU 2 set /a VALUE=%VALUE%+7
if %errorlevel% EQU 3 set /a VALUE=%VALUE%-1
if %errorlevel% EQU 4 set /a VALUE=%VALUE%+1
if %errorlevel% EQU 5 goto END

goto display1base


:END
cls
echo Are you sure you want to end the game?
echo (y/n)
choice /c:yn /N
if %errorlevel% EQU 1 exit
if %errorlevel% EQU 2 goto Display2


See More: need help with roguelike game in batch

Report •


#1
November 7, 2013 at 14:33:54
@echo off
:nextroom
set VALUE=143
call :template
set g143=@
set /a enemyval=157
set g157=E
goto display2
:nextroomone
set VALUE=50
call :template
set g50=@
goto display2
:template
set bvalue=0
set g1=#
set g2=#
set g3=#
set g4=#
set g5=#
set g6=#
set g7=#
set g8=#
set g9=#
set g10=#
set g11=#
set g12=#
set g13=#
set g14=#
set g15=#
set g16=#
set g17=#
set g18=#
set g19=#
set g20=#
set g21=#
set g22=.
set g23=.
set g24=.
set g25=.
set g26=.
set g27=.
set g28=.
set g29=.
set g30=_
set g31=.
set g32=.
set g33=.
set g34=.
set g35=.
set g36=.
set g37=.
set g38=.
set g39=.
set g40=#
set g41=#
set g42=.
set g43=.
set g44=.
set g45=.
set g46=.
set g47=.
set g48=.
set g49=#
set v49=49
set g50=V
set g51=#
set v51=51
set g52=.
set g53=.
set g54=.
set g55=.
set g56=.
set g57=.
set g58=.
set g59=.
set g60=#
set g61=#
set g62=.
set g63=.
set g64=.
set g65=.
set g66=.
set g67=.
set g68=.
set g69=#
set v69=69
set g70=#
set v70=70
set g71=#
set v71=71
set g72=.
set g73=.
set g74=.
set g75=.
set g76=.
set g77=.
set g78=.
set g79=.
set g80=#
set g81=#
set g82=.
set g83=.
set g84=.
set g85=.
set g86=.
set g87=.
set g88=.
set g89=.
set g90=.
set g91=.
set g92=.
set g93=.
set g94=.
set g95=.
set g96=.
set g97=.
set g98=.
set g99=.
set g100=#
set g101=#
set g102=.
set g103=_
set g104=.
set g105=.
set g106=.
set g107=.
set g108=.
set g109=.
set g110=.
set g111=.
set g112=.
set g113=.
set g114=.
set g115=.
set g116=.
set g117=.
set g118=.
set g119=.
set g120=#
set g121=#
set g122=[
set g123=.
set g124=]
set g125=.
set g126=.
set g127=.
set g128=.
set g129=.
set g130=.
set g131=.
set g132=.
set g133=.
set g134=.
set g135=.
set g136=.
set g137=.
set g138=.
set g139=.
set g140=#
set g141=#
set g142=[
set g143=.
set g144=]
set g145=.
set g146=.
set g147=.
set g148=.
set g149=.
set g150=.
set g151=.
set g152=.
set g153=.
set g154=.
set g155=.
set g156=.
set g157=.
set g158=.
set g159=.
set g160=#
set g161=#
set g162=#
set g163=#
set g164=#
set g165=#
set g166=#
set g167=#
set g168=#
set g169=#
set g170=#
set g171=#
set g172=#
set g173=#
set g174=#
set g175=#
set g176=#
set g177=#
set g178=#
set g179=#
set g180=#
goto :EOF
:display
cls
echo hello, this is motion test 2!!!
echo use wasd to move or e to exit
echo %value%
echo.
echo.
echo %g1%%g2%%g3%%g4%%g5%%g6%%g7%%g8%%g9%%g10%%g11%%g12%%g13%%g14%%g15%%g16%%g17%%g18%%g19%%g20%
echo %g21%%g22%%g23%%g24%%g25%%g26%%g27%%g28%%g29%%g30%%g31%%g32%%g33%%g34%%g35%%g36%%g37%%g38%%g39%%g40%
echo %g41%%g42%%g43%%g44%%g45%%g46%%g47%%g48%%g49%%g50%%g51%%g52%%g53%%g54%%g55%%g56%%g57%%g58%%g59%%g60%
echo %g61%%g62%%g63%%g64%%g65%%g66%%g67%%g68%%g69%%g70%%g71%%g72%%g73%%g74%%g75%%g76%%g77%%g78%%g79%%g80%
echo %g81%%g82%%g83%%g84%%g85%%g86%%g87%%g88%%g89%%g90%%g91%%g92%%g93%%g94%%g95%%g96%%g97%%g98%%g99%%g100%
echo %g101%%g102%%g103%%g104%%g105%%g106%%g107%%g108%%g109%%g110%%g111%%g112%%g113%%g114%%g115%%g116%%g117%%g118%%g119%%g120%
echo %g121%%g122%%g123%%g124%%g125%%g126%%g127%%g128%%g129%%g130%%g131%%g132%%g133%%g134%%g135%%g136%%g137%%g138%%g139%%g140%
echo %g141%%g142%%g143%%g144%%g145%%g146%%g147%%g148%%g149%%g150%%g151%%g152%%g153%%g154%%g155%%g156%%g157%%g158%%g159%%g160%
echo %g161%%g162%%g163%%g164%%g165%%g166%%g167%%g168%%g169%%g170%%g171%%g172%%g173%%g174%%g175%%g176%%g177%%g178%%g179%%g180%
goto :EOF
:display1
if %value% equ %enemyval% Goto endofgame
if %value% LSS 21 set /a VALUE=%value%+20
if %value% GTR 160 set /a VALUE=%value%-20
if %value% EQU 21 set /a VALUE=22
if %value% EQU 40 set /a VALUE=39
if %value% EQU 41 set /a VALUE=42
if %value% EQU 60 set /a VALUE=59
if %value% EQU 61 set /a VALUE=62
if %value% EQU 80 set /a VALUE=79
if %value% EQU 81 set /a VALUE=82
if %value% EQU 100 set /a VALUE=99
if %value% EQU 101 set /a VALUE=102
if %value% EQU 120 set /a VALUE=119
if %value% EQU 121 set /a VALUE=122
if %value% EQU 140 set /a VALUE=139
if %value% EQU 141 set /a VALUE=142
if %value% EQU 160 set /a VALUE=159
if %value% EQU %v51% set /a VALUE=%bvalue%
if %value% EQU %v49% set /a VALUE=%bvalue%
if %value% EQU %v69% set /a VALUE=%bvalue%
if %value% EQU %v70% set /a VALUE=%bvalue%
if %value% EQU %v71% set /a VALUE=%bvalue%
if %value% EQU 50 goto basement
call :template
set G%value%=@
set G%enemyval%=E
goto display2
:display2
call :display
goto prompt
:prompt
set /a bvalue=%VALUE%
choice /c:wsade /N
if %errorlevel% EQU 1 set /a VALUE=%VALUE%-20 && set /a enemyval="enemyval-21"
if %errorlevel% EQU 2 set /a VALUE=%VALUE%+20 && set /a enemyval="enemyval+19"
if %errorlevel% EQU 3 set /a VALUE=%VALUE%-1 && set /a enemyval="enemyval-1"
if %errorlevel% EQU 4 set /a VALUE=%VALUE%+1 && set /a enemyval="enemyval-1"
if %errorlevel% EQU 5 goto END
goto display1
:END
goto end2

:basement
set VALUE=12
call :templatebase
set g12=@
goto display2base
:templatebase
set bvalue=0
set rock=26
set v27=27
set g1=#
set g2=#
set g3=#
set g4=/
set g5=#
set g7=#
set g8=#
set g9=#
set g10=.
set g11=.
set g12=.
set g13=.
set g14=.
set g15=#
set g16=#
set g17=.
set g18=.
set g19=.
set g20=.
set g21=.
set g22=#
set g23=#
set g24=.
set g25=.
set g26=#
set g27=#
set g28=.
set g29=#
set g30=#
set g31=.
set g32=.
set g33=.
set g34=.
set g35=.
set g36=#
set g37=#
set g38=#
set g39=#
set g40=#
set g41=#
set g42=#
set g43=#
goto :EOF
:displaybase
cls
echo i made this...hahahahahahahaha!!!
echo use wasd to move or e to exit the program
echo %value%
echo.
echo %g1%%g2%%g3%%g4%%g5%%g7%%g8%
echo %g9%%g10%%g11%%g12%%g13%%g14%%g15%
echo %g16%%g17%%g18%%g19%%g20%%g21%%g22%
echo %g23%%g24%%g25%%g26%%g27%%g28%%g29%
echo %g30%%g31%%g32%%g33%%g34%%g35%%g36%
echo %g37%%g38%%g39%%g40%%g41%%g42%%g43%
goto :EOF
:display1base
if %value% GEQ 44 goto displayonebase
if %value% EQU 5 goto nextroomone
if %value% EQU %rock% set /a value=%bvalue%
if %value% EQU %v27% set /a value=%bvalue%
if %value% LSS 9 set /a VALUE=%VALUE%+7
if %value% GTR 36 set /a VALUE=%VALUE%-7
if %value% EQU 2 set VALUE=10
if %Value% EQU 9 set VALUE=10
if %value% EQU 3 set VALUE=11
if %value% EQU 4 set VALUE=12
if %value% EQU 5 set VALUE=13
if %value% EQU 6 set VALUE=14
if %value% EQU 7 set VALUE=14
if %value% EQU 15 set VALUE=14
if %value% EQU 16 set VALUE=17
if %value% EQU 22 set VALUE=21
if %value% EQU 23 set VALUE=24
if %value% EQU 29 set VALUE=28
if %value% EQU 30 set VALUE=31
if %value% EQU 36 set VALUE=35
if %value% EQU 38 set VALUE=31
if %value% EQU 39 set VALUE=32
if %value% EQU 40 set VALUE=33
if %value% EQU 41 set VALUE=34
if %value% EQU 42 set VALUE=35
call :templatebase
set G%value%=@
set G%enemyval%=E
goto display2base
:display2base
call :displaybase
if %value% LEQ 35 goto promptbase
:promptbase
set /a bvalue=%VALUE%
choice /c:wsade /N
if %errorlevel% EQU 1 set /a VALUE=%VALUE%-7
if %errorlevel% EQU 2 set /a VALUE=%VALUE%+7
if %errorlevel% EQU 3 set /a VALUE=%VALUE%-1
if %errorlevel% EQU 4 set /a VALUE=%VALUE%+1
if %errorlevel% EQU 5 goto END
goto display1base

:endofgame
cls
ECHO PLAYER ONE HAS DIED...
echo rESaRT?
echo (y/n)
choice /C:yn /N
if %errorlevel% EQU 1 goto display2
if %errorlevel% EQU 2 goto END2


:END2

::note this makes the game unwinable.....:D

::mike


Report •

#2
November 7, 2013 at 14:34:46
You will have to tweek the start of enemyval, as the game is unwinable. Also left the basement for you to decide what to do with it.

::mike


Report •

#3
November 7, 2013 at 20:57:16
@Mike: Ha ha! not exactly "unwinnable" as written. South move sends E into the walls, where he goes in opposite directions. Then I can make a run for the "basement". An interesting artifact that was probly not intended. You give huge advantages to the enemy, by allowing diagonal moves and walking through walls (ghosts, maybe, but zombies?). Good work Lol!
@OP: I still stand by the two-dimension grid as less hassle (row, column coords). Your one-dimension array works, but coords need to be evaluated from one-D to two-D using div and mod for each move.
If you want to build rooms, you might consider "painting" them in ascii text files, then reading them in. That's what I would do, so I can visualize what I'm building.
And, you could easily eliminate about 200 lines of code (probly more) by using loops.

message edited by nbrane


Report •

Related Solutions

#4
November 7, 2013 at 22:34:49
Yes its true nbrane....i did use lazy programming...however it felt like an easy way to code it. I will perhaps invest more effort tommorrow. The trick is not overwriting much of the original.

::mike


Report •

#5
November 8, 2013 at 06:16:05
nbrane, could you send an example of a coordinate plane along with an explanation of what the cammands do? please

message edited by firehawk4nzzz


Report •

#6
November 8, 2013 at 21:43:21
Ok, but a lot depends on if you want my whole solution, or if you want to try and work it out yourself. I will "dump" my code if you want (and it's still not perfect). For now, I will just put a room-load (from ascii text-file) into the coordinate plane. My program uses two "layers": the discreet layer, "Ar_c", used for logic, is the 2-dimension array. The raster layer, "LINEr", used only for display, is a series of lines (rows) composed of the elements of each row of the discreet-layer. They always should be kept in synch by the program, which is simple enough. Rows go down, like lines in a file, and columns go across, like letters on a page. So var. A2_4 refers to the 4th letter on line two. Var LINE2 refers to the entirety of line2. I wrote my code to allow any size of rooms. The room layout determines the starting position of "you" and the zombie(s) ("@" and "Z" resp.) And, IMPORTANT, you MUST have delayedexpansion enabled for this code to work. Usually, that is default, but I never assume that. Ok, here's the "load-from-file", which loads both sets of data:

@echo off & setlocal enabledelayedexpansion
:: allowable spaces for moves
set mov=@[]._V+
set @h=.
set zi=0
cls
:: load ascii "painting" or map of a room stored as text
set room=room2
call :loadroom
goto :input

:loadroom
set I=-1
for /f "tokens=*" %%a in (%room%) do (
set /a I+=1
set line!I!=%%a
)
for /L %%a in (0 1 %I%) do (
:: allow for variable widths of rooms (up to 80 in this case)
for /L %%b in (0 1 80) do (
set a%%a_%%b=!line%%a:~%%b,1!
:: determine horiz. max since it's variable
if %%a equ 0 if defined a0_%%b set J=%%b

if /i !a%%a_%%b!==Z (
:: zombie encountered, increment zombie-index, set row & column coords
set /a zi+=1
set z!zi!r=%%a
set z!zi!c=%%b
set z!zi!h=.
)
if !a%%a_%%b!==@ (
set @r=%%a
set @c=%%b
)
)
echo !line%%a!
)
:: zombie count
set zs=%zi%
echo use numeric keypad for moves
goto :eof
::========= end snippet
ps: the room is simply a snapshot of your initial room, but I added another zombie:

####################
#........_.........#
#.......#V#........#
#.......###........#
#..................#
#._................#
#[.]...............#
#[@]............Z.Z#
####################

ok

message edited by nbrane


Report •

#7
November 8, 2013 at 22:56:22
Here's the whole shebang, if you want to jump ahead:
::===== begin batch
@echo off & setlocal enabledelayedexpansion
:: allowable spaces for moves
set mov=@Z[]._V+
set @h=.
set zi=0
cls
:: load ascii "painting" or map of a room stored as text
set room=room2
call :loadroom
goto :input

:loadroom
set I=-1
for /f "tokens=*" %%a in (%room%) do (
set /a I+=1
set line!I!=%%a
:: setting blox to 1 disables random blockads, higher values will enable
set /a blox=I*3
set blox=1
set r=
:: allow for variable widths of rooms
for /L %%a in (0 1 %I%) do (
for /L %%b in (0 1 80) do (
set a%%a_%%b=!line%%a:~%%b,1!
:: determine horiz. max since it's variable
if %%a equ 0 (
if defined a0_%%b set J=%%b
) else (
if !a%%a_%%b! equ . (
set /a x=!random!"%%"blox
if %%b equ !x! set a%%a_%%b=#& set r=%%a
)
)
if /i !a%%a_%%b!==Z (
set /a zi+=1
set z!zi!r=%%a
set z!zi!c=%%b
set z!zi!h=.
)
if !a%%a_%%b!==@ (
set @r=%%a
set @c=%%b
)
)
if defined r call :update
echo !line%%a!
)
set zs=%zi%
echo use numeric keypad for moves, q or e to quit game
goto :eof

:input
set ix=@
set id=@
set r=%@r%
set c=%@c%
choice /c:123456789qe /n
set test=%errorlevel%
if %test% gtr 9 goto :goodbye
call :move
if defined f goto :goodbye
set @r=%r%
set @c=%c%
set ix=Z
for /L %%a in (1 1 %zs%) do (
set id=z%%a
set f=
call :zombie %%a
if defined f goto :goodbye
)
call :refresh
goto :input

:move
set f=
set /a fwd=test"%%"3
set /a bck=(test-1)"%%"3
set tr=%r%
set tc=%c%
if %test% lss 4 set /a tr+=1
if %test% gtr 6 set /a tr-=1
if %fwd% equ 0 set /a tc+=1
if %bck% equ 0 set /a tc-=1
rem echo one: %tr% %tc% !a%tr%_%tc%! r:%r% c:%c%

set x=!a%tr%_%tc%!

set movtest=!mov:%x%=!
rem echo two: x[%x%][!x!] %mov% %movtest% id:%id%
:: enable the following to allow zombie wall penetration
rem if %id% equ @ if %movtest% equ %mov% goto :eof
if %movtest% equ %mov% goto :eof
if /i %x% equ @ set f=1
if /i %x% equ Z set f=1
set a%tr%_%tc%=%ix%
set a%r%_%c%=!%id%h!
set %id%h=%x%
call :update
set c=%tc%
if %tr% neq %r% (
set r=!tr!
call :update)
set r=%tr%
rem if defined f goto :eof
goto :eof

:refresh
cls
for /L %%a in (0 1 %I%) do echo !line%%a!
goto :eof

:update
set line%r%=
for /L %%a in (0 1 %J%) do (
set line%r%=!line%r%!!a%r%_%%a!
)
goto :eof

:zombie
set /a rr=%id%r-@r
set /a cc=%id%c-@c
set test=5
if %rr% gtr 0 set test=8
if %rr% lss 0 set test=2
if %cc% lss 0 set /a test+=1
if %cc% gtr 0 set /a test-=1
set r=!%id%r!
set c=!%id%c!
:z
call :move
if /i %x% equ @ goto :eof
echo [%@r% %@c%][!%id%r! !%id%c!]
rem if "%@r% %@c%" equ "!%id%r! !%id%c!" goto :goodbye
:: zombie intelligence very tedious. Try certain moves if no movement
rem if !zr%zi%!!zc%zi%! equ %r%%c% (
rem call :brains
rem goto :z
rem )
set %id%r=%r%
set %id%c=%c%
goto :eof

:brains
:: all zombie intelligence stored here. currently null, like mine...
goto :eof

:goodbye
call :refresh
echo goodbye!
pause>nul
exit /b

message edited by nbrane


Report •

#8
November 9, 2013 at 09:45:04
OK well that's cool...but it seems really complicated...is there anyway two have the zombie follow you regardless of where you are on the map in my design...I've already come up with a battle system now I just need the zombies to follow the player. It just seems like I'd be back tracking to make almost all of my design...then just scrap it all

message edited by firehawk4nzzz


Report •

#9
November 9, 2013 at 11:37:02
Yeh, I understand. But didn't Mike build a working "dog" routine into your code in resp. #1? I would just use that. On consideration, I figured you would prefer to keep what you have achieved and build onto it. Good luck and beware the zombies!

Report •

#10
November 10, 2013 at 19:35:00
His is good but it doesn't really act like a zombie... I can make it so it doesn't go through walls but then there's still the fact that the zombie dosnt follow you regardless of your position...if its not possible to do that could you send me a working version of your design in one file?

Report •

#11
November 11, 2013 at 19:49:50
Uuh.., I'm confused at this point. Here's my "take": there's "seek & destroy" mode, and there's "seek then follow" mode (like a form of drone-based observation, or "ghosting" or "dogging"). Not sure which mode you want. Also, the disparity between diagonal-move-capability probly needs to be addressed, so the playing-rules are balanced, unless you want them not to be. Mikes and my versions were "seek and destroy", but that is of course not the only scenario. Zom could "shadow" the player indefinitely until the player chooses to "turn and do battle". These are all game design considertations, not mechanics - the gears&springs make the design work, but they're just machinery to implement the plot/design. Strictly back-stage, behind-the-scenes rigging, You, as designer/producer, dictate the behavior of both protagonist(s) and antagonist(s).
We need to know, specifically, where our programs diverge from you intended behavior/operation, if we're to make any corrections to suit you.
ps: google "crusher soleau" for a similar concept, (but not written in batch, of course). His games, written for "true DOS", are very well concieved and designed, although in my opinion, he never received proper credit for their quality (at the time.)
Still runs on winXP 32-bit... but not win-7

Report •

#12
November 11, 2013 at 22:22:36
On another note, if you just want to play a rouge like game there is a uncompiled c version of a script on the web somewhere...maybe source forge?

::mike


Report •

#13
November 12, 2013 at 05:21:06
Well my idea is that while the player is x amount away from the zombie,the zombie will make random moves. But when you move a certain distance toward it. It would start to follow you and once his position equaled yours, the battle system would initiate...I have the battle system...I just need the movement...in other words seek and destroy mode also in my last response I ment "response" not file

Report •

#14
November 12, 2013 at 06:51:29
Are you switching to nbrane's series, or are you keeping with your origional?

::mike


Report •

#15
November 12, 2013 at 07:20:17
is it even possible to keep my design? because if it is that would be awesome to add on to my current design...but if it isn't possible to make the zombies move randomly if too far away from the player but follow and kill the player if the player get's closer to them, then nbranes method would most likely have to be used

message edited by firehawk4nzzz


Report •

#16
November 12, 2013 at 11:49:35
<
Ghost k don't stop.

message edited by bobdsds


Report •

#17
November 12, 2013 at 20:35:20
You should be able to keep your original (1-dimensional) system, because all you need to convert from 1-d linear to 2-d coord is to apply div (to get row), and modulo (to get column) to the given linear value. The 2nd operand for both values is the width of your room. For a room that's 8 wide and 3 long (or high or deep), linear index will be from g1 to g24 (3x8). Planar coordinate vertical is curr. linear posn div 8, planar coord horiz. (width) is curr. linear posn modulo 8. This is just basic stuff.
As for "killing radius", (zombie sniffer-range), technically you need square root function if you want to be exact (pythagorus). ABS(Xz-Xp)+ABS(Yz-Yp) then take the square root of that, but batch doesn't offer sqrt. There might be a "work-around" that comes reasonably close using batch simply by tryiing all squares starting from 2 until you exceed your limit, since the limit will be very small anyway and we're only working whole-number integers here. Yeh, that should work...


Report •

#18
November 13, 2013 at 05:33:43
Would it be possible for you to post my original code with those changes to it
So I could " reverse engineer" it to figure it out more thouroghly

message edited by firehawk4nzzz


Report •

#19
November 13, 2013 at 12:04:35
on another note I couldn't get the second iteration to work without a ) after set r=

don't know if i missed something

::mike


Report •

#20
November 13, 2013 at 19:42:11
You talkin-ta me? (joke). Or to mike? I'll try to help, but I don't have time or patience to remodel your code (no offense intended, we just think differently). And this isn't really the place for it either, but bandwidth is cheap these days. I'll try to show you what I mean, so you can incorporate what you wish into your own code.
First, you would be way better off using a base of zero, instead of one, due to the nature of mod/div. So your first element would be g0, not g1. Here's why. Looking at the following grid:
00 01 02 03 04 05
06 07 08 09 10 11
12 13 14 15 16 17

For any location on the grid, you can convert linear (1 element per location) to planar (2 elements defined each location) by applying two operations to any linear value to get the two coords. of planar. Roomwidth is "W", which is not 5 but 6 since the room is 6 bytes wide. "Z" is any value you choose in the above. Row (vert) is: Z / W. Column is Z %% W. So, f/e: Z=8 gives the two values 1 (for row number, but based on zero), and 2 for column (again, base zero, where "06" is zero). In batch, 8/6=1, and 8 mod 6 is 2 (8 / 6=1, remainder = 2). So, whenever you move your man, or your
zombie, you need to re-calculate both X and Y (row# and column#) for whichever one moved, then apply the radius (pyghagorean) algorithm in order to see if they are in range to do battle. Here's my version of how to do that (NOT TESTED yet):
set /a diff1=myrow-z_row
set /a diff2=mycol-z_col
:: ABSolute value: just make dash into null. maybe another way?
set diff1=%diff1:-=%
set diff2=%diff2:-=%
:: two sides of a right triangle (gives radius)
set /a rad=diff1*diff1+diff2*diff2
for /L %%a in (2 1 %rad%) do (
:: hold former value for when test exceeds max
set h=!test!
set /a test=%%a*%%a
if !test! gtr %rad% (
set dist=!h!
goto :xx
)
)
:xx
set rad=%dist%
:: end snippet
this would of course be a subroutine useable by either move (player or zombie). I'll try and test it as time permits, unless you go a different route.
ps: posts #16 and MIke's latest, ..? (clueless)
pps: on further consideration, the triangulation is not necessary, you can just measure the diff in cols and rows, but you still need to calculate a 2-d coord for player and zombie. Also, you could use the "timeout" feature of "CHOICE" to "pass" the move from a lazy player to the zombies, so zombies can move even when the player does not - whether random or targeted. (see: CHOICE /?, note the /T option which you could make default to a "don't move" value.) I'll post some code as time permits since I'm kind of "hooked" now.

message edited by nbrane


Report •

#21
November 15, 2013 at 05:18:45
Thanks anyway guys you've been very helpful. But I think instead of trying to mess with dos programmings restrictive language I'll move on to a better language...perhaps java...any thanks any way

Report •

#22
November 15, 2013 at 06:25:07
I'm going to call this my (delayed) victory.

Also, I prefer C# over Java, but given Microsoft's latest tendencies, it might not be good to tie yourself to the Windows platform.

How To Ask Questions The Smart Way


Report •

#23
November 15, 2013 at 19:22:48
Yeh, give Razor "best answer" for sure! I'm leaving this room by the back door...

Report •

#24
November 22, 2013 at 19:50:41
It would appear that the saga continues here....
http://www.computing.net/answers/pr...

::mike


Report •


Ask Question