Note that there are some explanatory texts on larger screens.

plurals
  1. POoptimization of a windows batch file arcade game
    primarykey
    data
    text
    <p>I made a batch file game, and it works, but it is choppy and ugly. I already know about threading, but I don't want to implement that in my first version. I am hoping to have the optimization down before I start doing more advanced things with this game. my question is this: What optimizations can I make to this game, so that it will 1. not be choppy and 2. not be quite so annoying in the display. any ideas or comments about how to make it faster clearer or take less memory are welcome, however, please do not post answers like: "don't use batch" "rewrite it in (insert language here)" "do this part with vb-script" etc... as they are not helpful, nor do they answer the question. any and all non batch hating criticism is welcomed.</p> <p>here is the code:</p> <pre><code>@setlocal enableextensions enabledelayedexpansion @echo off color 0a mode con lines=35 cols=50 cls set instructions=use a and d to move left and right, w to fire. use q to quit and p to pause. set height=30 set length= set screen=50 set swidth=20 set amo=8 set lives=3 set 1=0 set 2=1 set 3=2 set 4=3 set 5=4 set 6=0 set 7=1 set 8=2 set 9=3 set 10=4 echo. What quality would you like? echo. 1. fast, but the graphics suck! echo. 2. medium both ways. echo. 3. slow, but the graphics are better! choice /n /c:123 set firequal=%errorlevel%00 cls echo %instructions% echo. pause cls ::main :controls cls if %height% EQU 2 goto gameover if %lives% LSS 1 goto gameover cls set /a shouldbomb+=1 set /a whenbomb=shouldbomb%%15 if %whenbomb% == 9 call :bomb if '%ret%'=='1' exit /b set ret= cls set alive= for /l %%i in (1,1,10) do if defined %%i set alive=true if not defined alive goto win cls for /l %%i in (1,1,5) do ( if defined %%i ( set /p a=[_] &lt;nul ) else ( set /p a=... &lt;nul ) ) echo. for /l %%i in (6,1,10) do ( if defined %%i ( set /p a=[_] &lt;nul ) else ( set /p a=... &lt;nul ) ) for /l %%a in (1,1,%height%) do echo. echo %length%[] echo. for /l %%i in (1,1,%amo%) do set /p a=^|&lt;nul echo. choice /c adwqp0 /n /t 1 /d 0 if %errorlevel% equ 1 goto :left if %errorlevel% equ 2 goto :right if %errorlevel% equ 3 goto :fire if %errorlevel% equ 4 (cls&amp;exit /b) if %errorlevel% equ 5 pause&amp;goto controls if %errorlevel% equ 6 goto :inactive goto controls ::move player left :left if '!length!' NEQ '' set length=!length:~0,-1! goto controls ::move player right :right call :strlen shiplen length if %shiplen% GTR %swidth% goto controls set length=%length% goto controls ::fire a shot upwards :fire if '!amo!' LSS '1' goto controls cls set /a amo-=1 for /l %%i in (%height%,-1,2) do ( cls for /l %%i in (1,1,5) do ( if defined %%i ( set /p a=[_] &lt;nul ) else ( set /p a=... &lt;nul ) ) echo. for /l %%i in (6,1,10) do ( if defined %%i ( set /p a=[_] &lt;nul ) else ( set /p a=... &lt;nul ) ) for /l %%j in (1,1,%%i) do echo. echo %length% ^ set /a ship=height-%%i-1 for /l %%b in (1,1,!ship!) do echo. echo %length%[] echo. for /l %%i in (1,1,%amo%) do set /p a=^|&lt;nul echo. for /l %%a in (1,1,%firequal%) do call &gt;nul 2&gt;&amp;1 ) call :checkshot set /a shouldbomb+=1 set /a whenbomb=shouldbomb%%2 if %whenbomb% == 0 call :bomb goto controls :inactive if %amo% LSS 10 set /a amo+=1 if !height! NEQ 2 set /a height-=1 call :bomb goto controls :bomb :btop set bombx= for /l %%a in (1,1,10) do ( if defined %%a ( set /a randomnum=%random%%%5 if '!%%a!'=='%randomnum%' ( set /a "bombx=5*(!%%a!)" ) ) ) ) if not defined bombx goto btop cls set bomb= for /l %%b in (1,1,!bombx!) do ( set bomb=!bomb! ) set /a bombh=height-1 for /l %%c in (1,1,!bombh!) do ( cls for /l %%i in (1,1,5) do ( if defined %%i ( set /p a=[_] &lt;nul ) else ( set /p a=... &lt;nul ) ) echo. for /l %%i in (6,1,10) do ( if defined %%i ( set /p a=[_] &lt;nul ) else ( set /p a=... &lt;nul ) ) for /l %%b in (1,1,%%c) do echo. echo !bomb!x set /a ship=height-%%c-1 for /l %%b in (1,1,!ship!) do echo. echo %length%[] echo. for /l %%i in (1,1,%amo%) do set /p a=^|&lt;nul echo. for /l %%a in (1,1,%firequal%) do call &gt;nul 2&gt;&amp;1 ) if "%bomb%" == "%length%" call :looselife if "%bomb% " == "%length%" call :looselife if "%bomb%" == "%length% " call :looselife if "%bomb% " == "%length%" call :looselife if "%bomb%" == "%length% " call :looselife exit /b :strlen &lt;resultVar&gt; &lt;stringVar&gt; ( setlocal EnableDelayedExpansion set "s=!%~2!#" set "len=0" for %%P in (1024 512 256 128 64 32 16 8 4 2 1) do ( if "!s:~%%P,1!" NEQ "" ( set /a "len+=%%P" set "s=!s:~%%P!" ) ) ) ( endlocal set "%~1=%len%" exit /b ) :checkshot call :strlen slen length for /l %%i in (0,5,20) do ( if '!slen!' == '%%i' ( set /a hit=%%i set /a hit=hit/5+1 set /a hit2=hit+5 if not defined !hit2! set !hit!= if defined !hit2! set !hit2!= ) ) exit /b :looselife set /a lives-=1 set length= set 1=0 set 2=1 set 3=2 set 4=3 set 5=4 if %lives% GTR 1 timeout /nobreak 1 &gt;nul 2&gt;&amp;1 exit /b :win cls echo YOU WIN^!^!^!^! echo. echo GOOD JOB^!^!^! echo. pause cls exit /b :gameover cls echo YOU LOOSE. echo. echo PLEASE TRY AGAIN. echo. pause cls set ret=1 </code></pre> <p>thank you in advance for any help.</p> <p>P.S. I am writing this game to convince a friend to learn something besides html, and while batch isn't the best, he uses windows, and he will only do something simple for now. He is twelve, so I think batch is best option.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload