Advertisement
T3RRYT3RR0R

SpriteDemo.bat

Dec 22nd, 2020 (edited)
1,407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 14.77 KB | None | 0 0
  1. ========================================================================================================
  2. ::: [ * SpriteDemo.bat ; Author: T3RRY { https://stackoverflow.com/users/12343998/t3rr0r } * ]
  3. ::: [ * Game_Engine.bat ;  Author: T3RRY { https://stackoverflow.com/users/12343998/t3rr0r } * ]
  4. ::::::::::::::::::::::::::::
  5. ::: Additional Accreditation
  6. ::: Getkey.Exe by Antonio { https://stackoverflow.com/users/778560/aacini }
  7. ::: * REQUIRED * for Extended key controls.
  8. ::: Sleep.bat by Dave Benham { https://stackoverflow.com/users/1012053/dbenham }
  9. ::: - Not required; allows for more precise sub second delays than other methods.
  10. ::: DOWNLOAD ALL + More Games_By_T3RRY from:
  11. ::: https://drive.google.com/file/d/1cAQLd-f9HN6SuWowBUETccKCZd2dVbWj/view?usp=sharing
  12. ::::::::::::::::::::::::::::
  13. ::: Script prep
  14. @Echo off & CD "%~dp0"
  15.  CHCP 65001 > nul
  16.  cls
  17.  Set "Delay=If exist Sleep.bat ( Call sleep.bat ? !time! )Else (For /L %%n in (1 1 10)Do ( Call :Delay 2> nul ))"
  18.  Call "Game_Engine.bat" || (Echo/Game_Engine.bat missing & Exit /B 0)
  19. rem/* PC.Prompt Macro - Supplemental Info displayed below control panel; shows information relating to PC status {Arg 1} and Obj=NPC status {Arg 2} */
  20.  Set "PC.Prompt=For %%n in (1 2)Do if %%n==2 (For /F "Tokens=1,2 Delims={}" %%G in ("!PC.NPC!")Do ( < Nul Set /P "=%\E%[10;!CNTRL!H%\E%[!Player.Color!mPlayer: %%G%\E%[0m   %\E%!!!!!!H%\E%[!Obj.Color!mObj: %%H%\E%[0m     " ))Else Set PC.NPC="
  21. rem/* G.O - Supplemental Gameflow macro. Use Substitution to exchange :start for another valid label to implement levels as exampled further below */
  22.  Set "G.O=Call :End & Endlocal & Goto :start"
  23. ========================================================================================================
  24. ::: Script main body
  25. ========================================================================================================
  26. :start
  27. CLS
  28.  Set "lvl=1"
  29.  Setlocal EnableDelayedExpansion
  30.  %MSG:?= Generating Border ...%
  31. ::::: Background.Border
  32. ::::   Defines critical Variables used by other Sprite Macros - Must be expanded first.
  33. :::    Extensive error testing performed in Background.Border due to dependencies of
  34. :::    other macros. As the border is not animated; Time Intensive testing can be performed.
  35. :::    Move.Sprite Rotate.Sprite and Show cannot engage in the same degree of testing without
  36. :::    grossly slowing animation speed
  37. ::: USAGE:
  38. ::: %Background.Border%{VTcolor}{.Xmin}{.Xmax}{.Ymin}{.Ymax}{.Char}{0|-1}
  39. ::: Override default control info panel width. [ default = 20 ]
  40. ::: %Background.Border:CNTRL.Width=INTEGER%{VTcolor}{.Xmin}{.Xmax}{.Ymin}{.Ymax}{.Char}{0|-1}
  41. ::: Arg 7 {0|-1} 0=Border Collision Fatal; -1=Non Fatal
  42.  %Background.Border%{48;2;130;100;10}{1}{50}{1}{25}{#}{0}
  43. ::: CNTRL.Width Default = 20. Info Panel position at col .Xmax + 5
  44. :::   Console Lines .Ymax + 2
  45. ::: Console Columns .Xmax + 5 + CNTRL.Width
  46. ::: Console resizes during execution of Background.Border Macro using the above offsets.
  47. ::: Game Control / Info Panel. Default width should be modified as shown in above Usage if
  48. ::: strings in panel info exceed 19 characters length
  49.  %Update.BackGround%
  50.  Set "lvl=1"
  51. rem /* custom {Y} coordinate for each line of a sprite to be supplied during Def.Sprite Expansion */
  52. rem /* using substring modification to replace # with Integer Y value GTR .Ymin LSS .Ymax */
  53. ========================================================================================================
  54.  %Def.Sprite:#=1%{player}{32}{ O  }
  55.      %Def.Sprite%{player}{32}{MWM }
  56.      %Def.Sprite%{player}{32}{ T  }
  57. ========================================================================================================
  58.   %Def.Sprite:#=3%{rocks}{90}{            @                             }
  59.       %Def.Sprite%{rocks}{90}{            @                             }
  60.       %Def.Sprite%{rocks}{90}{             #                         #@ }
  61.       %Def.Sprite%{rocks}{90}{                                      @@  }
  62.  %Def.Sprite:#=17%{rocks}{90}{                 @       @                }
  63.       %Def.Sprite%{rocks}{90}{                @         @               }
  64.       %Def.Sprite%{rocks}{90}{                #                         }
  65.       %Def.Sprite%{rocks}{90}{                 @                        }
  66. ========================================================================================================
  67.   %Def.Sprite:#=1%{river}{36}{                        .ll           }
  68.   %Def.Sprite:#=2%{river}{36}{                          ^l.         }
  69.       %Def.Sprite%{river}{36}{                           .l         }
  70.       %Def.Sprite%{river}{36}{                             .l_      }
  71.       %Def.Sprite%{river}{36}{                            .r^)._    }
  72.       %Def.Sprite%{river}{36}{                        _^)` .l`  ^). }
  73.       %Def.Sprite%{river}{36}{                             l`     . }
  74.       %Def.Sprite%{river}{36}{                           _l.        }
  75.       %Def.Sprite%{river}{36}{                          .           }
  76. ========================================================================================================
  77.   %Def.Sprite:#=9%{mount}{37}{        x X   xXx }
  78.       %Def.Sprite%{mount}{37}{       XxXx  Xx X }
  79.       %Def.Sprite%{mount}{37}{      Xx  xXxxX  x}
  80. ========================================================================================================
  81.   %Def.Sprite:#=8%{money}{33}{                                       $}
  82.  %Def.Sprite:#=12%{money}{33}{                          $}
  83. ========================================================================================================
  84. rem /* varname[index#] naming convention can be used to define multiple sprites of a given type - allowing for random selection from an array of sprites */
  85.  %Def.Sprite:#=21%{AI[1]}{31}{                                           /+\}
  86.       %Def.Sprite%{AI[1]}{31}{                                            + }
  87.       %Def.Sprite%{AI[1]}{31}{                                           \+/}
  88. ========================================================================================================
  89. rem /* Show initial sprite positions */
  90. rem /* Display order: Collectable; Background; Player; Collideable */
  91. :::    Display order priority allows quick confirmation of sprite placement during development
  92.  (
  93.   %Show:obj=money%
  94.   %Show:obj=mount%
  95.   %Show:obj=river%
  96.   %Show:obj=rocks%
  97.   %Show:obj=player%
  98.   %Show:obj=AI[1]%
  99.  )>%Foreground%
  100.  TYPE %Foreground%
  101. rem /* Define valid keys */
  102.  %Def.Key%"-72=up" "-80=down" "-75=left" "-77=right" "27=escape" "32=space" "13=enter"
  103.  %Def.Key%"48=0" "49=1" "50=2" "51=3" "52=4" "53=5" "54=6" "55=7" "56=8" "57=9"
  104.  %MSG:?= Sprite Demo by T3RRY. Collect Both $ Coins%
  105. rem / ********************** /
  106.  %PC.Prompt:Obj=AI[1]%{Start}{Waiting}
  107.  ========================================================================================================
  108. ::: GAME LOGIC           /* DEMO of Sprite movement and Display only. Not intended as an Actual Game. */
  109. :level[1] :# Objectives ::::::::::::::::::::::::::::::::::::
  110. ::: Player Win  - capture both $ coins                   :::
  111. ::: Player Loss - player or AI experiences any collision :::
  112. ::: AI     Win  - AI Captures any $ coin                 :::
  113. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  114. rem /* input is taken and assessed within the loop ; all game actions repeat with each loop until a specified end condition is met */
  115. rem /* clear previous key; catch new input */
  116.   Set "Key="& %GetKey%
  117. rem /* ::: ?Key# insert/remove substring modification ':mode=dev' for/after debugging. Dev mode allows testing of key inputs to identify errorcode values returned */
  118. rem /* Expand ?Key# macro; test if captured errorlevel corresponds to a valid key */
  119.  %?Key#:Obj=Player%
  120. rem /* Static Sprite Objects NOT collision tested should be refreshed each cycle PRIOR to movement */
  121.  %Show:obj=river%
  122. rem /* Test move in the current Direction for declared SPRITE OBJect valid against list of collision characters; Call :End on Collision */
  123. rem /* Previous sprite position overwritten with whitespace during Move.Sprite macro execution */
  124.  For %%O in (!Player.Dir!)Do (
  125.   %PC.Prompt:Obj=AI[1]%{%%O}{!.%%O!}
  126.   If /I not "!key!" == "enter" (
  127. rem /* if not key equ enter move in current dir */
  128.    For %%M in (!Player.Dir!)Do %Move.Sprite:obj=player%!%%M!{"@" "x" "+" "/" "\"}{"$"}
  129.   )Else (
  130. rem /* If key equ enter rotate sprite */
  131.    For %%D in (!Player.Dir!)Do %Rotate.Sprite:obj=player%{!r%%D!}{"@" "x" "+" "/" "\"}{"$"}
  132.   )
  133.   %SHOW:Obj=Player%
  134.  )
  135.  If !Player.capt! GEQ 1 Set /A "Playercoin+=1 + 0"
  136.  If "!valid!" == "0" ( Set "Win=Lost" & set ".Win=Won" & %G.O% 1)
  137. ::: GAME LOGIC OPTION :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  138. ::: Implement levels by using conditional tests that flag winning the current level jump to
  139. ::: a new label to define new sprites.
  140. ::: Before implementing a new level loop:
  141. :::   - endlocal environment to remove previous sprites and renew Setlocal EnableDelayedExpansion
  142. :::      [ Tunneling any variables For scoring etc ]
  143. :::     prior to defining the next batch of sprites - MUST be done to remove }Y;X definitions used
  144. :::     for collision testing.
  145.  If "!Playercoin!" == "2" (Set "Win=Won" & set ".Win=Lost" & %G.O:start=lvl[2]% 1)
  146. ::: %G.O:start=lvl[2]% Substitution changes label target from start to lvl[2] definition stage
  147. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  148. rem /* Simple AI sprite motion. AI moves in opposite direction to player */
  149.  For %%. in (!Player.Dir!)Do For %%M in (!.%%.!)Do %Move.Sprite:obj=AI[1]%!%%M!{"@" "x" "O" "M" "T"}{"$"}
  150.  If !AI[1].capt! GEQ 1 (Set "Win=Lost" & set ".Win=Won" & %G.O%)
  151.  If "!valid!" == "0" (Set "Win=Lost" & set ".Win=Lost" & %G.O%)
  152.  If /I "!Key!" == "escape" Goto :Quit
  153.  %Delay:#=100%
  154. Goto :level[1]
  155. =======================================================================================================
  156. ::: Demonstration of level implementation
  157. :lvl[2] :# Level specific definitions
  158. CLS
  159.  Set /A "lvl+=1+0"
  160.  Setlocal EnableDelayedExpansion
  161.  %MSG:?= Generating Border ...%
  162.  %Background.Border%{38;2;240;128;128}{1}{50}{1}{25}{#}{0}
  163.  %Update.BackGround%
  164. ========================================================================================================
  165.  %Def.Sprite:#=1%{player}{36}{ O  }
  166.      %Def.Sprite%{player}{36}{MWM }
  167.      %Def.Sprite%{player}{36}{ T  }
  168. ========================================================================================================
  169.   %Def.Sprite:#=5%{rocks}{38;2;160;82;45}{                  #@                    }
  170.       %Def.Sprite%{rocks}{38;2;160;82;45}{                 @#                   # }
  171.       %Def.Sprite%{rocks}{38;2;160;82;45}{                #                   @#@ }
  172.       %Def.Sprite%{rocks}{38;2;160;82;45}{                                      @@}
  173.  %Def.Sprite:#=17%{rocks}{38;2;160;82;45}{               @#@                      }
  174.       %Def.Sprite%{rocks}{38;2;160;82;45}{                @         @#            }
  175.       %Def.Sprite%{rocks}{38;2;160;82;45}{                           #@           }
  176. ========================================================================================================
  177.  %Def.Sprite:#=12%{river}{34}{      .ll     }
  178.       %Def.Sprite%{river}{34}{       ^l.    }
  179.       %Def.Sprite%{river}{34}{      .l      }
  180.       %Def.Sprite%{river}{34}{     .l_      }
  181.       %Def.Sprite%{river}{34}{   r^) ._     }
  182.       %Def.Sprite%{river}{34}{ .l`    ^).   }
  183.       %Def.Sprite%{river}{34}{        l` `. }
  184.       %Def.Sprite%{river}{34}{      _l   .^)}
  185.       %Def.Sprite%{river}{34}{          .r  }
  186. ========================================================================================================
  187.   %Def.Sprite:#=9%{mount}{37}{        x X   xXx }
  188.       %Def.Sprite%{mount}{37}{       XxXx  Xx X }
  189.       %Def.Sprite%{mount}{37}{      Xx  xXxxX  x}
  190. ========================================================================================================
  191.   %Def.Sprite:#=4%{money}{33}{                $}
  192.   %Def.Sprite:#=7%{money}{33}{                                        $}
  193. ========================================================================================================
  194.  %Def.Sprite:#=20%{AI[1]}{35}{                                           /+\}
  195.       %Def.Sprite%{AI[1]}{35}{                                           +++}
  196.       %Def.Sprite%{AI[1]}{35}{                                           \+/}
  197.       %Def.Sprite%{AI[1]}{35}{                                           \+/}
  198. ========================================================================================================
  199.  (
  200.   %Show:obj=money%
  201.   %Show:obj=mount%
  202.   %Show:obj=river%
  203.   %Show:obj=rocks%
  204.   %Show:obj=player%
  205.   %Show:obj=AI[1]%
  206.  ) >%Foreground%
  207.  TYPE %Foreground%
  208.  %Def.Key%"-72=up" "-80=down" "-75=left" "-77=right" "27=escape" "32=space" "13=enter"
  209.  %Def.Key%"48=0" "49=1" "50=2" "51=3" "52=4" "53=5" "54=6" "55=7" "56=8" "57=9"
  210.  %MSG:?= Sprite Demo by T3RRY. Collect Both $ Coins%
  211.  %PC.Prompt:Obj=AI[1]%{Start}{Waiting}
  212. :level[2] :# Gameplay Loop
  213.   Set "Key="& %GetKey%
  214.  %?Key#:Obj=Player%
  215.  %Show:obj=river%
  216.  For %%O in (!Player.Dir!)Do (
  217.   %PC.Prompt:Obj=AI[1]%{%%O}{!.%%O!}
  218.   If /I not "!key!" == "enter" (
  219. rem /* if not key equ enter move in current dir */
  220.    %Move.Sprite:obj=player%!%%O!{"@" "x" "+" "/" "\"}{"$"}
  221.   )Else (
  222. rem /* If key equ enter rotate sprite */
  223.    %Rotate.Sprite:obj=player%{!r%%O!}{"@" "x" "+" "/" "\"}{"$"}
  224.   )
  225.  )
  226.  If !Player.capt! GEQ 1 Set /A "Playercoin+=1 + 0"
  227.  If "!valid!" == "0" ( Set "Win=Lost" & set ".Win=Won" & %G.O%)
  228.  If "!Playercoin!" == "2" (Set "Win=Won" & set ".Win=Lost" & %G.O:start=Eof%)
  229.  For %%. in (!Player.Dir!)Do For %%M in (!.%%.!)Do %Move.Sprite:obj=AI[1]%!%%M!{"@" "x" "O" "M" }{"$"}
  230.  If !AI[1].capt! GEQ 1 (Set "Win=Lost" & set ".Win=Won" & %G.O%)
  231.  If "!valid!" == "0" (Set "Win=Lost" & set ".Win=Lost" & %G.O%)
  232.  If /I "!Key!" == "escape" Goto :Quit
  233.  %Delay:?=80%
  234. Goto :level[2]
  235. =======================================================================================================
  236. ::: SCRIPT BREAK :# Functions below.
  237. =======================================================================================================
  238. :End
  239.  (
  240.   %Show:obj=player%
  241.   %Show:obj=AI[1]%
  242.  )>%Foreground%
  243.  TYPE %Foreground%
  244. rem /* Sound alert level over */
  245.  Echo/n|Choice /N /C:y 2> nul
  246.  %MSG:?= Level !lvl! !Win! %
  247.  %PC.Prompt:Obj=AI[1]%{!Win!}{!.Win!}
  248.  Timeout /T 2 /Nobreak > Nul
  249.  <nul Set /P "=%\E%[!.End!;1H%\E%[?25h%\E%[31m{escape} %\E%[0m:%\E%[31m Quit%\E%[37m or %\E%[32mPress any Key to continue... "
  250. rem /* use substitution to remove /n no-wait switch from getkey macro execution; wait for input */
  251.  Set "Key="& %Getkey: /n=%
  252.  %?Key#%
  253.  If /I "!Key!" == "escape" (Call :Quit & Exit)
  254. :Quit
  255.  <nul Set /P "=%\E%[!.End!;1H%\E%[?25h%\E%[31m"
  256.  DEL "%Save.Dir%%~n0*.~tmp" 2> Nul
  257.  <nul Set /P "=%\E%[0m"
  258. Exit /B 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement