# Solved how to make an x y coordinate plane in batch

November 22, 2013 at 14:11:41
Specs: Windows 7
 i am trying to make a riugelike game in batch...could any one post a simple x y coordinate plane map...just a simple one that allows you to walk through the map

See More: how to make an x y coordinate plane in batch

December 2, 2013 at 21:07:44
 @mike: thanks for helping to explain, especially emphasizing base zero, which can be confusing, but always critical.@OP firehawk"how is it that you can manipulate the players symbol "@" when the map isn't made of variables?" I don't! The entire map is made of variables, including the player-symbol, barriers, treasure, and any other active elements (other players or enemies). Do you understand arrays? Arrays, and looping, are like blood-brothers: one is never employed without the other, and the result is massivly more than the sum of these elements. I think that batch syntax is what is giving you fits, because it is NOT a user-friendly language (contrary to most initial opinions). For "basic" concept, I still favor BASIC (Qbasic or QuickBasic) because they're easy to aquire, and don't have much overhead or learning curve. But this is only as a learning platform. Win-7, and all 64 bit platforms, will not be compatible.If you wish to pursue batch, you only need to understand simple concepts such as:SET g%row%_%col%=@IF "!g%row%_%col%!" equ "#" goto :WALL_NOMOVEThese are valid variables - nothing mysterious. g%row%_%col% is functionallty equivalent to g\$(row,col) in BASIC. If row value is 3, and col is 5, then a variable named g3_5 is equiv. to a var g%row%_%col% (since row and column are replaced by %row% and %col% in batch) is equiv to g\$(3,5) or g\$(row,col) in BASIC. Inside a loop or code-block, you need to add the exclams to access elements, f/e:@echo off & setlocalset g0_0=A0set g0_1=B0set g0_2=C0set g0_3=D0SET g0_4=+++set g1_0=A1set g1_1=B1set g1_2=C1set g1_3=D1SET g1_4=---set g2_0=A2set g2_1=B2set g2_2=C2set g2_3=D2SET g2_4=###set g3_0=A3set g3_1=B3set g3_2=C3set g3_3=D3SET g3_4=\$\$\$rem etc.for /L %%a in (0,1,3) do (set line%%a=for /L %%b in (0,1,4) do (:: this next line appends elements to an output ("raster") line:rem echo g%%a_%%bset line%%a=!line%%a!___!g%%a_%%b!):: inside the loop, the raster-line is completeecho line%%a:== !line%%a!)this builds a simple set of 4 lines (vars. line1, line2, line3, line4) out of 4 groups having five elements per group.A loop will operate on subsets within the array for any "dimension" (row, column) and any subset within that dimension. As previously pointed out, a 2-dimension "plane" can be reduced to one dimension (using math) and vice versa because it's all regular sets (height, width) of data.message edited by nbrane

#1
November 22, 2013 at 21:12:51
 This also had a random-walk zombie feature that you may not want...Ok, here's the last one I made, hope it helps:@echo off & setlocal enabledelayedexpansion:: allowable spaces for moves (walls vs halls/space) these are the allowed movesset mov=@[]._V+set @h=.set zi=0::speed, or frequency of random-zombie moves, in secondsset spd=1cls:: load ascii "painting" or map of a room stored as text filename "room2"set room=room2call :loadroomgoto :input:loadroomset I=-1for /f "tokens=*" %%a in (%room%) do (set /a I+=1set line!I!=%%a):: setting blox to 1 disables random blockades, higher values will enable increasingset /a blox=I*3set blox=1set r=:: allow for variable widths of roomsfor /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 variableif %%a equ 0 (if defined a0_%%b set J=%%b) else (if !a%%a_%%b! equ . (set /a x=!random!"%%"bloxif %%b equ !x! set a%%a_%%b=#& set r=%%a))if /i !a%%a_%%b!==Z (set /a zi+=1set z!zi!r=%%aset z!zi!c=%%bset z!zi!h=.)if !a%%a_%%b!==@ (set @r=%%aset @c=%%b))if defined r call :updateecho !line%%a!)set zs=%zi%echo use numeric keypad for movesset to=/t:5,%spd%goto :eof:inputset ix=@set id=@set r=%@r%set c=%@c%set test=choice /c:123456789qe /n %to%set test=%errorlevel%if %test% gtr 9 goto :goodbyecall :moverem if %test% equ 5 (rem goto :zpassrem ) else (rem call :moverem ):: zombie match player, end gameif defined f goto :goodbyerem call :%x% 2>nulset @r=%r%set @c=%c%:zpass:: lazy player, pass move to zombie randomset ix=Zfor /L %%a in (1 1 %zs%) do (set id=z%%aset f=call :zombie z%%aif defined f goto :goodbye)call :refreshgoto :input:moveset f=if %test% equ 5 goto :eofset /a fwd=test"%%"3set /a bck=(test-1)"%%"3set tr=%r%set tc=%c%if %test% lss 4 set /a tr+=1if %test% gtr 6 set /a tr-=1if %fwd% equ 0 set /a tc+=1if %bck% equ 0 set /a tc-=1rem 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 penetrationrem if %id% equ @ if %movtest% equ %mov% goto :eofif %movtest% equ %mov% goto :eofif /i %x% equ @ set f=1rem if /i %x% equ Z set f=1set a%tr%_%tc%=%ix%set a%r%_%c%=!%id%h!set %id%h=%x%call :updateset c=%tc%if %tr% neq %r% (set r=!tr!call :update)set r=%tr%rem if defined f goto :eofgoto :eof:refreshclsfor /L %%a in (0 1 %I%) do echo !line%%a!goto :eof:updateset line%r%=for /L %%a in (0 1 %J%) do (set line%r%=!line%r%!!a%r%_%%a!)goto :eof:zombieset id=%1rem echo zombie===========%id% !%id%r! !%id%c!rem pauserem set to=/t:5,%spd%set /a test=%random%"%%"10rem goto :zset /a rr=%id%r-@rset /a cc=%id%c-@cset dx=%rr:-=%set dy=%cc:-=%if %dx% gtr 4 goto :zif %dy% gtr 4 goto :zset to=set zlr=2set zud=3set test=5if %rr% gtr 0 set test=8if %rr% lss 0 set test=2if %cc% lss 0 set /a test+=1if %cc% gtr 0 set /a test-=1:zset r=!%id%r!set c=!%id%c!call :moveif /i %x% equ @ goto :eofecho [%@r% %@c%][!%id%r! !%id%c!]rem pauserem if "%@r% %@c%" equ "!%id%r! !%id%c!" goto :goodbye:: zombie intelligence very tedious. Try certain moves if no movementrem if !zr%zi%!!zc%zi%! equ %r%%c% (rem call :brainsrem goto :zrem )set %id%r=%r%set %id%c=%c%goto :eof:brains:: all zombie intelligence stored here.goto :eofif %test% gtr 6 (set /a test-=3if %test% equ 5 if %zlr% neq 6 (set /a zlr+=2set test=%zlr%goto :z))if %test% lss 4 (set /a test+=3if %test% equ 5 if %zlr% neq 6 (set /a zlr+=2set test=%zlr%goto :z))if %zud% neq -1 (set /a test+=zudset /a zud=-zudif !zud! equ -3 set zud=1goto :z)goto :eof:chkif %x% equ @ echo x: %x% & goto :goodbyeif %x% equ Z echo x: %x% & goto :goodbyegoto :eof:goodbyecall :refreshecho goodbye!pause>nulexit /b::======== end batchThis code may seem tedious, but it tries for both maximum efficiency (subroutines)and maximum flexibility (room design, multiple rooms, multiple zombies, diagonal moves).

Report •

#2
November 23, 2013 at 13:41:54
 I mean one without zombies on just a 10x10 grid just so I can dissect the code and learn how it works...and please include a map...so I know how to construct it...so instead of making the map "call" have it in the file...thankyou

Report •

