Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch Movement Simulator Help  (Read 9276 times)

0 Members and 1 Guest are viewing this topic.

Nathansswell

    Topic Starter


    Rookie

    Thanked: 1
    • Yes
    • I make music!
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 8
Batch Movement Simulator Help
« on: December 19, 2012, 08:31:10 PM »
Ok, so I am working on a "game" written in batch and I came across a problem. I'm just showing a smaller example of the game to reduce confusion and unneeded coding. So, in a display that looks like:

#####
#O      #   #=All the walls
#   #   #   O=Movable Character
#        #    Spaces=Area to move
#####

I need to find a way to have the bold # be a wall which will keep the character (O) to stay where is was at when you directed it towards it. It would look something like this:

#####   If I made the "O" go right,
#        #   it would hold that position.
#O#   #   I want the "O" to hold it's
#        #   position from the top,
#####   bottom, and left of the # as well.

That is the problem though, because I can only assign it to go to a single place if the "O" is going to the #.

This is the example code which I am showing you:
Or just download it from here.

Code: [Select]
@echo off
mode con cols=14 lines=7
title Test
color 0f
set position=7
call :layout
set a7=#
goto redir
:screen
cls
echo %a1%%a2%%a3%%a4%%a5%
echo %a6%%a7%%a8%%a9%%a10%
echo %a11%%a12%%a13%%a14%%a15%
echo %a16%%a17%%a18%%a19%%a20%
echo %a21%%a22%%a23%%a24%%a25%
goto :eof
:redir
call :screen
:prompt
choice /c wasde /n
if errorlevel 5 exit
if errorlevel 4 set /a position=%position%+1&goto ifcheck
if errorlevel 3 set /a position=%position%+5&goto ifcheck
if errorlevel 2 set /a position=%position%-1&goto ifcheck
if errorlevel 1 set /a position=%position%-5&goto ifcheck
:layout
set a1=Û
set a2=Û
set a3=Û
set a4=Û
set a5=Û
set a6=Û
set a7=±
set a8=±
set a9=±
set a10=Û
set a11=Û
set a12=±
set a13=Û
set a14=±
set a15=Û
set a16=Û
set a17=±
set a18=±
set a19=±
set a20=Û
set a21=Û
set a22=Û
set a23=Û
set a24=Û
set a25=Û
goto :eof
:ifcheck
if %position%==2 set position=7
if %position%==3 set position=8
if %position%==4 set position=9
if %position%==6 set position=7
if %position%==11 set position=12
if %position%==16 set position=17
if %position%==22 set position=17
if %position%==23 set position=18
if %position%==24 set position=19
if %position%==10 set position=9
if %position%==15 set position=14
if %position%==20 set position=19
call :layout
set a%position%=#
goto redir

If I was not clear enough, please tell me. I tried my best.  :P -Nathansswell

DaveLembke



    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Batch Movement Simulator Help
« Reply #1 on: December 20, 2012, 02:34:54 AM »
This is easy in languages like Basic, C, C++, Perl, Python, and a bunch of others. Not sure how you are going to do this with limitations of Batch. I made similar ASCII type games in Basic and C many years ago and used an array and a bunch of IF statements to control the X,Y boundaries by which the character would move in, such as confined within all your hashes in yoursetup. Also had to have collision detection to keep your character from being able to occupy the same space as other "solid" objects in the 2D ACSII Game. Maybe this can be done in Batch, but its beyond my batching abilities. For me it would be way easy in these 5 languages I listed vs batch.

Looking at your code above it looks incomplete, such as missing :eof where the goto :eof is directing the next set of executions after set a25=Û, as well as missing a bunch of other sections. ( Maybe the clipboard chopped out a bunch of your code when copy/pasting it here to look at. ) * I am not a fan of downloading anything, so I will run it if all the source is here and I can visually inspect it for its intent before execution, and be able to copy it all direct to notepad and save as a test.bat file etc.

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: Batch Movement Simulator Help
« Reply #2 on: December 20, 2012, 04:17:49 AM »
From what I see, you are never going back to prompt, so it isn't giving you the option to move more than once. This may or may not be the problem.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

Salmon Trout

  • Guest
Re: Batch Movement Simulator Help
« Reply #3 on: December 20, 2012, 04:34:32 AM »
Looking at your code above it looks incomplete, such as missing :eof where the goto :eof is directing the next set of executions after set a25=Û,

This is a nomal thing - in a batch script,  you can CALL a colon+label subroutine just like you can call an external batch. The goto :eof (with a colon before eof) is a special thing equivalent to "return" from a GOSUB in e.g. BASIC. It takes you back to the line after the CALL statement.

REM main code
echo main code
call :subroutine
echo back in main code
goto end

:subroutine
echo in subroutine
goto :eof

:end

http://www.robvanderwoude.com/call.php

Nathansswell

    Topic Starter


    Rookie

    Thanked: 1
    • Yes
    • I make music!
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 8
Re: Batch Movement Simulator Help
« Reply #4 on: December 20, 2012, 10:20:42 PM »
After thinking too much, I finally figured it out! Grazie amici! The sad part is, I don't know any other languages other than batch still.. :( But it works, so I'll still use it.

NoroGaming



    Newbie

    • Experience: Familiar
    • OS: Windows 10
    Re: Batch Movement Simulator Help
    « Reply #5 on: December 04, 2018, 05:37:03 PM »
    I'm trying basically the same thing but without restraints to going right and down. This is what i have...

    @echo off
    @setlocal EnableDelayedExpansion

    set y=0
    set x=0
    set space=
    echo []

    :0
    set errorlevel=0
    choice /c wasd /n
    if %errorlevel% equ 1 (
    set y=%y%-1
    if %y% equ -1 set %y%=0
    )
    if %errorlevel% equ 2 (
    set x=%x%-1
    if %x% equ -1 set %x%=0
    )
    if %errorlevel% equ 3 (
    set y=%y%+1
    )
    if %errorlevel% equ 4 (
    set x=%x%+1
    )


    set height=%y%
    set length=%x%
    set arm=
    cls

    :y
    if %height% equ 0 goto x
    set height=%height%-1
    echo.
    goto y

    :x
    if %x% equ 0 goto 1
    if %length% equ 0 goto z
    set length=%length%-1
    set arm=%arm%%space%
    goto x

    :z
    echo %arm%[]
    goto 0

    :1
    echo []
    goto 0



    Its supposed to work by generating your position every time you press wasd but it doesn't work.