Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ========================================================================================================
- ::: [ * HuntedSnake.bat ; Author: T3RRY { https://stackoverflow.com/users/12343998/t3rr0r } * ]
- ::: See it here: https://youtu.be/Wi3izdqbwcw
- ::: [ * REQUIRED * for Sprite definition and animation:
- ::: Game_Engine.bat ; Author: T3RRY { https://stackoverflow.com/users/12343998/t3rr0r } * ]
- ::: Additional Accreditation
- ::: [ * REQUIRED * for Extended key controls:
- ::: Getkey.Exe ; Author: Antonio { https://stackoverflow.com/users/778560/aacini } * ]
- ::: DOWNLOAD ALL + More Games_By_T3RRY from:
- ::: https://drive.google.com/file/d/1cAQLd-f9HN6SuWowBUETccKCZd2dVbWj/view?usp=sharing
- ========================================================================================================
- ::: Script prep
- @Echo off & CD "%~dp0"
- cls
- Call Game_EngineDEBUG.bat || (Echo/Game_Engine.bat missing & Exit /B 0)
- 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="
- Set "G.O=Call :End & Endlocal & Goto :start"
- Set "dir[1]=%left%" & Set "dir[2]=%right%" & Set "dir[3]=%up%" & Set "dir[4]=%down%"
- ========================================================================================================
- ::: Script main body
- ========================================================================================================
- :start
- CLS
- Set /A "lvl=1"
- Setlocal EnableDelayedExpansion
- %MSG:?= Generating Border ...%
- %Background.Border%{48;2;130;100;10}{1}{40}{1}{20}{#}{-1}
- %Update.BackGround%
- Set "lvl=1"
- ========================================================================================================
- ::: Level one playfield
- %Def.Sprite:#=2%{snake}{32}{ O }
- %Def.Sprite:#=2%{tail}{36}{] }
- %Def.Sprite:#=2%{rocks}{90}{ @ }
- %Def.Sprite%{rocks}{90}{ @ }
- %Def.Sprite%{rocks}{90}{ @ }
- %Def.Sprite%{rocks}{90}{ @ @ @ @@ }
- %Def.Sprite%{rocks}{90}{ @ @ @@ }
- %Def.Sprite:#=9%{rocks}{90}{ @@ @ }
- %Def.Sprite%{rocks}{90}{ @ @ @ }
- %Def.Sprite%{rocks}{90}{ @ @ @ }
- %Def.Sprite%{rocks}{90}{ @@ @ @ }
- %Def.Sprite%{rocks}{90}{ @ @ @ }
- %Def.Sprite%{rocks}{90}{ @ }
- %Def.Sprite%{rocks}{90}{ @ @ }
- %Def.Sprite%{rocks}{90}{ @ @@ }
- %Def.Sprite:#=8%{pushee}{91}{ XX }
- %Def.Sprite%{pushee}{91}{ XX }
- %Def.Multicol.Sprite:Obj=AI%"14;33H91M" "14;34H31M" "15;34H95/" "15;33H35\"
- ========================================================================================================
- Call :Getfood
- ========================================================================================================
- (
- %Show:obj=rocks%
- %Show:obj=snake%
- %Show:obj=tail%
- %Show:obj=Pushee%
- %Show:obj=AI%
- )>%Foreground%
- TYPE %Foreground%
- %Def.Key%"-72=up" "-80=down" "-75=left" "-77=right" "27=escape" "32=space" "13=enter"
- %Def.Key%"48=0" "49=1" "50=2" "51=3" "52=4" "53=5" "54=6" "55=7" "56=8" "57=9"
- %MSG:?= Hunted Snake by T3RRY. Introducing Game_Engine.bat%
- %PC.Prompt%{Start}{ }
- ========================================================================================================
- ::: GAME LOGIC /* DEMO of Def.Macros for Sprite based batch Arcade games - Adaptation from my Snake.Bat */
- rem /* Attribution: Kai Engel {https://freemusicarchive.org/music/Kai_Engel/Death.Soundless_The_Renaissance/04_-_Chant_Of_Night_Blades} */
- %Play.Music%{%~dp0Amphunt_Components\Chantofthenightblades.mp3}{60}{1}
- %Monitor.Game%
- :level[1] :# Objectives :::::::::::::::::::::::::::::::::::::::::::::::::
- Set "ltime=!TIME:~9,1!"
- ::: snake Loss - snake experiences any collision with non food cell
- ::: - remmed out { rock collision } - now non fatal
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- Set "Key="& %GetKey%
- rem /* transfer player input dir to snake object direction - can be used to control other objects */
- %?Key#:Obj=Snake%
- If /I "!Key!" == "escape" Goto :Quit
- For %%M in (!Snake.Dir!)Do (
- rem /* Insert / remove "]" tail char from collision arg to switch tail collision on off */
- %Move.Sprite:obj=snake%!%%M!{"%.Char%" "X" "@" "/" "\" "M"}{"$"}
- %PC.Prompt:Obj=AI%{%%M}{!AI.DIR!}
- rem /* if not blocking collision ; update tail cells */
- If not "!Snake.Collide.Type!" == "@" If not "!Snake.Collide.Type!" == "#" If not "!Snake.Collide.Type!" == "]" If not "!Snake.Collide.Type!" == "X" (
- Set "Tail="!oy!;!ox!H]",!Tail!"
- Set "Tail.{i}=0"
- For %%G in (!Tail!)Do For /F "Tokens=1,2,3* Delims=[;H" %%A in (%%G)Do (
- If !Tail.{i}! EQU !Tail.Len! (
- Set "Tail=!Tail:,"%%A;%%BH%%C"=,!"
- Set "}%%A;%%B="
- <nul Set /P "=%\E%[%%A;%%BH "
- ) Else (
- Set "}%%A;%%B=%%A;%%BH%%C"
- Set /A "Tail.{i}+=1"
- )))
- %Show:obj=tail%
- )
- If "!Snake.Collide.Type!" == "X" For %%M in ("!Snake.Dir!")Do %Move.Sprite:obj=pushee%!%%~M!{"#" "@" "/" "\" "M" "$" "]"}
- Rem /* Attribution: Chris Rierson {https://freesound.org/people/ChrisReierson/sounds/383979/} */
- If !Snake.Coll! GEQ 1 (
- %Play.Music%{%~dp0Amphunt_Components\ding.wav}{15}{0}
- %Delay:#=5%
- )
- :# [ rem: remove ::: below to make rock collisions fatal ]
- ::: If "!Snake.Collide.Type!" == "@" ( Set "State=Hit Rock" & %G.O% 1)
- If "!Snake.Collide.Type!" == "/" ( Set "State=Nommed :^(" & %G.O% 1)
- If "!Snake.Collide.Type!" == "\" ( Set "State=Nommed :^(" & %G.O% 1)
- If "!Snake.Collide.Type!" == "M" ( Set "State=Nommed :^(" & %G.O% 1)
- If "!Snake.Collide.Type!" == "]" ( Set "State=Ate tail" & %G.O% 1)
- If "!?Border.Fatal!" == "0" If "!Collide.Type!" == "!.Char!" ( Set "State=Wall Splat" & %G.O% 1)
- If "!Snake.Collide.Type!" == "$" Call :Getfood
- :# [ rem: toggle border fatal condition off for AI character only ]
- Set "Snake?Border.Fatal=!?Border.Fatal!"
- Set "?Border.fatal=-1"
- rem /* Select random X Y movement axis for AI */
- Set /A "AI.Axis=!Random! %%2 + 1"
- rem /* when sprite does no thave momentum ; initial direction must be chosen */
- If not defined AI.Dir (
- For /F "Delims=" %%z in ('Set /A "d.xy=!random! %%4 + 1"')Do %Move.Sprite:obj=AI%!Dir[%%z]!{"#" "X" "@" "$"}{"O"}
- ) Else (
- rem /* For selected AI moement axis ; assess ai sprite psoition reletive to target sprite [snake] */
- rem /* Make the move closer to the taget accordingly */
- If "!AI.Axis!" == "1" (
- If !AI.lX! LSS !Snake.lX! (
- %Move.Sprite:obj=AI%!right!{"#" "X" "@" "$"}{"O"}
- ) Else %Move.Sprite:obj=AI%!left!{"#" "X" "@" "$"}{"O"}
- ) Else (
- If !AI.lY! LSS !Snake.lY! (
- %Move.Sprite:obj=AI%!down!{"#" "X" "@" "$"}{"O"}
- ) Else (
- %Move.Sprite:obj=AI%!up!{"#" "X" "@" "$"}{"O"}
- ))
- rem /* If a sprite is permitted non fatal interaction with other sprites, it should be displayed after movement */
- %Show:Obj=AI%
- )
- If not "!valid!" == "0" If "!AI.Capt!" == "1" ( Set "State=Nommed." & %G.O% 1)
- Set "?Border.fatal=!Snake?Border.Fatal!"
- Set "Collide.Type="
- ::: If "!TIME:~9,1!" == "!ltime!" %Delay:#=20%
- %?Key#:Obj=AI%
- Goto :level[1]
- =======================================================================================================
- ::: SCRIPT BREAK :# Functions below.
- :Getfood :# HuntedSnake.bat Script specific function
- :# Generate Food Cell; If within Border; If cell not occupied; display, adjust cell definitions;
- :# grow tail and return to gameloop.
- Set /A "fy=(!random! %% (.Ymax - .Ymin) + .Ymin ) + 1,fx=(!random! %% (.Xmax - .Xmin) + .Xmin ) + 1"
- For /F "Tokens=1,2 Delims={}" %%X in ("{!fX!}{!fY!}")Do (
- If %%Y LSS !.Ymax! If %%X LSS !.Xmax! If %%Y GTR !.Ymin! If %%X GTR !.Xmin! if "!}%%Y;%%X!" == "" (
- <nul Set /P "=%\E%[%%Y;%%XH%\E%[33m$%\E%[0m"
- Set "}%%Y;%%X=%%Y;%%XH$"
- Set /A "Tail.Len+=1"
- rem /* Attribution: Brad Wesson {https://freesound.org/people/bradwesson/sounds/135936/} */
- %Play.Music%{%~dp0Amphunt_Components\collectcoin.wav}{80}{0}
- Exit /B 0
- ))
- Goto :Getfood
- =======================================================================================================
- :End :# Game_Engine Sprite system cleanup tasks and game end related output.
- %Show:Obj=AI%
- %Stop.Music%
- rem /* Sound alert level over */
- rem /* Attribution: Fupicat {https://freesound.org/people/Fupicat/sounds/475347/} */
- If /I "!State:~0,6!" == "Nommed" (%Play.Music%{%~dp0Amphunt_Components\death.wav}{100}{0})
- %PC.Prompt%{!State!}{}
- Timeout /T 2 /Nobreak > Nul
- <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... "
- Set "Key="& %Getkey: /n=%
- %?Key#%
- If /I "!Key!" == "escape" (Call :Quit & Exit)
- :Quit
- Title
- %Stop.Music:running=%
- <nul Set /P "=%\E%[%.End%;1H%\E%[0m Thanks for trying %\E%[31mhuntedsnake%\E%[0m by %\E%[34mT3RRY%\E%[0m.%\E%[?25h"
- DEL "%Save.Dir%%~n0*.~tmp" 2> Nul
- Exit /B 0
Add Comment
Please, Sign In to add comment