#3
November 23, 2013 at 23:32:35
 Ok. Here's a stripped-down version of my way of doing this. No two people think exactlly alike (thank God). I put in lots of comments to explain my actions, but again, as stated prior, delayed expansion (and some understanding of it) is necessary for this code to work. PS: I understand if you want new approaches, so I won't put any further responses unless specifically asked. So if you make a new post, it will remain "open" for others to contribute. Good luck/have fun!It's a 10x10 room as per req. I did throw in one "obstacle", just as a demo since the rest of the room is built as a loop (because I'm lazy), and you will probably not want such a boring room in your future developments. You can define each line (or "row") like:```set line1=#....#v#....# set line2=#....#_#....# ```etc.::====== begin batchscript@echo off & setlocal enabledelayedexpansioncls::======== all initializations: Width and Height of roomset W=9set H=9:: --- begin build room..top, bottom rowsset line0=##########:: all middle rows, looped due to lazinessset line1=#........#for /L %%a in (2 1 %H%) do set line%%a=%line1%set line%H%=%line0%:: make one exception at row #4set line4=#...#....#:: so you can see how to build a room row-by-row.:: build 2-dimension grid from the collection of rowsfor /L %%a in (0 1 %H%) do (for /L %%b in (0 1 %W%) do set g%%a_%%b=!line%%a:~%%b,1!)set id=@:: set %id%h=.set @h=.:: initial position of player: row, colmset r=3set c=2set g%r%_%c%=@:: end of room-build:: this wasn't necessary. It just reiterates building of rows from grid elemsfor /L %%a in (0 1 9) do (set xx=for /L %%b in (0 1 9) do (set xx=!xx!!g%%a_%%b!)echo !xx!)pause::========== MAIN GAME LOOP BEGINS WITH USER INPUT:inputchoice /c:123456789qe /n::-----------set test=%errorlevel%if %test% gtr 9 goto :goodbye:: 2 steps: update altered grid rows and rebuild only affected lines,call :move:: then redisplay entire gridcall :refreshgoto :input:move:: test for movement and adjust accordingly based on 9 poss. moves: compass -:: NSEW, diags, and "stay" (skip-move/"pass", or do action like FIRE):: mine uses numeric kpd for these moves, but not necc. for code to work.if %test% equ 5 goto :eof:: foll is zero if 9, 6 or 3 which are all "rightward" or Eastset /a fwd=test"%%"3:: foll is zero if 7, 4 or 1 which are all "leftward" or Westset /a bck=(test-1)"%%"3set tr=%r%set tc=%c%:: foll is South, or down. Increment Row#if %test% lss 4 set /a tr+=1:: foll is North, or up. Decrement Row#if %test% gtr 6 set /a tr-=1if %fwd% equ 0 set /a tc+=1if %bck% equ 0 set /a tc-=1rem echo one: %tr% %tc% !g%tr%_%tc%! r:%r% c:%c%:: hits a wall?if !g%tr%_%tc%! equ # goto :eof:: begin actual update::: FROM-grid token restored to previously saved token.set g%r%_%c%=%@h%:: current TO-grid-token saved in x, {f/e usually a dot .}set x=!g%tr%_%tc%!::TO-grid updated to "@",set g%tr%_%tc%=@set @h=%x%:: now update only the affected "raster/display" lines (two maximum):: current line ALWAYS needs updated.call :updateset c=%tc%:: adjacent line only needs updated if any vertical displacement detectedif %tr% neq %r% (set r=!tr!call :update)set r=%tr%goto :eof:: now just display the raster-lines:refreshclsrem pausefor /L %%a in (0 1 %H%) do echo !line%%a!goto :eof:update:: rebuild a line to reflect current token-values after moveset line%r%=for /L %%a in (0 1 %W%) do (set line%r%=!line%r%!!g%r%_%%a!)goto :eof:goodbyeecho goodbyemessage edited by nbrane

Report •

Related Solutions

#4
November 25, 2013 at 09:48:58
 ok so I somewhat know whats happening here but at the same time not really... the loops are what confuse me...would it be possible to write the code without loops?...I haven't learned how to use loops yet and with limited internet access it's very difficult to learn more ill work on learning how to use loops but for now could you write it without loops?

