Advertisement
Ganondox

Troll Slayer

Aug 21st, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 4.28 KB | None | 0 0
  1. @echo off
  2. SetLocal ENABLEDELAYEDEXPANSION
  3.  
  4. REM While it was created as an independent game, it was created as a proof of concept for action scenes in Rariquest, which REM I never implemented.
  5.  
  6. echo TROLL SLAYER
  7. echo -
  8.  
  9. :start
  10.  
  11. REM intilize
  12. set /a heroX= 1
  13. set /a heroY= 1
  14. set /a trollX= 9
  15. set /a trollY= 6
  16. set /a westwall= 0
  17. set /a eastwall= 10
  18. set /a northwall= 0
  19. set /a southwall= 7
  20. set /a rockX= 6
  21. set /a rockY= 4
  22. set /a swordX= %eastwall% + 1
  23. set /a swordY= %southwall% + 1
  24. set heroChar= @
  25. set trollChar= T
  26. set rockChar= O
  27. set swordChar= +
  28.  
  29. set heroD= W
  30. set swordOut= false
  31.  
  32. :loop
  33. REM reset background
  34. set /a y= %northwall%
  35. :outer
  36. set /a x= %westwall%
  37. :inner
  38. set char%y%_%x%= .
  39. set /a x= x + 1
  40. if %x% LEQ %eastwall% goto inner
  41. set /a y= y + 1
  42. if %y% LEQ %southwall% goto outer
  43.  
  44. REM add walls
  45. set /a x= %westwall%
  46. :northwall
  47. set char%northwall%_%x%= -
  48. set /a x= x + 1
  49. if %x% LEQ %eastwall% goto :northwall
  50. set /a x= %westwall%
  51. :southwall
  52. set char%southwall%_%x%= -
  53. set /a x= x + 1
  54. if %x% LEQ %eastwall% goto :southwall
  55. set /a y= %northwall%
  56. :westwall
  57. set char%y%_%westwall%= -
  58. set /a y= y + 1
  59. if %y% LEQ %southwall% goto :westwall
  60. set /a y= %northwall%
  61. :eastwall
  62. set char%y%_%eastwall%= -
  63. set /a y= y + 1
  64. if %y% LEQ %southwall% goto :eastwall
  65.  
  66. REM add objects
  67. set char%heroY%_%heroX%=%heroChar%
  68. set char%trollY%_%trollX%=%trollChar%
  69. set char%rockY%_%rockX%=%rockChar%
  70. set char%swordY%_%swordX%=%swordChar%
  71.  
  72.  
  73. REM display
  74. set /a y= %northwall%
  75. :outer1
  76. set displayline=
  77. set /a x= %westwall%
  78. :inner1
  79. set displayline=%displayline% !char%y%_%x%!
  80. set /a x= x + 1
  81. if %x% LEQ %eastwall% goto inner1
  82. echo %displayline%
  83. set /a y= y + 1
  84. if %y% LEQ %southwall% goto outer1
  85.  
  86. REM character eaten if under troll
  87. set character=!char%heroY%_%heroX%!
  88. if %character%==%trollChar% goto gameover
  89.  
  90. REM troll slain if under sword
  91. set character=!char%trollY%_%trollX%!
  92. if %character%==%swordChar% goto win
  93.  
  94. set swordOut= false
  95.  
  96. REM move character (WASD)
  97. set /a nheroY = %heroY%
  98. set /a nheroX = %heroX%
  99. choice /c QWASDZ /n /t 1 /d Q    
  100. if %errorlevel%==2 set /a nheroY= heroY - 1
  101. if %errorlevel%==2 set heroD=W
  102. if %errorlevel%==3 set /a nheroX= heroX - 1
  103. if %errorlevel%==3 set heroD=A
  104. if %errorlevel%==4 set /a nheroY= heroY + 1
  105. if %errorlevel%==4 set heroD=S
  106. if %errorlevel%==5 set /a nheroX= heroX + 1
  107. if %errorlevel%==5 set heroD=D
  108. if %errorlevel%==6 set swordOut=true
  109.  
  110. REM prevent moving into walls and rocks
  111. set return= retChar
  112. set char=hero
  113. goto walls
  114. :retChar
  115.  
  116. REM update characters location
  117. set /a heroX = %nheroX%
  118. set /a heroY = %nheroY%
  119. set char%heroY%_%heroX%=%heroChar%
  120.  
  121. REM move troll (random)
  122. set /a ntrollY = %trollY%
  123. set /a ntrollX = %trollX%  
  124. set dir= %random%
  125. set /a dir= dir - ( (dir / 5) * 5)
  126. if %dir%==1 set /a ntrollY= trollY - 1
  127. if %dir%==2 set /a ntrollX= trollX - 1
  128. if %dir%==3 set /a ntrollY= trollY + 1
  129. if %dir%==4 set /a ntrollX= trollX + 1
  130.  
  131. REM prevent moving into walls and rocks
  132. set return= retTroll
  133. set char=troll
  134. goto walls
  135. :retTroll
  136.  
  137. REM update trolls location
  138. set /a trollX = %ntrollX%
  139. set /a trollY = %ntrollY%
  140.  
  141. REM move sword in if sword is out
  142. if %swordOut%==true goto sword
  143. set /a swordX= %eastwall% + 1
  144. set /a swordY= %southwall% + 1
  145. goto loop
  146.  
  147. :sword
  148. echo WHOA
  149. REM move sword
  150. set /a nswordX= heroX
  151. set /a nswordY= heroY
  152. if %heroD%==W set /a nswordY= %heroY% - 1
  153. if %heroD%==A set /a nswordX= %heroX% - 1
  154. if %heroD%==S set /a nswordY= %heroY% + 1
  155. if %heroD%==D set /a nswordX= %heroX% + 1
  156.  
  157. REM prevent moving into walls and rocks
  158. set return= retSword
  159. set char=sword
  160. goto walls
  161. :retSword
  162.  
  163. REM update swords location
  164. set /a swordX = %nswordX%
  165. set /a swordY = %nswordY%
  166.  
  167. goto loop
  168.  
  169. :walls
  170. REM set char and return before calling
  171. set /a nY= !n%char%Y!
  172. set /a nX= !n%char%X!
  173. if %nX%==%westwall% goto block
  174. if %nX%==%eastwall% goto block
  175. if %nY%==%northwall% goto block
  176. if %nY%==%southwall% goto block
  177. set destination=!char%nY%_%nX%!
  178. if %destination%==%rockChar% goto block
  179. goto %return%
  180. :block
  181. echo "THUD^!"
  182. set /a n%char%X= !%char%X!
  183. set /a n%char%Y= !%char%Y!
  184. goto %return%
  185.  
  186.  
  187. :gameover
  188. echo You ams eaten by a troll.
  189. pause
  190. goto retry
  191.  
  192.  
  193. :win
  194. echo You ams slay the troll.
  195. pause
  196. goto retry
  197.  
  198. :retry
  199. echo -
  200. echo Ams plays again?
  201. choice
  202. if %errorlevel%==1 goto start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement