Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & setlocal enableDelayedExpansion
- call :canvas 50 40
- set "balls=6"
- for /l %%a in (1,1,%balls%) do (
- set /a "di[%%a]=!random! %% 3 + 1", "dj[%%a]=!random! %% 2 + 1"
- set /a "dr[%%a]=!random! %% 4 + 1", "ds[%%a]=!random! %% 2"
- set /a "dw[%%a]=width - dr[%%a] - 1", "dh[%%a]=height - dr[%%a] - 1"
- set /a "ds[%%a]=!random! %% 1"
- )
- for %%a in (I C A R U S) do set /a "c+=1" & set "dc[!c!]=%%a"
- set /a "dx[0]=23", "dy[0]=20", "dx[1]=24", "dy[1]=20", "dx[2]=25", "dy[2]=20", "dx[3]=26", "dy[3]=20", "dx[4]=27", "dy[4]=20", "dx[5]=28", "dy[5]=20"
- call :print 23 20 "ICARUS"
- call :showCanvas
- timeout /t 2 /nobreak > nul
- :loop
- for /l %%a in (1,1,%balls%) do (
- set /a "dx[%%a]+=di[%%a] + ds[%%a]"
- set /a "dy[%%a]+=dj[%%a] + ds[%%a]"
- if !dx[%%a]! gtr !dw[%%a]! set /A "dx[%%a]=dw[%%a]", "di[%%a]*=-1"
- if !dx[%%a]! lss !dr[%%a]! set /A "dx[%%a]=dr[%%a]", "di[%%a]*=-1"
- if !dy[%%a]! gtr !dh[%%a]! set /A "dy[%%a]=dh[%%a]", "dj[%%a]*=-1"
- if !dy[%%a]! lss !dr[%%a]! set /A "dy[%%a]=dr[%%a]", "dj[%%a]*=-1"
- call :plot !dx[%%a]! !dy[%%a]! !dc[%%a]!
- REM call :ellipse !dx[%%a]! !dy[%%a]! !dr[%%a]!
- )
- call :showCanvas
- call :updateCanvas
- if !l! neq 4000 ( set /a "l+=1" & goto :loop ) else exit /b
- rem ---------------------------------------------------------------------------------------
- dx = Ball X position
- dy = Ball Y position
- di = Ball X direction
- dj = Ball Y direction
- dr = Ball Radius
- ds = Ball Speed
- dw = Ball max width boundry
- dh = Ball max height boundry
- dc = Ball character
- rem All functions below this line.
- rem ---------------------------------------------------------------------------------------
- :canvas
- set /a "width=%~1 - 1", "height=%~2 - 1", "_=-1", "conWidth=width + 4", "conHeight=height + 5"
- if exist cursorpos.exe ( set "cls=cursorpos 0 0" ) else ( set "cls=cls" )
- for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
- for /l %%a in (0,1,%width%) do set "widthBuffer=!widthBuffer! "
- call :updateCanvas
- mode con: cols=%conWidth% lines=%conHeight%
- goto :eof
- :updateCanvas
- set "_=-1"
- for /l %%a in (0,1,%height%) do set /a "_+=1" & set "_[!_!]=%widthBuffer%"
- set "_="
- goto :eof
- :showCanvas
- %cls%
- echo=%outerBuffer%
- for /l %%a in (0,1,%height%) do echo=#!_[%%a]!#
- echo=%outerBuffer%
- goto :eof
- goto :eof
- :plot x y
- setlocal
- set /a "_x2=%~1 + 1"
- (endlocal
- set "_[%~2]=!_[%~2]:~0,%~1!%~3!_[%~2]:~%_x2%!"
- )
- goto :eof
- :ellipse x y r
- for /l %%y in (-%~3,1,%~3) do for /l %%x in (-%~3,1,%~3) do (
- set /a "t=-%~3 - 1", "S=(%%x * %%x) + (%%y * %%y) - (%~3 * %~3) + t + %~3"
- if !S! geq !t! if !S! leq 1 ( set /a "x=%%x + %~1", "y=%%y + %~2" & call :plot !x! !y! ".")
- )
- goto :eof
- :print x y
- setlocal
- call :length "%~3" _x2
- set /a "_x2+=%~1"
- (endlocal
- set "_[%~2]=!_[%~2]:~0,%~1!%~3!_[%~2]:~%_x2%!"
- )
- goto :eof
- :length
- setlocal
- set "str=X%~1"
- set length=0
- for /L %%a in (8,-1,0) do (
- set /a "length|=1<<%%a"
- for %%b in (!length!) do if "!str:~%%b,1!" equ "" set /a "length&=~1<<%%a"
- )
- (endlocal
- if "%~2" neq "" ( set "%2=%length%" ) else echo %length%
- )
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement