Page 1 of 3

CmdRunner - 3d game (CubeRunner clone)

Posted: 18 Jun 2016 10:28
by misol101
Here's a little game using the latest functionality of my external tool cmdgfx.

Link: http://www.mediafire.com/download/wj9p9 ... runner.zip

It's a clone of the iOS game CubeRunner, where you are supposed to avoid oncoming obstacles by navigating your ship.

Press/hold cursor left/right to steer the ship.

Can you beat my record, 8110? :mrgreen:

Image

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 18 Jun 2016 10:34
by misol101
The game script looks as follows:

Code: Select all

:: CmdRunner : Mikael Sollenborn 2016
@echo off
setlocal ENABLEDELAYEDEXPANSION
bg font 0
set W=180&set H=110
mode con lines=%H% cols=%W%
mode con rate=31 delay=0
cmdwiz showcursor 0
color 07
for /F "Tokens=1 delims==" %%v in ('set') do if not %%v==H if not %%v==W set "%%v="
set RY=0

set /a XMID=%W%/2&set /a YMID=%H%/2-53
set DIST=2500
set ASPECT=1.13333
set DRAWMODE=0
set MAXCUBES=30
set GROUNDCOL=3
set ACCSPEED=350
set HISCORE=0&if exist hiscore.dat for /F "tokens=*" %%i in (hiscore.dat) do set HISCORE=%%i

set CUBECOL0=4 c db 4 c db  4 c b1  4 c b1  4 c 20 4 c 20
set CUBECOL1=6 0 db 6 0 db  6 e b1  6 e b1  6 e 20 6 e 20
set CUBECOL2=2 a db 2 a db  2 a b1  2 a b1  2 a 20 2 a 20
set CUBECOL3=5 d db 5 d db  5 d b1  5 d b1  5 d 20 5 d 20
set PLYCHAR=db

:OUTERLOOP
set NOFCUBES=15
set SCORE=0
set TILT=0
set ACTIVECUBES=0

set CURRZ=30000
set /A ACZ=%CURRZ%/%MAXCUBES%
for /L %%a in (1,1,%MAXCUBES%) do set /A CURRZ-=%ACZ% & set PZ%%a=!CURRZ!+ !RANDOM! %% %ACZ%& set /A PX%%a=!RANDOM! %% 8000 - 4000 & set /A PY%%a=-18000&set /A COLPAL=!RANDOM!%%4&for %%b in (!COLPAL!) do set CPAL%%a=!CUBECOL%%b!
set STARTINDEX=1

set BKSTR="fbox 0 1 b1 0,0,%W%,10 & fbox 0 1 20 0,10,%W%,5 & fbox 9 1 b1 0,15,%W%,5 & fbox 9 1 db 0,19,%W%,1  &  fbox 0 0 20 0,21,%W%,5 & fbox 0 %GROUNDCOL% b2 0,23,%W%,5 & fbox 0 %GROUNDCOL% b1 0,27,%W%,10 & fbox 0 %GROUNDCOL% b0 0,34,%W%,22 & fbox 8 %GROUNDCOL% 20 0,50,%W%,100 "
cmdgfx "%BKSTR:~1,-1%"
gotoxy 28 2 "\T20k40\I:CR2.gxy;"

