Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

143 Zeilen
2.6 KiB

  1. ;; lobo: Logo Bolo
  2. ;; (c) Ben Kurtovic, 2011
  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-fire-rate
  13. max-speed
  14. max-turn
  15. speed
  16. team
  17. ]
  18. ;; ==========
  19. ;; Procedures
  20. ;; ==========
  21. to spawn-tank [tank-team]
  22. create-tanks 1 [
  23. set-tank-vars tank-team false
  24. ]
  25. end
  26. to set-tank-vars [tank-team player-tank?]
  27. set acceleration 0.03
  28. set ammunition 24
  29. set armor 8
  30. set fire-cool-down 0
  31. set friction 0.0075
  32. set is-accelerating? false
  33. set is-player? player-tank?
  34. set max-fire-rate 7
  35. set max-speed 0.25
  36. set max-turn 24
  37. set speed 0
  38. set team tank-team
  39. set color get-tank-color
  40. set heading 0
  41. set shape "tank"
  42. set size 1.5
  43. end
  44. to do-tank-logic
  45. if is-accelerating? [
  46. accelerate acceleration
  47. ]
  48. fd speed
  49. decelerate friction
  50. if fire-cool-down > 0 [
  51. set fire-cool-down fire-cool-down - 1
  52. ]
  53. end
  54. to accelerate [amount]
  55. set speed speed + amount
  56. if speed > max-speed [
  57. set speed max-speed
  58. ]
  59. end
  60. to decelerate [amount]
  61. set speed speed - amount
  62. if speed < 0 [
  63. set speed 0
  64. ]
  65. end
  66. to tank-facexy [txcor tycor]
  67. ;; Face a target at (txcor, tycor) like facexy, but don't
  68. ;; turn more than our max turn rate (max-turn¡):
  69. let old-heading heading
  70. facexy txcor tycor
  71. if subtract-headings old-heading heading > max-turn [
  72. set heading old-heading - max-turn
  73. ]
  74. if subtract-headings old-heading heading < 0 - max-turn [
  75. set heading old-heading + max-turn
  76. ]
  77. end
  78. to fire
  79. if fire-cool-down = 0 [
  80. ifelse ammunition > 0 [
  81. debug "FIRE" (word who " (" ammunition " left)")
  82. set ammunition ammunition - 1
  83. fire-bullet
  84. play-sound "fire"
  85. ] [
  86. play-sound "noammo"
  87. ]
  88. set fire-cool-down max-fire-rate
  89. ]
  90. end
  91. to shot-at
  92. debug "SHOT" (word who " by " ([shooter] of myself))
  93. set armor armor - 1
  94. ifelse armor = 0 [
  95. explode "kill"
  96. play-sound "kill"
  97. kill-tank
  98. ] [
  99. explode "shot"
  100. play-sound "shot"
  101. ]
  102. end
  103. to kill-tank
  104. debug "KILL" (word who " by " ([shooter] of myself))
  105. if is-player? [
  106. set player-deaths player-deaths + 1
  107. ]
  108. if [is-player?] of (turtle [shooter] of myself) [
  109. set player-kills player-kills + 1
  110. ]
  111. die
  112. end
  113. ;; =========
  114. ;; Reporters
  115. ;; =========
  116. to-report get-tank-affiliation
  117. if is-player? [ report "player" ]
  118. if team = 0 [ report "ally" ]
  119. report "enemy"
  120. end
  121. to-report get-tank-color
  122. let affiliation get-tank-affiliation
  123. if affiliation = "player" [ report black ]
  124. if affiliation = "ally" [ report green ]
  125. if affiliation = "enemy" [ report red ]
  126. end