Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

160 lignes
3.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. ]
  21. ;; ==========
  22. ;; Procedures
  23. ;; ==========
  24. to spawn-tank [tank-team tank-xcor tank-ycor tank-heading]
  25. create-tanks 1 [
  26. set-tank-vars false tank-team tank-xcor tank-ycor tank-heading
  27. ]
  28. end
  29. to set-tank-vars [player? tteam txcor tycor theading]
  30. set acceleration 0.03
  31. set ammunition 20
  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. setxy txcor tycor
  50. end
  51. to do-tank-logic
  52. if is-accelerating? [
  53. accelerate acceleration
  54. ]
  55. fd speed
  56. decelerate friction
  57. if fire-cool-down > 0 [
  58. set fire-cool-down fire-cool-down - 1
  59. ]
  60. end
  61. to accelerate [amount]
  62. set speed speed + amount
  63. if speed > max-speed [
  64. set speed max-speed
  65. ]
  66. end
  67. to decelerate [amount]
  68. set speed speed - amount
  69. if speed < 0 [
  70. set speed 0
  71. ]
  72. end
  73. to tank-facexy [txcor tycor]
  74. ;; Face a target at (txcor, tycor) like facexy, but don't
  75. ;; turn more than our max turn rate (max-turn¡):
  76. let old-heading heading
  77. facexy txcor tycor
  78. if subtract-headings old-heading heading > max-turn [
  79. set heading old-heading - max-turn
  80. ]
  81. if subtract-headings old-heading heading < 0 - max-turn [
  82. set heading old-heading + max-turn
  83. ]
  84. end
  85. to fire
  86. if fire-cool-down = 0 [
  87. ifelse ammunition > 0 [
  88. debug who "TANK-FIRE" (word (ammunition - 1) " left")
  89. set ammunition ammunition - 1
  90. fire-bullet 8
  91. play-sound "fire"
  92. ] [
  93. play-sound "noammo"
  94. ]
  95. set fire-cool-down max-fire-rate
  96. ]
  97. end
  98. to tank-shot-at
  99. set armor armor - 1
  100. ifelse armor = 0 [
  101. debug who "TANK-KILL" (word "by " ([shooter] of myself))
  102. explode "huge"
  103. play-sound "kill"
  104. kill-tank
  105. ] [
  106. debug who "TANK-SHOT" (word "by " ([shooter] of myself))
  107. explode "medium"
  108. play-sound "shot"
  109. ]
  110. end
  111. to kill-tank
  112. if is-player? [
  113. set player-deaths player-deaths + 1
  114. ]
  115. if [is-shooter-player?] of myself [
  116. set player-kills player-kills + 1
  117. ]
  118. die
  119. end
  120. to place-pill
  121. ifelse number-of-pills > 0 and count bases-here = 0 [
  122. set number-of-pills number-of-pills - 1
  123. hatch-pillbox
  124. play-sound "place"
  125. ] [
  126. play-sound "nopill"
  127. ]
  128. end
  129. ;; =========
  130. ;; Reporters
  131. ;; =========
  132. to-report get-tank-affiliation
  133. if is-player? [ report "player" ]
  134. if team = 0 [ report "ally" ]
  135. report "enemy"
  136. end
  137. to-report get-tank-color
  138. let affiliation get-tank-affiliation
  139. if affiliation = "player" [ report black ]
  140. if affiliation = "ally" [ report green ]
  141. if affiliation = "enemy" [ report red ]
  142. end