:IDLELOOP
set CRSTR=""
set /A INDEX=%STARTINDEX%-1
for /L %%b in (1,1,%MAXCUBES%) do set /A INDEX+=1&(if !INDEX! gtr %MAXCUBES% set INDEX=1)& for %%a in (!INDEX!) do set CRSTR="!CRSTR:~1,-1! & 3d cube.ply %DRAWMODE% 0,%RY%,0 !PX%%a!,-1800,!PZ%%a! -250,0,0,0 0,0,0,10 %XMID%,%YMID%,%DIST%,%ASPECT% !CPAL%%a!"&set /A PZ%%a-=%ACCSPEED% & if !PZ%%a! lss 1000 set PZ%%a=30000&set /A PX%%a=!RANDOM! %% 8000 - 4000&set /A STARTINDEX-=1&if !STARTINDEX! lss 1 set STARTINDEX=%MAXCUBES%
cmdgfx "fbox 9 1 b1 0,15,%W%,5 & fbox 9 1 db 0,19,%W%,1  &  fbox 0 0 20 0,21,%W%,5 & fbox 0 %GROUNDCOL% b2 0,23,%W%,5 & fbox 0 %GROUNDCOL% b1 0,27,%W%,10 & fbox 0 %GROUNDCOL% b0 0,34,%W%,22 & fbox 8 %GROUNDCOL% 20 0,50,%W%,100 %CRSTR:~1,-1% & text f 1 _Press_SPACE_to_play_ 80,15" pk
set KEY=%ERRORLEVEL%
set /a RY+=8
if %KEY% == 27 goto ESCAPE
if not %KEY% == 32 goto IDLELOOP

:INGAMELOOP
set CRSTR=""
set /A INDEX=%STARTINDEX%-1
for /L %%b in (1,1,%MAXCUBES%) do set /A INDEX+=1&(if !INDEX! gtr %MAXCUBES% set INDEX=1)& for %%a in (!INDEX!) do set CRSTR="!CRSTR:~1,-1! & 3d cube.ply %DRAWMODE% 0,%RY%,0 !PX%%a!,!PY%%a!,!PZ%%a! -250,0,0,0 0,0,0,10 %XMID%,%YMID%,%DIST%,%ASPECT% !CPAL%%a!"&set /A PZ%%a-=%ACCSPEED% & if !PZ%%a! lss 1000 set PZ%%a=30000&set /A PX%%a=!RANDOM! %% 8000 - 4000 - %TILT%*50 &(if %ACTIVECUBES% leq !NOFCUBES! if !PY%%a! lss -1800 if !RANDOM! lss 10922 set /A PY%%a=-1800&set /A ACTIVECUBES+=1)&set /A STARTINDEX-=1&if !STARTINDEX! lss 1 set STARTINDEX=%MAXCUBES%

cmdgfx "%BKSTR:~1,-1% %CRSTR:~1,-1% & 3d tetramod.ply %DRAWMODE% 0,180,%TILT% 0,-1800,4000 -50,0,0,0 1,0,0,10 %XMID%,%YMID%,%DIST%,%ASPECT% f %GROUNDCOL% %PLYCHAR% 7 %GROUNDCOL% %PLYCHAR% & 3d tetramod.ply %DRAWMODE% 0,180,%TILT% 0,-1900,4000 -50,0,0,0 1,0,0,10 %XMID%,%YMID%,%DIST%,%ASPECT% 0 %GROUNDCOL% b2 0 %GROUNDCOL% b2 & text 7 1 SCORE:_%SCORE%_(%HISCORE%) 2,1" k
set KEY=%ERRORLEVEL%

for /L %%a in (1,1,%MAXCUBES%) do if !PY%%a! gtr -15000 if !PZ%%a! lss 4000 if !PZ%%a! gtr 3500 if !PX%%a! gtr -300 if !PX%%a! lss 300 (for /L %%a in (1,1,40) do set /A TILT+=40 & cmdgfx "%BKSTR:~1,-1% %CRSTR:~1,-1% & 3d tetramod.ply %DRAWMODE% 0,180,!TILT! 0,-1800,4000 -50,0,0,0 1,0,0,10 %XMID%,%YMID%,%DIST%,%ASPECT% f %GROUNDCOL% %PLYCHAR% 7 %GROUNDCOL% %PLYCHAR% & text 7 1 SCORE:_%SCORE%_(%HISCORE%) 2,1")&goto OUTERLOOP

set /A NOFCUBES=15+%SCORE%/250 & if !NOFCUBES! gtr %MAXCUBES% set NOFCUBES=%MAXCUBES%
if not %TILT%==0 (if %TILT% gtr 0 set /A TILT-=1) & (if %TILT% lss 0 set /A TILT+=1)

if %KEY%==331 set /A TILT+=7&if !TILT! gtr 55 set TILT=55
if %KEY%==333 set /A TILT-=7&if !TILT! lss -55 set TILT=-55
if %TILT% gtr 0 for /L %%a in (1,1,%MAXCUBES%) do set /A PX%%a+=%TILT%
if %TILT% lss 0 for /L %%a in (1,1,%MAXCUBES%) do set /A PX%%a+=%TILT%
set /a RY+=8
set /a SCORE+=1&if !SCORE! gtr %HISCORE% set HISCORE=!SCORE!
if not %KEY% == 27 goto INGAMELOOP
goto OUTERLOOP

:ESCAPE
echo %HISCORE%>hiscore.dat
endlocal
mode con cols=80 lines=50
cmdwiz showcursor 1
cls
bg font 6

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 20 Jun 2016 08:18
by batchcc
misol101 this is really cool do you think you could make something like this http://armorgames.com/play/12614/city-s ... ngle-siege
Thanks for cube runner!

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 21 Jun 2016 10:14
by misol101
Thanks batchcc!

Umm... well I mean it would be *possible* to make a game like that, but I can't say I intend to... Needs a lot more design/graphics compared to CmdRunner, which is just simple 3d shapes.

But... I would certainly both applaud and help/support anybody else trying to make a 2d runner/shooter with the help of cmdgfx and possibly my other tools.

Your question prompted me to try making a parallax scroller for a 2d game. Here I use only simple primitives (filled ellipses and boxes), but I think the result looks OK anyway.

Screenshot: http://www.mediafire.com/view/ywckaupke61reo2/hills.PNG

Here is the script for this. You need cmdgfx.exe and bg.exe in the same folder. Press SPACE while running to hide the ridiculous "running man"/player. Press cursor left/right to change direction.

Code: Select all

:: Hills parallax scroller : Mikael Sollenborn 2016
@echo off
setlocal ENABLEDELAYEDEXPANSION
cls & bg font 0
set W=240&set H=110
mode con lines=%H% cols=%W%
color 07

set MIN_ADV_L1=60
set /A HILLS_L1=%W%/%MIN_ADV_L1% + 2
set /A WX=0
for /L %%b in (1,1,%HILLS_L1%) do set WL1_%%b=!WX!&set /A WLW1_%%b=!RANDOM!%%40+30&set /A WLH1_%%b=!WLW1_%%b!+!RANDOM!%%37&set /A WX+=!RANDOM! %% 60 + %MIN_ADV_L1%&set /A WLW1b_%%b=!WLW1_%%b!+5

set MIN_ADV_L2=60
set /A HILLS_L2=%W%/%MIN_ADV_L2% + 2
set /A WX=0
for /L %%b in (1,1,%HILLS_L2%) do set WL2_%%b=!WX!&set /A WLW2_%%b=!RANDOM!%%30+20&set /A WLH2_%%b=!WLW2_%%b!+!RANDOM!%%19+50&set /A WX+=!RANDOM! %% 60 + %MIN_ADV_L2%&set /A WLW2b_%%b=!WLW2_%%b!+2

set SHOW_PLY=1
set /A WMAX=%W%+100
set DIR=1

