Batch Game Movement (Tutorial)

by Prof. Pickle in Circuits > Computers

85303 Views, 19 Favorites, 0 Comments

Batch Game Movement (Tutorial)

dad.jpg
Now, there are many ways to get a character in batch to move, however, in this tutorial is probably the shortest codes anyone has made.

Enjoy!

Note: Copy and paste the following code into notepad or another text-editing program and save it as movement.bat


Code 1 (simple Movement)

pong.jpeg
pong-773348.jpg
@setlocal enableextensions enabledelayedexpansion
@echo off
title movement
color 0a

set length=         
set height= a

:controls
cls
echo Use WASD to move your character ([]).
echo.
for %%a in ( %height% ) do echo.
echo %length%[]
choice /c wasd /n
if %errorlevel% equ 1 call:up
if %errorlevel% equ 2 call:left
if %errorlevel% equ 3 call:down
if %errorlevel% equ 4 call:right

:left
set length=!length:~0,-1!
goto controls

:right
set length=%length%
goto controls

:up
set height=!height:~0,-2!
goto controls

:down
set height=%height% a
goto control

As you can see, the code is very small (29 lines to be exact). This, I believe, is one of the smallest anyone has made.

Feel free to use it as the basis for any games to come, also, extra points if you make pong with it.

Code 2 (Grid Confined Movement)

In this code, your character will be confined to a "cage".

@setlocal enableextensions enabledelayedexpansion
@echo off
color 0a
title Movement 2 ~ Grid
cls
goto data

:data
set lespa=         
set rispa=         
set space=5
set err=0
set right=10
set left=10

:hud
cls
echo Move your character (X) with the WASD keys. Press R to reset
echo #######################
if %space% equ 0 if %err% neq 1 (
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 1 if %err% neq 1 (
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 2 if %err% neq 1 (
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 3 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 4 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 5 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 6 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 7 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     #
echo #                     # )
if %space% equ 8 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     #
echo #                     # )
if %space% equ 9 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%#
echo #                     # )
if %space% equ 10 if %err% neq 1 (
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #                     #
echo #%lespa%X%rispa%# )
echo #######################
echo.
echo.
choice /c wasdr /n
if %errorlevel% equ 1 goto w
if %errorlevel% equ 2 goto a
if %errorlevel% equ 3 goto s
if %errorlevel% equ 4 goto d
if %errorlevel% equ 5 goto data

:w
set /a space=%space%-1
if %space% lss 0 set space=0
goto hud

:a
set lespa=!lespa:~0,-1!
set /a left=%left%-1
if %left% lss 1 set left=1 && set lespa=%lespa%
set rispa=%rispa%
set /a right=%right%+1
if %right% gtr 19 set right=19 && set rispa=!rispa:~0,-1!
goto hud

:s
set /a space=%space%+1
if %space% gtr 10 set space=10
goto hud

:d
set rispa=!rispa:~0,-1!
set /a right=%right%-1
if %right% lss 1 set right=1 && set rispa=%rispa%
set lespa=%lespa%
set /a left=%left%+1
if %left% gtr 19 set left=19 && set lespa=!lespa:~0,-1!
goto hud