Can anyone help me clean up this code?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
(_osd_)
Posts: 25
Joined: 01 Mar 2015 07:41

Can anyone help me clean up this code?

#1 Post by (_osd_) » 13 Aug 2016 09:54

As the screen flickers quite often while moving (WASD), I was wondering if the code could be cleaned up to run faster. Can you help me? Would be greatly appreciated :)


Code: Select all

@echo off
setlocal EnableDelayedExpansion
mode con cols=56 lines=18
color f0

for /L %%i in (58,1,503) do set "u%%i=±"

for /L %%i in (1,1,57) do set "u%%i=Û"
for /L %%i in (505,1,559) do set "u%%i=Û"

for /L %%i in (113,56,505) do set "u%%i=Û"
for /L %%i in (112,56,560) do set "u%%i=Û"


::set first position of the player
set "u119=#"
set position=119

::set the movements
set "mov[1]=-56"
set "mov[2]=-1"
set "mov[3]=56"
set "mov[4]=1"

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:screen
title %position%
cls
echo.
echo ########################################################
echo %u1%%u2%%u3%%u4%%u5%%u6%%u7%%u8%%u9%%u10%%u11%%u12%%u13%%u14%%u15%%u16%%u17%%u18%%u19%%u20%%u21%%u22%%u23%%u24%%u25%%u26%%u27%%u28%%u29%%u30%%u31%%u32%%u33%%u34%%u35%%u36%%u37%%u38%%u39%%u40%%u41%%u42%%u43%%u44%%u45%%u46%%u47%%u48%%u49%%u50%%u51%%u52%%u53%%u54%%u55%%u56%
echo %u57%%u58%%u59%%u60%%u61%%u62%%u63%%u64%%u65%%u66%%u67%%u68%%u69%%u70%%u71%%u72%%u73%%u74%%u75%%u76%%u77%%u78%%u79%%u80%%u81%%u82%%u83%%u84%%u85%%u86%%u87%%u88%%u89%%u90%%u91%%u92%%u93%%u94%%u95%%u96%%u97%%u98%%u99%%u100%%u101%%u102%%u103%%u104%%u105%%u106%%u107%%u108%%u109%%u110%%u111%%u112%
echo %u113%%u114%%u115%%u116%%u117%%u118%%u119%%u120%%u121%%u122%%u123%%u124%%u125%%u126%%u127%%u128%%u129%%u130%%u131%%u132%%u133%%u134%%u135%%u136%%u137%%u138%%u139%%u140%%u141%%u142%%u143%%u144%%u145%%u146%%u147%%u148%%u149%%u150%%u151%%u152%%u153%%u154%%u155%%u156%%u157%%u158%%u159%%u160%%u161%%u162%%u163%%u164%%u165%%u166%%u167%%u168%
echo %u169%%u170%%u171%%u172%%u173%%u174%%u175%%u176%%u177%%u178%%u179%%u180%%u181%%u182%%u183%%u184%%u185%%u186%%u187%%u188%%u189%%u190%%u191%%u192%%u193%%u194%%u195%%u196%%u197%%u198%%u199%%u200%%u201%%u202%%u203%%u204%%u205%%u206%%u207%%u208%%u209%%u210%%u211%%u212%%u213%%u214%%u215%%u216%%u217%%u218%%u219%%u220%%u221%%u222%%u223%%u224%
echo %u225%%u226%%u227%%u228%%u229%%u230%%u231%%u232%%u233%%u234%%u235%%u236%%u237%%u238%%u239%%u240%%u241%%u242%%u243%%u244%%u245%%u246%%u247%%u248%%u249%%u250%%u251%%u252%%u253%%u254%%u255%%u256%%u257%%u258%%u259%%u260%%u261%%u262%%u263%%u264%%u265%%u266%%u267%%u268%%u269%%u270%%u271%%u272%%u273%%u274%%u275%%u276%%u277%%u278%%u279%%u280%
echo %u281%%u282%%u283%%u284%%u285%%u286%%u287%%u288%%u289%%u290%%u291%%u292%%u293%%u294%%u295%%u296%%u297%%u298%%u299%%u300%%u301%%u302%%u303%%u304%%u305%%u306%%u307%%u308%%u309%%u310%%u311%%u312%%u313%%u314%%u315%%u316%%u317%%u318%%u319%%u320%%u321%%u322%%u323%%u324%%u325%%u326%%u327%%u328%%u329%%u330%%u331%%u332%%u333%%u334%%u335%%u336%
echo %u337%%u338%%u339%%u340%%u341%%u342%%u343%%u344%%u345%%u346%%u347%%u348%%u349%%u350%%u351%%u352%%u353%%u354%%u355%%u356%%u357%%u358%%u359%%u360%%u361%%u362%%u363%%u364%%u365%%u366%%u367%%u368%%u369%%u370%%u371%%u372%%u373%%u374%%u375%%u376%%u377%%u378%%u379%%u380%%u381%%u382%%u383%%u384%%u385%%u386%%u387%%u388%%u389%%u390%%u391%%u392%
echo %u393%%u394%%u395%%u396%%u397%%u398%%u399%%u400%%u401%%u402%%u403%%u404%%u405%%u406%%u407%%u408%%u409%%u410%%u411%%u412%%u413%%u414%%u415%%u416%%u417%%u418%%u419%%u420%%u421%%u422%%u423%%u424%%u425%%u426%%u427%%u428%%u429%%u430%%u431%%u432%%u433%%u434%%u435%%u436%%u437%%u438%%u439%%u440%%u441%%u442%%u443%%u444%%u445%%u446%%u447%%u448%
echo %u449%%u450%%u451%%u452%%u453%%u454%%u455%%u456%%u457%%u458%%u459%%u460%%u461%%u462%%u463%%u464%%u465%%u466%%u467%%u468%%u469%%u470%%u471%%u472%%u473%%u474%%u475%%u476%%u477%%u478%%u479%%u480%%u481%%u482%%u483%%u484%%u485%%u486%%u487%%u488%%u489%%u490%%u491%%u492%%u493%%u494%%u495%%u496%%u497%%u498%%u499%%u500%%u501%%u502%%u503%%u504%
echo %u505%%u506%%u507%%u508%%u509%%u510%%u511%%u512%%u513%%u514%%u515%%u516%%u517%%u518%%u519%%u520%%u521%%u522%%u523%%u524%%u525%%u526%%u527%%u528%%u529%%u530%%u531%%u532%%u533%%u534%%u535%%u536%%u537%%u538%%u539%%u540%%u541%%u542%%u543%%u544%%u545%%u546%%u547%%u548%%u549%%u550%%u551%%u552%%u553%%u554%%u555%%u556%%u557%%u558%%u559%%u560%
echo ########################################################
choice /C WASD /N
set /A newPos=position+mov[%errorlevel%]
if "!u%newPos%!"=="Û" goto screen

:refresh
set "u%position%=±"
set "position=%newPos%"
set "u%position%=#"
goto screen

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Can anyone help me clean up this code?

#2 Post by aGerman » 13 Aug 2016 10:15

You clear the screen and write its content new all the time. Flickering is more or less the normal behavior then. Search the forum for "antiflicker". einstein1969 made a lot of efforts to suppress it.

Regards
aGerman

(_osd_)
Posts: 25
Joined: 01 Mar 2015 07:41

Re: Can anyone help me clean up this code?

#3 Post by (_osd_) » 14 Aug 2016 06:30

Nevermind, I found a way to fix the flickering myself.

/close

douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: Can anyone help me clean up this code?

#4 Post by douglas.swehla » 14 Aug 2016 10:43

(_osd_) wrote:I found a way to fix the flickering myself.


Please share your solution, and let us know how it compares to einstein1969's.

(_osd_)
Posts: 25
Joined: 01 Mar 2015 07:41

Re: Can anyone help me clean up this code?

#5 Post by (_osd_) » 14 Aug 2016 11:33

douglas.swehla wrote:
(_osd_) wrote:I found a way to fix the flickering myself.


Please share your solution, and let us know how it compares to einstein1969's.


It uses Colous.exe, an external program to display colors in batch, but can be used instead of cls as well.
Download for Colous.exe: http://www.mediafire.com/download/jzem4xtymkd/colous.exe
Link to the guy who made Colous.exe: https://diamam.blogspot.de/2010/10/ya-llega-colous-v6.html

Use this code to test the method:

Code: Select all

@echo off
title Flickering test
:q
echo use anti-flicker? [y/n]
set /p q1=
if "%q1%"=="y" goto antiflicker1
if "%q1%"=="n" goto noantiflicker
:antiflicker1
cls
:antiflicker
colous 0 0 1,1
echo %random%
echo Flickering yet?
goto antiflicker

:noantiflicker
cls
echo %random%
echo Flickering yet?
goto noantiflicker


It works pretty good in my opinion :)

douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: Can anyone help me clean up this code?

#6 Post by douglas.swehla » 14 Aug 2016 12:14

(_osd_) wrote:It uses Colous.exe, an external program to display colors in batch, but can be used instead of cls as well.
Download for Colous.exe: http://www.mediafire.com/download/jzem4xtymkd/colous.exe
Link to the guy who made Colous.exe: https://diamam.blogspot.de/2010/10/ya-llega-colous-v6.html

Thanks for sharing!

(_osd_) wrote:It works pretty good in my opinion :)

Good to know. Have you compared it to any of the solutions in either these posts?
Anti-Flicker in dos batch.
Another "MODE" trick demo

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Can anyone help me clean up this code?

#7 Post by aGerman » 14 Aug 2016 12:36

The reason why it works is that the content was overwritten instead of cleared out via CLS.
You will find a few "CursorPos" or "GotoXY" 3rd party apps here at DosTips too.
http://www.dostips.com/forum/viewtopic.php?f=3&t=3428
http://www.dostips.com/forum/viewtopic.php?f=3&t=7129

You could even compile your own from scratch.
http://www.dostips.com/forum/viewtopic.php?f=3&p=27555#p27555

(_osd_)
Posts: 25
Joined: 01 Mar 2015 07:41

Re: Can anyone help me clean up this code?

#8 Post by (_osd_) » 14 Aug 2016 13:11

douglas.swehla wrote:
(_osd_) wrote:It uses Colous.exe, an external program to display colors in batch, but can be used instead of cls as well.
Download for Colous.exe: http://www.mediafire.com/download/jzem4xtymkd/colous.exe
Link to the guy who made Colous.exe: https://diamam.blogspot.de/2010/10/ya-llega-colous-v6.html

Thanks for sharing!

(_osd_) wrote:It works pretty good in my opinion :)

Good to know. Have you compared it to any of the solutions in either these posts?
Anti-Flicker in dos batch.
Another "MODE" trick demo


The Mode-Trick flashes a lot for me, so I can't use it.
And for me, the Anti-Flicker by einstein1969 is slower than colous.exe.

Post Reply