set CNT=0
:SHOWLOOP
set L1=""
set /A ADD=%DIR%*(1+%CNT% %% 2)
for /L %%a in (1,1,%HILLS_L1%) do set /A WL1_%%a-=%ADD% & set CX=!WL1_%%a!& set L1="!L1:~1,-1! & fellipse 2 0 20 !CX!,98,!WLW1b_%%a!,!WLH1_%%a! & fellipse a 0 b1 !CX!,100,!WLW1_%%a!,!WLH1_%%a! & fellipse a 0 db !CX!,120,!WLW1_%%a!,!WLH1_%%a!"& set /A CX+=!WLW1_%%a!*%DIR% & set OUT=0&(if %DIR%==1 if !CX! lss -100 set OUT=1&set /A INDEX=%%a-1&if !INDEX! lss 1 set INDEX=%HILLS_L1%)&(if %DIR%==-1 if !CX! gtr %WMAX% set OUT=1&set /A INDEX=%%a+1&if !INDEX! gtr %HILLS_L1% set INDEX=1)&if !OUT!==1 for %%b in (!INDEX!) do set /A WL1_%%a=!WL1_%%b! + !RANDOM!*%DIR% %% 60 + %MIN_ADV_L1%*%DIR%&set /A WLW1_%%a=!RANDOM!%%40+30&set /A WLW1b_%%a=!WLW1_%%a!+5&set /A WLH1_%%a=!WLW1_%%a!+!RANDOM!%%37
set L2=""
set /A ADD=%DIR%*(1+%CNT% %% 1)
for /L %%a in (1,1,%HILLS_L2%) do set /A WL2_%%a-=%ADD% & set CX=!WL2_%%a!& set L2="!L2:~1,-1! & fellipse 2 0 20 !CX!,99,!WLW2b_%%a!,!WLH2_%%a! & fellipse 2 0 b0 !CX!,100,!WLW2_%%a!,!WLH2_%%a! & fellipse 2 0 db !CX!,110,!WLW2_%%a!,!WLH2_%%a!"& set /A CX+=!WLW2_%%a!*%DIR%& set OUT=0&(if %DIR%==1 if !CX! lss -100 set OUT=1&set /A INDEX=%%a-1&if !INDEX! lss 1 set INDEX=%HILLS_L2%)&(if %DIR%==-1 if !CX! gtr %WMAX% set OUT=1&set /A INDEX=%%a+1&if !INDEX! gtr %HILLS_L2% set INDEX=1)&if !OUT!==1 for %%b in (!INDEX!) do set /A WL2_%%a=!WL2_%%b! + !RANDOM!*%DIR% %% 60 + %MIN_ADV_L2%*%DIR%&set /A WLW2_%%a=!RANDOM!%%30+20&set /A WLW2b_%%a=!WLW2_%%a!+2&set /A WLH2_%%a=!WLW2_%%a!+!RANDOM!%%19+50

set PLY="" & if %SHOW_PLY% == 1 set /A LEG1=23+%CNT% %% 7 & set /A LEG2=28-%CNT% %% 7 & set PLY="fellipse c 4 b1 25,95,7,5 & fellipse c 7 b1 25,88,4,3 & fellipse c 4 b1 !LEG1!,100,2,5 & fellipse c 4 b1 !LEG2!,100,2,5"
cmdgfx "fbox 1 9 b2 0,0,%W%,10 & fbox 1 9 b1 0,3,%W%,10 & fbox 1 9 b0 0,9,%W%,%H% & %L2:~1,-1% & %L1:~1,-1% & fbox a 0 20 0,95,%W%,50 & fbox a e b2 0,96,%W%,50 & fbox a e b1 0,102,%W%,50 & %PLY:~1,-1%" k
if !ERRORLEVEL!==27 goto ESCAPE
if !ERRORLEVEL!==331 set DIR=-1
if !ERRORLEVEL!==333 set DIR=1
if !ERRORLEVEL!==32 set /A SHOW_PLY=1-%SHOW_PLY%
set /A CNT+=1
goto SHOWLOOP

:ESCAPE
endlocal
mode con cols=80 lines=50
cls & bg font 6

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 21 Jun 2016 13:21
by misol101
Changed the parallax script above so that it can run in both directions. Use cursor left/right to switch.

(also, my high score for CmdRunner is now 10475 :wink: )

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 22 Jun 2016 14:07
by misol101
Well, thanks again to batchcc! The question asked made me realize that something vital was missing from cmdgfx to make 2d games: sprites/images. So I added that, gxy files and pcx files can now be used.

Also, the parallax scroller is now included in the cmdgfx.zip archive, download from http://www.mediafire.com/download/x2lrkla93bd149o/cmdgfx.zip

The player has now become Super Mario, a sprite :) Press Up to jump :)

