Question

I am trying to make a batch roguelike but I am running in to three main problems. First of all my message system is not working. Second there is a glitch where if i try to move somewhere where I can't the choice statement keeps writing the W, S, A, and D's at the bottom. Third and most importantly there is a very annoying flashing of the screen. I tried to minimize the time it takes to load but to no avail. Here is my code:

@echo off 
setlocal enableextensions
mode con: cols=54 lines=30
set num=1
set nextVar=1
set oldVar=103
set message=a
cls 
echo Loading...
:startup
if not %num%==1001 (
set b%num%=.
set /a num = %num% + 1
goto startup
)
cls
set b103=@
goto update

:update 
choice /c wsad /n /m ""
if %errorlevel%==1 set /a nextVar = %oldVar% - 50 
if %errorlevel%==2 set /a nextVar = %oldVar% + 50 
if %errorlevel%==3 set /a nextVar = %oldVar% - 1 
if %errorlevel%==4 set /a nextVar = %oldVar% + 1  
if defined b%nextVar% (
set b%nextVar%=@
set b%oldVar%=.
set oldVar=%nextVar%
set message="a"
goto display
)
set message="You can not move there."
goto update

:display
set ln1=%b1%%b2%%b3%...
set ln2=%b51%%b52%%b53%... 
set ln3=%b101%%b102%... 
...
...
...
set ln8=%b351%%b352%... 
set ln18=%b851%%b852%%b853% 
set ln19=%b901%%b902%%b903%%b904%... 
set ln20=%b951%%b952%%b953%%b954%%b955%%b956%...%b1000%
cls
if not "%message%"=="a" (
echo %message%
goto next
)
echo.
:next
echo.
echo %ln1%
echo %ln2%
echo %ln3%
echo %ln4%
echo %ln5%
echo %ln6%
echo %ln7%
echo %ln8%
echo %ln9%
echo %ln10%
echo %ln11%
echo %ln12%
echo %ln13%
echo %ln14%
echo %ln15%
echo %ln16%
echo %ln17%
echo %ln18%
echo %ln19%
echo %ln20%
echo.
goto update 

I had to ... some sections to save space. If anyone can solve these problems in particularity the screen flashing that would be super helpful. Also if anyone has ideas on generation NetHack like dungeons that would also be appreciated. Thank you.

Was it helpful?

Solution

So problems 1 and 2 are related.

First of all my message system is not working. Second there is a glitch where if i try to move somewhere where I can't the choice statement keeps writing the W, S, A, and D's at the bottom.

Change the error goto statement for the update section. You want to go to the display section so the screen is redrawn (removing the old used choice prompt) and the error message is displayed.

set message="You can not move there."
goto display

Problem 3 is a bit more difficult due to the nature of batch.

Third and most importantly there is a very annoying flashing of the screen.

The flashing is caused primarily because of one command. The cls command. Instead of just redrawing the screen it is first causing the screen to turn black before the new output is drawn causing the flicker.

Step 1: Remove the cls command. This means that you will have to output 30 lines each time to fill the screen.

Reducing the flicker even more will require a bigger overhaul on your script. Instead of echoing each line use the natural ability of the command window to wrap lines to draw the whole screen. This will reduce the amount of echo calls to a couple. Your canvas is set to 54 x 30 so that equals 1620 characters to fill the whole screen at one time.

Step 2: Output the entire screen with a single or as few calls as possible to prevent drawing/scrolling delay and use the natural line wrapping ability of the console window.

Here is an example I put together to illustrate this second step. Let me know if you have any questions.

@echo off
( if "%~1"=="" start "" /HIGH %0 1 & exit /b 1 )
setlocal enabledelayedexpansion
mode con: cols=80 lines=25
set "mark=0"
set "switch=0"

:next
if %mark% geq 920 set "mark=0" & if %switch% equ 0 ( set "switch=1" ) else set "switch=0"
set top=........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
set bot=........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
if %switch% equ 0 set top=!top:~0,%mark%!^|!top:~%mark%!
if %switch% equ 1 set bot=!bot:~0,%mark%!^|!bot:~%mark%!
goto display

:display
echo %mark%
set /p "=%top:~0,920%" <nul
set /p "=%bot:~0,920%" <nul
ping 192.0.2.2 -n 1 -w 200 >nul
set /a mark+=1
goto next

Step 3: An additional step that helps would be to increase the processes priority level. I have also added this to my example script above on the second line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top