Report •

#5
November 25, 2013 at 20:33:33
 Well, I must say, programming without looping is like flying without wings: it won't get you far, and you'll eventually feel the pain (never mind rockets and parachutes, for you literal minded interpreters!) Loops, and subroutines, are the essence of base-level (as opposed to object-oritented) programming. Probably more than loop concept (which is simple enough), with batch, the key is the concept of delayed expansion and enabling it. Meanwhile, I'll see what I can do, and maybe some other masochists on the forum will pitch in (just joking!) Turkey-day coming up etc...

Report •

#6
November 26, 2013 at 08:23:29
 more customizable is my goal.. I would eventually like it so I could have a menu pop up to the side of the map when the player presses a button...so far ive figured out how to make the map bigger and how to put obstacles in there...but I don't even know how the map is displayed at this point because im use to displaying things using echo...but I do like this method much more it takes much less "computing power" to go... it goes faster than my original method...again I still don't quite get what all of the symbols in the loops do but I figured out how to have the map larger and display right off the bat... but how would I make it display a little menu to the right of the map...and if you could please explain the loops you've made... or how they work..i hate to ask too much but it would really be helpful!

Report •

#7
November 26, 2013 at 20:14:57
 Before I do, can you take a look at:for /? (page 1 primarily)set /? (pages 2,3)Because these help explain the symbols, and the concept of variable expansion, which is mostly unique to batch. My code uses "echo", same as yours. Only difference is that mine composes the lines from the elements (as explained earlier-on) so that only one or two lines need to be re-configured for each move and the rest do not. The larger the map, the more expedient this becomes. As for menu display, all you need do is append each menu-line to the display of each raster-line (map row). It would be somewhat simpler to put the menu above or below the map, but thats a minor thing. I suspect that delayed expansion, and use of !, is what is holding you up in my code. delayedexpansion allows two different abilities, a) access to var values inside a code-block, and b) allowing variables to be expressed inside of other variables before evaluation. item "b" F/e:set row=3set col=4set line%row%_%col% = @echo !line%row%_%col%!If you try to "echo line%row%_%col%" you will get: "line3_4"if you echo !line%row%_col%! you will get your desired target: "@"because the evaluation of line%row%_%col% is subsequent to the evaluations of row and column variables. There's another way to do this, but this is the easiest to deal with.Of course, delayedexpansion must be in effect to take advantage of this feature.

Report •

#8
December 2, 2013 at 09:38:31
 Hey sorry for taking so long to reply ive been on vacation for the week and there was't any wifi there so I couldn't keep up with this... anyway my main problem is I really don't know how the x y coordinate map works...how is it that you can manipulate the players symbol "@" when the map isn't made of variables? I know I probably just disregarded most of what you just said if not all of it but I think I just need to figure out how it works instead of expecting you to make it more..."dumbed down" for me. so my question is first how do you use loops? for this example. meaning, like a simple 10 by 10 map with nothing but the map making skills...no movement needed yet..id like to take this in steps. 1st map making, 2nd movement, 3rd "If I move here take me to a different map or :EXAMPLE(bookmark)", 4th how to add a menu with options that take you places. I really appreciate your patience with me, and not that you'd want it but if you can figure out a way ill send you a final copy of my game when it's done! :) thanks!

Report •

#9
December 2, 2013 at 11:38:45
 From nbranes posts above:: its important to note the grid top to bottom is 0-9 not 1-10:: --- begin build room..top, bottom rowsset line0=##########:: all middle rows, looped due to lazinessset line1=#........#::this is for lines starting at 2 in steps of 1 to the variable H, which is set to 9::this all of the other rows are set to #........#for /L %%a in (2 1 %H%) do set line%%a=%line1%set line%H%=%line0%::this sets the last line H to the same as the first line:: make one exception at row #4set line4=#...#....#::this edits line four to the above.:: so you can see how to build a room row-by-row.edit: note that I ment no offense nbrane :) ::mikemessage edited by mikelinus

Report •

#10
December 2, 2013 at 21:07:44