Screenshot: http://www.mediafire.com/view/p44w8wn6bw54koh/mariohills.PNG

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 22 Jun 2016 15:12
by batchcc
Thank you for creating this I haven't tried it yet but it looks cool; can't wait to play!

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 22 Jun 2016 15:18
by misol101
batchcc wrote:Thank you for creating this I haven't tried it yet but it looks cool; can't wait to play!


Ah, hate to disappoint, but unlike CmdRunner the Mario thing is not a game, just the bare bones of what could become a game, should anyone be so inclined.

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 23 Jun 2016 14:04
by misol101
Archive updated.

I was looking at a 3d batch script by einstein1969,and found the line:

for /F "Tokens=1 delims==" %%v in ('set') do set "%%v="

Clever little thing, and amazing how much it speeds things up to clean the environment from variables!

So I tried it for this game and got a speed increase of about 8% on my machine, so I decided to make an update.

Thanks to einstein1969 and whoever came up with it in the first place.

I'm sure there are many other clever speedup tricks to be found, if you know of one please let me know! :)

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 23 Jun 2016 16:36
by foxidrive
Clearing the environment is great

That's going to clear windows variables and even the PATH in your game, so just saying here that some extra work may need doing to restore some, or filter some out.

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 25 Jun 2016 04:52
by misol101
The cmdrunner archive was updated (see top for link), and now includes a second batch file called cmdrunner_fog.bat.

As the name indicates, if you run cmdrunner_fog.bat, then you get "fog" in the game, i.e. cubes in the background are less visible. This looks better IMHO, but the downside is that the game runs about 15-20% slower. But hey, the game is easier when it's slower, so it could help your score! :mrgreen:

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 26 Jun 2016 11:22
by einstein1969
misol101 wrote:Archive updated.

I was looking at a 3d batch script by einstein1969,and found the line:

for /F "Tokens=1 delims==" %%v in ('set') do set "%%v="

Clever little thing, and amazing how much it speeds things up to clean the environment from variables!

So I tried it for this game and got a speed increase of about 8% on my machine, so I decided to make an update.

Thanks to einstein1969 and whoever came up with it in the first place.

I'm sure there are many other clever speedup tricks to be found, if you know of one please let me know! :)


Very good work misol101 8)

For achieve major performnce you can do this:
- Use one set/A using comma separator instead using set/A&set/a&....
- Using a for /L %%. () do for a loop instead using GOTO :label
- Do not execute every time cmdgfx. manage input into cmdgfx or use a parallel process. Look at work done in batchSNAKE by dbenham or other work done by aAcini. http://www.dostips.com/forum/viewtopic.php?f=3&t=6601

einstein1969

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 26 Jun 2016 15:15
by misol101
einstein1969 wrote:For achieve major performnce you can do this:
1 - Use one set/A using comma separator instead using set/A&set/a&....
2 - Using a for /L %%. () do for a loop instead using GOTO :label
3 - Do not execute every time cmdgfx. manage input into cmdgfx or use a parallel process. Look at work done in batchSNAKE by dbenham or other work done by aAcini. http://www.dostips.com/forum/viewtopic.php?f=3&t=6601


