Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
4.0 KiB

  1. ;; lobo: Logo Bolo
  2. ;; (c) Ben Kurtovic, 2011-2012
  3. breed [tanks tank]
  4. tanks-own [
  5. acceleration
  6. ammunition
  7. armor
  8. fire-cool-down
  9. friction
  10. is-accelerating?
  11. is-player?
  12. max-ammo
  13. max-armor
  14. max-fire-rate
  15. max-speed
  16. max-turn
  17. number-of-pills
  18. speed
  19. team
  20. ai-objective
  21. ]
  22. ;; ==========
  23. ;; Procedures
  24. ;; ==========
  25. to spawn-tank [tank-team tank-heading]
  26. sprout-tanks 1 [
  27. set-tank-vars false tank-team tank-heading
  28. ]
  29. end
  30. to set-tank-vars [player? tteam theading]
  31. set acceleration 0.03
  32. set ammunition 4
  33. set armor 8
  34. set fire-cool-down 0
  35. set friction 0.0075
  36. set is-accelerating? false
  37. set is-player? player?
  38. set max-ammo 24
  39. set max-armor 8
  40. set max-fire-rate 7
  41. set max-speed 0.25
  42. set max-turn 24
  43. set number-of-pills 0
  44. set speed 0
  45. set team tteam
  46. set ai-objective "nothing"
  47. set color get-tank-color
  48. set heading theading
  49. set shape "tank"
  50. set size 1.5
  51. end
  52. to do-tank-logic
  53. if not is-player? [
  54. ai-do-cycle
  55. ]
  56. if is-accelerating? [
  57. accelerate acceleration
  58. ]
  59. fd speed * ground-friction
  60. decelerate friction
  61. if fire-cool-down > 0 [
  62. set fire-cool-down fire-cool-down - 1
  63. ]
  64. end
  65. to accelerate [amount]
  66. set speed speed + amount
  67. if speed > max-speed [
  68. set speed max-speed
  69. ]
  70. end
  71. to decelerate [amount]
  72. set speed speed - amount
  73. if speed < 0 [
  74. set speed 0
  75. ]
  76. end
  77. to tank-facexy [txcor tycor]
  78. ;; Face a target at (txcor, tycor) like facexy, but don't
  79. ;; turn more than our max turn rate (max-turn¡):
  80. let old-heading heading
  81. facexy txcor tycor
  82. if subtract-headings old-heading heading > max-turn [
  83. set heading old-heading - max-turn
  84. ]
  85. if subtract-headings old-heading heading < 0 - max-turn [
  86. set heading old-heading + max-turn
  87. ]
  88. end
  89. to fire
  90. if fire-cool-down = 0 [
  91. ifelse ammunition > 0 [
  92. debug who "TANK-FIRE" (word (ammunition - 1) " left")
  93. set ammunition ammunition - 1
  94. fire-bullet 6
  95. play-sound "fire"
  96. ] [
  97. play-sound "noammo"
  98. ]
  99. set fire-cool-down max-fire-rate
  100. ]
  101. end
  102. to tank-shot-at
  103. set armor armor - 1
  104. ifelse armor = 0 [
  105. debug who "TANK-KILL" (word "by " ([shooter] of myself))
  106. explode "huge"
  107. play-sound "kill"
  108. kill-tank
  109. ] [
  110. debug who "TANK-SHOT" (word "by " ([shooter] of myself))
  111. explode "medium"
  112. play-sound "shot"
  113. ]
  114. end
  115. to kill-tank
  116. if is-player? [
  117. set player-deaths player-deaths + 1
  118. ]
  119. if [is-shooter-player?] of myself [
  120. set player-kills player-kills + 1
  121. ]
  122. ifelse is-player? [
  123. ifelse any? bases with [team = -1 or team = 0] [
  124. ask patch (6 - random 12) (4 - random 8) [
  125. spawn-player (random 360)
  126. ]
  127. ] [
  128. set stop-game ["GAME OVER: PLAYER LOSES!" "Enemy controls all bases"]
  129. ]
  130. ] [
  131. ifelse any? bases with [team = -1 or team = 1] [
  132. ask patch (6 - random 12) (4 - random 8) [
  133. spawn-tank ([team] of myself) (random 360)
  134. ]
  135. ] [
  136. set stop-game ["GAME OVER: PLAYER WINS!" "Player controls all bases"]
  137. ]
  138. ]
  139. ask max-one-of tanks [who] [ ; Tank that was just spawned
  140. play-sound "spawn"
  141. ]
  142. while [number-of-pills > 0] [
  143. let mpxcor pxcor
  144. let mpycor pycor
  145. ask one-of patches with [(count pillboxes-here) = 0 and pxcor <= (mpxcor + 2) and pxcor >= (mpxcor - 2) and pycor <= (mpycor + 2) and pycor >= (mpycor - 2)] [
  146. spawn-pillbox
  147. ask max-one-of pillboxes [who] [
  148. set armor 0
  149. set alive? false
  150. set shape "pillbox-dead"
  151. ]
  152. ]
  153. set number-of-pills number-of-pills - 1
  154. ]
  155. die
  156. end
  157. to place-pill
  158. ifelse number-of-pills > 0 and count bases-here = 0 [
  159. set number-of-pills number-of-pills - 1
  160. hatch-pillbox
  161. play-sound "place"
  162. ] [
  163. play-sound "nopill"
  164. ]
  165. end
  166. ;; =========
  167. ;; Reporters
  168. ;; =========
  169. to-report get-tank-affiliation
  170. if is-player? [ report "player" ]
  171. if team = 0 [ report "ally" ]
  172. report "enemy"
  173. end
  174. to-report get-tank-color
  175. let affiliation get-tank-affiliation
  176. if affiliation = "player" [ report black ]
  177. if affiliation = "ally" [ report green ]
  178. if affiliation = "enemy" [ report red ]
  179. end