This answer covers both the "flicker" question and this one.
The flicker on the screen mainly depends on two factors: the size of the screen area that is updated (larger areas means more flicker) and how fast the commands that update the screen are executed (faster commands means less flicker).
For example, this code:
Code: Select all
:screen
cls
echo.
echo %u1%%u2%%u3%%u4%%u5%%u6%%u7%%u8%%u9%%u10%%u11%%u12%%u13%%u14%%u15%%u16%%u17%%u18%
echo %u19%%u20%%u21%%u22%%u23%%u24%%u25%%u26%%u27%%u28%%u29%%u30%%u31%%u32%%u33%%u34%%u35%%u36%
echo %u37%%u38%%u39%%u40%%u41%%u42%%u43%%u44%%u45%%u46%%u47%%u48%%u49%%u50%%u51%%u52%%u53%%u54%
echo %u55%%u56%%u57%%u58%%u59%%u60%%u61%%u62%%u63%%u64%%u65%%u66%%u67%%u68%%u69%%u70%%u71%%u72%
echo %u73%%u74%%u75%%u76%%u77%%u78%%u79%%u80%%u81%%u82%%u83%%u84%%u85%%u86%%u87%%u88%%u89%%u90%
... cause more flicker than this one:
Code: Select all
:screen
(
cls
echo/
echo %u1%%u2%%u3%%u4%%u5%%u6%%u7%%u8%%u9%%u10%%u11%%u12%%u13%%u14%%u15%%u16%%u17%%u18%
echo %u19%%u20%%u21%%u22%%u23%%u24%%u25%%u26%%u27%%u28%%u29%%u30%%u31%%u32%%u33%%u34%%u35%%u36%
echo %u37%%u38%%u39%%u40%%u41%%u42%%u43%%u44%%u45%%u46%%u47%%u48%%u49%%u50%%u51%%u52%%u53%%u54%
echo %u55%%u56%%u57%%u58%%u59%%u60%%u61%%u62%%u63%%u64%%u65%%u66%%u67%%u68%%u69%%u70%%u71%%u72%
echo %u73%%u74%%u75%%u76%%u77%%u78%%u79%%u80%%u81%%u82%%u83%%u84%%u85%%u86%%u87%%u88%%u89%%u90%
)
The reason is that in the first case each line is parsed and then executed individually, so from the execution of the "cls" until the execution of the last "echo" may pass a certain time. In the second case all the lines enclosed in parentheses are first parsed as a block, and then the whole block is executed as a unit, so the time between the "cls" and the last "echo" is less than in previous example. Also, the execution of "echo." may take more time than "echo/"; the reason is explained elsewhere in this forum. Finally, if each output line would be comprised of just one variable instead of 18 its execution would be faster, because takes less time to expand one variable than 18.
This way, in order to minimize the flicker in an animated game you should try to execute the less possible number of commands in each screen refresh (from the "cls" up to the last "echo"), and execute such commands in the fastest possible way. You may review a large example of an animated game that use all these techniques in this
Tetris game, that use just standard Batch commands.
Another way to minimize the flickering and play smoother animations is using external .exe programs that perform actions not available to standard Batch, like the Coulous.exe program you described. If a program can move the cursor the flicker is reduced in a large amount, because in this case the "cls" command is not longer necessary and the screen refresh just needs to update certain areas. However, the basic rules still apply: if the .exe program is a multi-purpose large application it will take more time to execute than a very small one, so smoother animations may be obtained via very small auxiliary .exe programs.
I developed a series of very efficient
auxiliary .exe commands designed for its use in Batch files that allows to move the cursor, show text in color, read cursor control keys or mouse clicks, etc. A large example of a game that use such programs is
this Batch file version of the 2048 game, that I think is very similar to your game in the way the keys are read and the game responds.
One problem that the auxiliary .exe files have is that the downloading of third party programs is restricted in certain places, so it is convenient to look for another way to get similar results via standard Windows features. One frequent solution is use PowerShell to read cursor keys, move the cursor or show text in color, but the PowerShell.exe application is contained in a 450 KB size file; this means that this method is slow and can not be used in games/animations.
I developed an interesting method that load the PowerShell application
just once and then it is repeatedly used from the Batch file code to read keys, move cursor, show colors, etc.; you may review such method at
this thread. After that, I modified the Tetris.bat game in order to use such method with very good results. I also modified the 2048.bat program, but this game was developed using auxiliary .exe commands, so in this case the modification was completed in a way that allows to select the original .exe programs or the PowerShell engine via a switch. A simple visual comparison of both methods conclude that the .exe programs one is still faster... You may review the modified version of the 2048.bat program in the same thread, below the
Tetris.bat one.
Antonio