1 - That's something I should start doing, definitely. I don't think in this script that it would matter much (very few repeated "set" in the time critical sections). Perhaps if I re-structured things.
2 - I have found that to be true as well, so I use no GOTO loops except for the "infinite" ones in this script. Can I get rid of them too somehow, i.e. can I create infinite for loops? (actually I have discovered a way to make infinite for loops (a double "for /R" with folder creation in the loop), but it's slower than a regular GOTO loop :) )
3 - In this script and in general I concatenate strings and only run cmdgfx.exe once per frame. Is that what you mean by "manage input?"
Parallell processing sounds interesting! (and kind of tricky, I'll read the link)

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 26 Jun 2016 15:42
by aGerman
2 - I have found that to be true as well, so I use no GOTO loops except for the "infinite" ones in this script. Can I get rid of them too somehow, i.e. can I create infinite for loops? (actually I have discovered a way to make infinite for loops (a double "for /R" with folder creation in the loop), but it's slower than a regular GOTO loop :) )


Leave the parentheses empty to run an infinite loop like for /l %%i in () do ...
But FOR /L loops are unbreakable:

Code: Select all

@prompt $g &setlocal EnableDelayedExpansion &set i=0
for /l %%i in () do (
  set /a i+=1
  echo !i!
  if !i!==100 goto endloop
)
:endloop
pause

Result:

Code: Select all

.
.
.
> (
set /a i+=1
 echo !i!
 if !i! == 100 goto endloop
)
98

> (
set /a i+=1
 echo !i!
 if !i! == 100 goto endloop
)
99

> (
set /a i+=1
 echo !i!
 if !i! == 100 goto endloop
)
100

> (
set /a i+=1
 echo !i!
 if !i! == 100 goto endloop
)

> (
set /a i+=1
 echo !i!
 if !i! == 100 goto endloop
)

> (
set /a i+=1
 echo !i!
 if !i! == 100 goto endloop
)
.
.
.

The loop never stops even if everything in the loop isn't executed anymore after i was 100.
There is a way around using EXIT which means you have to run another cmd process. See viewtopic.php?t=2707

Sometimes GOTO loops make more sense :wink:

Re: CmdRunner - 3d game (CubeRunner clone)

Posted: 26 Jun 2016 17:13
by misol101
aGerman wrote:Leave the parentheses empty to run an infinite loop like for /l %%i in () do ...

The loop never stops even if everything in the loop isn't executed anymore after i was 100.
There is a way around using EXIT which means you have to run another cmd process. See viewtopic.php?t=2707


Ahh, ok, I didn't know about the empty parantheses. Interesting solution with the "while loop" there though. But doesn't make sense for this game (edit: was curious, so changed gameloop into a WHILE loop Aacini style... no noticeable speed difference).

By the way, my completely strange attempt at creating an infinite for loop is below. It works for me, but would be interesting to know if it does for others. I feel there is a big chance it won't (maybe due to drive read/write speed etc). Create a new folder to put this in before trying, a LOT of empty folders are created/removed while running this :mrgreen:

Code: Select all

@echo off
setlocal ENABLEDELAYEDEXPANSION

set /A "STOP=0, TAIL=30, CNT=0" & set /A CNT2=-!TAIL!
for /R . %%a in (.) do if !STOP! == 0 for /R . %%a in (.) do if !STOP!==0 rd !CNT2! 2>nul&rd !CNT2!a 2>nul&md !CNT! 2>nul&md !CNT!a 2>nul&set /A "CNT+=1, CNT2+=1"& (

  echo !CNT!
  if !CNT!==2000 set STOP=1
)
for /L %%a in (1,1,%TAIL%) do rd !CNT2!&rd !CNT2!a&set /A CNT2+=1

endlocal


I get infinite run for TAIL value of 20 or higher. 19 only makes this run 195 times (yeah, it's weird :) )

Unfortunately the looping is slower than a regular GOTO loop (atleast for short jumps), but if it works for others too, then perhaps it can be modified to make it better.


Edit: Here is a faster version. It actually seems to be faster than regular GOTO. For 10000 iterations with some dummy SET's in the loop, I get: FOR /R:10s GOTO: 13s NORMAL FOR /L 1-10000: 2s. Ummm, yeah, remains to be seen if it works for anybody else though.

Code: Select all

@echo off
setlocal ENABLEDELAYEDEXPANSION

set /A "STOP=0, TAIL=30, CNT=0" & set /A CNT2=-!TAIL!
for /R %%a in (.) do if !STOP! == 0 for /R %%a in (.) do if !STOP! == 0 for /R %%a in (.) do if !STOP!==0 rd !CNT2! 2>nul&md !CNT! 2>nul&set /A "CNT+=1, CNT2+=1"& (

  echo !CNT!
  if !CNT!==2000 set STOP=1
)
for /L %%a in (1,1,%TAIL%) do rd !CNT2!&set /A CNT2+=1

endlocal