Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

140 rader
3.1 KiB

  1. ;; lobo: Logo Bolo
  2. ;; (c) Ben Kurtovic, 2011
  3. globals [
  4. base-max-ammo
  5. base-max-armor
  6. ]
  7. breed [bases base]
  8. bases-own [
  9. ammunition
  10. armor
  11. last-ammo-regen
  12. last-armor-regen
  13. last-refuel
  14. team
  15. ]
  16. ;; ==========
  17. ;; Procedures
  18. ;; ==========
  19. to spawn-base [base-xcor base-ycor]
  20. create-bases 1 [
  21. set-base-vars base-max-ammo base-max-armor -1 base-xcor base-ycor
  22. ]
  23. end
  24. to set-base-vars [b-ammo b-armor b-team b-xcor b-ycor]
  25. set ammunition b-ammo
  26. set armor b-armor
  27. set team b-team
  28. set last-ammo-regen timer
  29. set last-armor-regen timer
  30. set last-refuel timer
  31. set color get-base-color
  32. set shape "base"
  33. set size 1.15
  34. setxy b-xcor b-ycor
  35. end
  36. to do-base-logic
  37. ifelse team = -1 [
  38. if any? tanks-here [
  39. claim-base one-of tanks-here
  40. ]
  41. ] [
  42. let allies-here tanks-here with [team = ([team] of myself)]
  43. let enemies-here tanks-here with [team != ([team] of myself)]
  44. if any? allies-here [
  45. refuel-tank one-of allies-here
  46. ]
  47. if any? enemies-here and armor = 0 [
  48. claim-base one-of enemies-here
  49. set armor 1
  50. ]
  51. ]
  52. regenerate
  53. set label armor
  54. end
  55. to claim-base [claimer]
  56. debug who "BASE-TAKE" (word "by " ([who] of claimer) ": " team " -> " [team] of claimer)
  57. set team [team] of claimer
  58. set color get-base-color
  59. set last-armor-regen timer ; Don't regenerate armor right after being claimed
  60. end
  61. to refuel-tank [tank-to-refuel]
  62. let time-since-last-refuel timer - last-refuel
  63. ask tank-to-refuel [
  64. ifelse armor < tank-max-armor and ([armor] of myself) > 1 [
  65. if time-since-last-refuel > 25 / max-fps [ ; 25 frames
  66. set armor armor + 1
  67. ask myself [
  68. set armor armor - 1
  69. set last-refuel timer
  70. ]
  71. ]
  72. ] [
  73. if ammunition < tank-max-ammo and ([ammunition] of myself) > 1 [
  74. if time-since-last-refuel > 10 / max-fps [ ; 10 frames
  75. set ammunition ammunition + 1
  76. ask myself [
  77. set ammunition ammunition - 1
  78. set last-refuel timer
  79. ]
  80. ]
  81. ]
  82. ]
  83. ]
  84. end
  85. to regenerate
  86. let time-since-last-ammo-regen timer - last-ammo-regen
  87. let time-since-last-armor-regen timer - last-armor-regen
  88. if ammunition < base-max-ammo and time-since-last-ammo-regen > 6 [
  89. set ammunition ammunition + 1
  90. set last-ammo-regen timer
  91. ]
  92. if armor < base-max-armor and time-since-last-armor-regen > 15 [
  93. set armor armor + 1
  94. set last-armor-regen timer
  95. ]
  96. end
  97. to base-shot-at
  98. set armor armor - 1
  99. set last-armor-regen timer ; Don't regenerate armor right after being shot
  100. ifelse armor > 0 [
  101. debug who "BASE-SHOT" (word "by " ([shooter] of myself))
  102. explode "small"
  103. play-sound "shot"
  104. ] [
  105. debug who "BASE-KILL" (word "by " ([shooter] of myself))
  106. explode "medium"
  107. play-sound "kill"
  108. ]
  109. end
  110. ;; =========
  111. ;; Reporters
  112. ;; =========
  113. to-report get-base-afiliation
  114. if team = -1 [ report "neutral" ]
  115. if team = 0 [ report "ally" ]
  116. report "enemy"
  117. end
  118. to-report get-base-color
  119. let affiliation get-base-afiliation
  120. if affiliation = "neutral" [ report gray ]
  121. if affiliation = "ally" [ report green ]
  122. if affiliation = "enemy" [ report red ]
  123. end