Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
2.8 KiB

  1. ;; lobo: Logo Bolo
  2. ;; (c) Ben Kurtovic, 2011
  3. globals [
  4. tank-max-ammo
  5. tank-max-armor
  6. ]
  7. breed [tanks tank]
  8. tanks-own [
  9. acceleration
  10. ammunition
  11. armor
  12. fire-cool-down
  13. friction
  14. is-accelerating?
  15. is-player?
  16. max-fire-rate
  17. max-speed
  18. max-turn
  19. number-of-pills
  20. speed
  21. team
  22. ]
  23. ;; ==========
  24. ;; Procedures
  25. ;; ==========
  26. to spawn-tank [tank-team tank-xcor tank-ycor tank-heading]
  27. create-tanks 1 [
  28. set-tank-vars false tank-team tank-xcor tank-ycor tank-heading
  29. ]
  30. end
  31. to set-tank-vars [player? tteam txcor tycor theading]
  32. set acceleration 0.03
  33. set ammunition tank-max-ammo
  34. set armor tank-max-armor
  35. set fire-cool-down 0
  36. set friction 0.0075
  37. set is-accelerating? false
  38. set is-player? player?
  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. ;; =========
  121. ;; Reporters
  122. ;; =========
  123. to-report get-tank-affiliation
  124. if is-player? [ report "player" ]
  125. if team = 0 [ report "ally" ]
  126. report "enemy"
  127. end
  128. to-report get-tank-color
  129. let affiliation get-tank-affiliation
  130. if affiliation = "player" [ report black ]
  131. if affiliation = "ally" [ report green ]
  132. if affiliation = "enemy" [ report red ]
  133. end