Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

tank.nls 2.7 KiB

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