computing
  • 2

Solved How To Make a Batch Game Have Movement

  • 2

I know you have to make a grid and set x and y to something, but I don’t know how to do it.
I want to make a game that has an object bouncing off of the walls and a little platform that the player would control, and when the ball hits certain objects those objects will disappear and all that stuff. I’m really lost here and would greatly appreciate some help.

I’m talking about a game like this:

_________________
|……………………….| The O would be the ball.
|….###……………..| and it would be able to
|……#………………. | bounce off of the walls
|……………………….| and break the objects
|……………….O…… | (#) when it hits them.
|……………………….|
|……——……………| —— = platform
|________________|

 

message edited by Person23

Share

1 Answer

  1. Man, you have a lot of patience! But you need to study and learn to use loops and subroutines to your advantage. Also, in my opinion, you’re way overcomplicating things. You had the right idea, with the “f” variable series. All you needed to do was build a “cieling” (north wall) and a “floor” (south wall) as “f” vars, then for each line of vars between, start and end with vertical wall char.s. I don’t know where this “boundary” stuff came in, but it’s not necessary.Anyway, I cannot work with your code, as I don’t have the patience, so i can only supply my version (including rudimentary “move” analysis):
    @echo off & setlocal
    ::dimensions of room – vary to suit!
    set width=12
    set depth=10
    set /a q=depth+1
    ::initial location x-y coordinates of character {x=row=”r”, y=col=”c”}
    set r=3
    set c=1
    set a%r%_%c%=@
    :: random block(s) – vary as needed!
    set a6_4=°
    set a9_7=#

    ::build room – cieling {x=0, north wall}
    set left=É
    set right=»
    set mid=Í
    call :line 0
    :: – floor {x=depth, south wall}
    set left=È
    set right=¼
    call :line %q%

    set beg=1
    set end=%depth%
    set step=1

    :refresh
    :: – x=1..depth-1, central arena
    set left=º
    set right=º
    (set mid= )
    for /L %%a in (%beg% %step% %end%) do call :line %%a

    :: display room
    cls
    for /L %%a in (0 1 %q%) do echo !line%%a!

    :move
    set tc=%c%
    set tr=%r%
    :: why do you guys always insist on these instead of numeric keypad? Oh well…
    choice /c:wasd /n
    if %errorlevel%==4 set /a tc+=1
    if %errorlevel%==3 set /a tr+=+1
    if %errorlevel%==2 set /a tc-=1
    if %errorlevel%==1 set /a tr-=1
    if “!f%tr%_%tc%!” neq ” ” goto :move

    set beg=%r%
    set end=%tr%
    set /a step=tr-r
    if %step% equ 0 set step=1
    set a%r%_%c%=
    set r=%tr%
    set c=%tc%
    set a%r%_%c%=@
    rem echo refreshing %r% %step% %end%
    goto :refresh

    :line
    ::build the map into sequential {array} var. Fx_y where x is vert, y is horiz
    set f%1_0=%left%
    set f%1_%width%=%right%
    set /a k=width-1
    for /L %%b in (1 1 %k%) do if defined a%1_%%b (set f%1_%%b=!a%1_%%b!) else (set f%1_%%b=%mid%)

    ::build lines for display
    set line%1=
    for /L %%b in (0 1 %width%) do set line%1=!line%1!!f%1_%%b!
    ::====== end
    I don’t think you will ever make any significant progress using your current technique (brute force). You need to think in terms of loops and subroutines. Loops require knowledge of variable expansion (echo !f%r%_%c%!) At any rate, the above 72 lines of script effectively replace the 167 lines of “brute force” and work much better in all respects – not to brag, just to demonstrate the difference in approach.

    • 0