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.

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