T3RRYT3RR0R

HuntedSnake.bat

Dec 28th, 2020 (edited)
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 9.31 KB | None | 0 0
  1. ========================================================================================================
  2. ::: [ * HuntedSnake.bat ; Author: T3RRY { https://stackoverflow.com/users/12343998/t3rr0r } * ]
  3. :::   See it here: https://youtu.be/Wi3izdqbwcw
  4. ::: [ * REQUIRED * for Sprite definition and animation:
  5. :::     Game_Engine.bat  ; Author: T3RRY { https://stackoverflow.com/users/12343998/t3rr0r } * ]
  6. :::                                    Additional Accreditation
  7. ::: [ * REQUIRED * for Extended key controls:
  8. :::     Getkey.Exe       ; Author: Antonio { https://stackoverflow.com/users/778560/aacini } * ]
  9. ::: DOWNLOAD ALL + More Games_By_T3RRY from:
  10. ::: https://drive.google.com/file/d/1cAQLd-f9HN6SuWowBUETccKCZd2dVbWj/view?usp=sharing
  11. ========================================================================================================
  12. ::: Script prep
  13. @Echo off & CD "%~dp0"
  14.  cls
  15.  Call Game_EngineDEBUG.bat || (Echo/Game_Engine.bat missing & Exit /B 0)
  16.  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%[!snake.Color!msnake: %%G%\E%[0m   " )& If not "!OHASH!" == "Obj" ( < Nul Set /P "=%\E%!!!!!!H%\E%[!Obj.Color!mObj: %%H%\E%[0m     " )))Else Set PC.NPC="
  17.  Set "G.O=Call :End & Endlocal & Goto :start"
  18.  Set "dir[1]=%left%" & Set "dir[2]=%right%" & Set "dir[3]=%up%" & Set "dir[4]=%down%"
  19. ========================================================================================================
  20. ::: Script main body
  21. ========================================================================================================
  22. :start
  23. CLS
  24.  Set /A "lvl=1"
  25.  Setlocal EnableDelayedExpansion
  26.  %MSG:?= Generating Border ...%
  27.  %Background.Border%{48;2;130;100;10}{1}{40}{1}{20}{#}{-1}
  28.  %Update.BackGround%
  29.  Set "lvl=1"
  30. ========================================================================================================
  31. ::: Level one playfield
  32.   %Def.Sprite:#=2%{snake}{32}{ O }
  33.    %Def.Sprite:#=2%{tail}{36}{]  }
  34.   %Def.Sprite:#=2%{rocks}{90}{            @                       }
  35.       %Def.Sprite%{rocks}{90}{                       @            }
  36.       %Def.Sprite%{rocks}{90}{                @                   }
  37.       %Def.Sprite%{rocks}{90}{     @       @   @              @@  }
  38.       %Def.Sprite%{rocks}{90}{      @                   @    @@   }
  39.   %Def.Sprite:#=9%{rocks}{90}{          @@      @                 }
  40.       %Def.Sprite%{rocks}{90}{             @     @        @       }
  41.       %Def.Sprite%{rocks}{90}{         @   @              @       }
  42.       %Def.Sprite%{rocks}{90}{  @@     @  @                       }
  43.       %Def.Sprite%{rocks}{90}{    @                   @       @   }
  44.       %Def.Sprite%{rocks}{90}{                               @    }
  45.       %Def.Sprite%{rocks}{90}{      @                         @   }
  46.       %Def.Sprite%{rocks}{90}{     @          @@                  }
  47.  %Def.Sprite:#=8%{pushee}{91}{                                 XX }
  48.      %Def.Sprite%{pushee}{91}{                                 XX }
  49.  %Def.Multicol.Sprite:Obj=AI%"14;33H91M" "14;34H31M" "15;34H95/" "15;33H35\"
  50. ========================================================================================================
  51.  Call :Getfood
  52. ========================================================================================================
  53.  (
  54.   %Show:obj=rocks%
  55.   %Show:obj=snake%
  56.   %Show:obj=tail%
  57.   %Show:obj=Pushee%
  58.   %Show:obj=AI%
  59.  )>%Foreground%
  60.  TYPE %Foreground%
  61.  %Def.Key%"-72=up" "-80=down" "-75=left" "-77=right" "27=escape" "32=space" "13=enter"
  62.  %Def.Key%"48=0" "49=1" "50=2" "51=3" "52=4" "53=5" "54=6" "55=7" "56=8" "57=9"
  63.  %MSG:?= Hunted Snake by T3RRY. Introducing Game_Engine.bat%
  64.  %PC.Prompt%{Start}{ }
  65.  ========================================================================================================
  66. ::: GAME LOGIC /* DEMO of Def.Macros for Sprite based batch Arcade games - Adaptation from my Snake.Bat */
  67. rem /* Attribution: Kai Engel {https://freemusicarchive.org/music/Kai_Engel/Death.Soundless_The_Renaissance/04_-_Chant_Of_Night_Blades} */
  68.  %Play.Music%{%~dp0Amphunt_Components\Chantofthenightblades.mp3}{60}{1}
  69.  %Monitor.Game%
  70. :level[1] :# Objectives :::::::::::::::::::::::::::::::::::::::::::::::::
  71.  Set "ltime=!TIME:~9,1!"
  72. ::: snake Loss - snake experiences any collision with non food cell
  73. :::  - remmed out { rock collision } - now non fatal
  74. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  75.  Set "Key="& %GetKey%
  76. rem /* transfer player input dir to snake object direction - can be used to control other objects */
  77.  %?Key#:Obj=Snake%
  78.  If /I "!Key!" == "escape" Goto :Quit
  79.  For %%M in (!Snake.Dir!)Do (
  80. rem /* Insert / remove "]" tail char from collision arg to switch tail collision on off */
  81.   %Move.Sprite:obj=snake%!%%M!{"%.Char%" "X" "@" "/" "\" "M"}{"$"}
  82.   %PC.Prompt:Obj=AI%{%%M}{!AI.DIR!}
  83. rem /* if not blocking collision ; update tail cells */
  84.   If not "!Snake.Collide.Type!" == "@"  If not "!Snake.Collide.Type!" == "#" If not "!Snake.Collide.Type!" == "]" If not "!Snake.Collide.Type!" == "X" (
  85.    Set "Tail="!oy!;!ox!H]",!Tail!"
  86.    Set "Tail.{i}=0"
  87.    For %%G in (!Tail!)Do For /F "Tokens=1,2,3* Delims=[;H" %%A in (%%G)Do (
  88.     If !Tail.{i}! EQU !Tail.Len! (
  89.      Set "Tail=!Tail:,"%%A;%%BH%%C"=,!"
  90.      Set "}%%A;%%B="
  91.      <nul Set /P "=%\E%[%%A;%%BH "
  92.     ) Else (
  93.      Set "}%%A;%%B=%%A;%%BH%%C"
  94.      Set /A "Tail.{i}+=1"
  95.   )))
  96.   %Show:obj=tail%
  97.  )
  98.  If "!Snake.Collide.Type!" == "X" For %%M in ("!Snake.Dir!")Do %Move.Sprite:obj=pushee%!%%~M!{"#" "@" "/" "\" "M" "$" "]"}
  99. Rem /* Attribution: Chris Rierson {https://freesound.org/people/ChrisReierson/sounds/383979/} */
  100.  If !Snake.Coll! GEQ 1 (
  101.   %Play.Music%{%~dp0Amphunt_Components\ding.wav}{15}{0}
  102.   %Delay:#=5%
  103.  )
  104. :# [ rem: remove ::: below to make rock collisions fatal ]
  105. ::: If "!Snake.Collide.Type!" == "@" ( Set "State=Hit Rock" & %G.O% 1)
  106.  If "!Snake.Collide.Type!" == "/" ( Set "State=Nommed :^(" & %G.O% 1)
  107.  If "!Snake.Collide.Type!" == "\" ( Set "State=Nommed :^(" & %G.O% 1)
  108.  If "!Snake.Collide.Type!" == "M" ( Set "State=Nommed :^(" & %G.O% 1)
  109.  If "!Snake.Collide.Type!" == "]" ( Set "State=Ate tail" & %G.O% 1)
  110.  If "!?Border.Fatal!" == "0" If "!Collide.Type!" == "!.Char!" ( Set "State=Wall Splat" & %G.O% 1)
  111.  If "!Snake.Collide.Type!" == "$" Call :Getfood
  112. :# [ rem: toggle border fatal condition off for AI character only ]
  113.  Set "Snake?Border.Fatal=!?Border.Fatal!"
  114.  Set "?Border.fatal=-1"
  115. rem /* Select random X Y movement axis for AI */
  116.  Set /A "AI.Axis=!Random! %%2 + 1"
  117. rem /* when sprite does no thave momentum ; initial direction must be chosen */
  118.  If not defined AI.Dir (
  119.   For /F "Delims=" %%z in ('Set /A "d.xy=!random! %%4 + 1"')Do %Move.Sprite:obj=AI%!Dir[%%z]!{"#" "X" "@" "$"}{"O"}
  120.  ) Else (
  121. rem /* For selected AI moement axis ; assess ai sprite psoition reletive to target sprite [snake] */
  122. rem /* Make the move closer to the taget accordingly */
  123.   If "!AI.Axis!" == "1" (
  124.    If !AI.lX! LSS !Snake.lX! (
  125.     %Move.Sprite:obj=AI%!right!{"#" "X" "@" "$"}{"O"}
  126.    ) Else %Move.Sprite:obj=AI%!left!{"#" "X" "@" "$"}{"O"}
  127.   ) Else (
  128.    If !AI.lY! LSS !Snake.lY! (
  129.     %Move.Sprite:obj=AI%!down!{"#" "X" "@" "$"}{"O"}
  130.    ) Else (
  131.     %Move.Sprite:obj=AI%!up!{"#" "X" "@" "$"}{"O"}
  132.   ))
  133. rem /* If a sprite is permitted non fatal interaction with other sprites, it should be displayed after movement */
  134.   %Show:Obj=AI%
  135.  )
  136.  If not "!valid!" == "0" If "!AI.Capt!" == "1" ( Set "State=Nommed." & %G.O% 1)
  137.  Set "?Border.fatal=!Snake?Border.Fatal!"
  138.  Set "Collide.Type="
  139. ::: If "!TIME:~9,1!" == "!ltime!" %Delay:#=20%
  140.  %?Key#:Obj=AI%
  141. Goto :level[1]
  142. =======================================================================================================
  143. ::: SCRIPT BREAK :# Functions below.
  144. :Getfood :# HuntedSnake.bat Script specific function
  145. :# Generate Food Cell; If within Border; If cell not occupied; display, adjust cell definitions;
  146. :#  grow tail and return to gameloop.
  147.  Set /A "fy=(!random! %% (.Ymax - .Ymin) + .Ymin ) + 1,fx=(!random! %% (.Xmax - .Xmin) + .Xmin ) + 1"
  148.  For /F "Tokens=1,2 Delims={}" %%X in ("{!fX!}{!fY!}")Do (
  149.   If %%Y LSS !.Ymax! If %%X LSS !.Xmax! If %%Y GTR !.Ymin! If %%X GTR !.Xmin! if "!}%%Y;%%X!" == "" (
  150.    <nul Set /P "=%\E%[%%Y;%%XH%\E%[33m$%\E%[0m"
  151.    Set "}%%Y;%%X=%%Y;%%XH$"
  152.    Set /A "Tail.Len+=1"
  153. rem /* Attribution: Brad Wesson {https://freesound.org/people/bradwesson/sounds/135936/} */
  154.    %Play.Music%{%~dp0Amphunt_Components\collectcoin.wav}{80}{0}
  155.    Exit /B 0
  156.  ))
  157. Goto :Getfood
  158. =======================================================================================================
  159. :End :# Game_Engine Sprite system cleanup tasks and game end related output.
  160.  %Show:Obj=AI%
  161.  %Stop.Music%
  162. rem /* Sound alert level over */
  163. rem /* Attribution: Fupicat {https://freesound.org/people/Fupicat/sounds/475347/} */
  164.  If /I "!State:~0,6!" == "Nommed" (%Play.Music%{%~dp0Amphunt_Components\death.wav}{100}{0})
  165.  %PC.Prompt%{!State!}{}
  166.  Timeout /T 2 /Nobreak > Nul
  167.  <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... "
  168.  Set "Key="& %Getkey: /n=%
  169.  %?Key#%
  170.  If /I "!Key!" == "escape" (Call :Quit & Exit)
  171. :Quit
  172.   Title
  173.   %Stop.Music:running=%
  174.  <nul Set /P "=%\E%[%.End%;1H%\E%[0m            Thanks for trying %\E%[31mhuntedsnake%\E%[0m by %\E%[34mT3RRY%\E%[0m.%\E%[?25h"
  175.  DEL "%Save.Dir%%~n0*.~tmp" 2> Nul
  176. Exit /B 0
  177.  
  178.  
Add Comment
Please, Sign In to add comment