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.

419 linhas
6.2 KiB

  1. ;; lobo: Logo Bolo
  2. ;; (c) Ben Kurtovic, 2011
  3. ;;
  4. ;; Logo Bolo is a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo.
  5. ;;
  6. __includes [
  7. "bullet.nls"
  8. "player.nls"
  9. "tank.nls"
  10. ]
  11. extensions [
  12. sound
  13. table
  14. ]
  15. globals [
  16. last-tick-time
  17. max-fps
  18. mouse-was-down?
  19. player
  20. player-deaths
  21. player-has-target?
  22. player-kills
  23. player-target-xcor
  24. player-target-ycor
  25. sounds
  26. ]
  27. ;; ===========================
  28. ;; Button-initiated procedures
  29. ;; ===========================
  30. to setup
  31. clear-all
  32. no-display
  33. setup-defaults
  34. ask patches [
  35. set pcolor (random 3) - 5 + green
  36. ]
  37. spawn-player
  38. spawn-tank 0 ask tank 1 [ setxy -6 0 ]
  39. spawn-tank 1 ask tank 2 [ setxy 6 0 ]
  40. render
  41. set last-tick-time timer
  42. end
  43. to go
  44. ask player [
  45. do-player-logic
  46. ]
  47. ask tanks [
  48. do-tank-logic
  49. ]
  50. ask bullets [
  51. do-bullet-logic
  52. ]
  53. show-crosshair
  54. render
  55. keep-time
  56. end
  57. ;; ================
  58. ;; Other procedures
  59. ;; ================
  60. to debug [action msg]
  61. ; Comment this and remove the output box
  62. ; to turn off debugging info:
  63. output-print (word (round timer) ": " action ": " msg)
  64. end
  65. to setup-defaults
  66. set-patch-size 30
  67. resize-world -8 8 -8 8
  68. set max-fps 30
  69. set mouse-was-down? false
  70. set player-deaths 0
  71. set player-has-target? false
  72. set player-kills 0
  73. set player-target-xcor 0
  74. set player-target-ycor 0
  75. make-sounds-table
  76. end
  77. to make-sounds-table
  78. set sounds table:make
  79. table:put sounds "fire" "Hand Clap"
  80. table:put sounds "shot player" "Acoustic Snare"
  81. table:put sounds "shot ally" "Acoustic Snare"
  82. table:put sounds "shot enemy" "Acoustic Snare"
  83. table:put sounds "kill player" "Electric Snare"
  84. table:put sounds "kill ally" "Electric Snare"
  85. table:put sounds "kill enemy" "Electric Snare"
  86. end
  87. to show-crosshair
  88. clear-drawing
  89. if mouse-inside? [
  90. ask patch mouse-xcor mouse-ycor [
  91. draw-border white 1
  92. ]
  93. ]
  94. if player-has-target? [
  95. ask patch player-target-xcor player-target-ycor [
  96. draw-border white 2
  97. ]
  98. ]
  99. end
  100. to draw-border [b-color b-thickness]
  101. sprout 1 [
  102. set color b-color
  103. set pen-size b-thickness
  104. set heading 0
  105. fd 0.5
  106. pd
  107. rt 90
  108. fd 0.5
  109. repeat 3 [
  110. rt 90
  111. fd 1
  112. ]
  113. rt 90
  114. fd 0.5
  115. die
  116. ]
  117. end
  118. to render
  119. display
  120. no-display
  121. end
  122. to keep-time
  123. let time-since-last-tick timer - last-tick-time
  124. let wait-time (1 / max-fps) - time-since-last-tick
  125. wait wait-time
  126. tick
  127. set last-tick-time timer
  128. end
  129. to play-sound [name]
  130. if enable-sound? [
  131. let dist distancexy ([xcor] of player) ([ycor] of player)
  132. let volume 127 - (dist * 4)
  133. if volume > 0 [
  134. sound:play-drum (table:get sounds name) volume
  135. ]
  136. ]
  137. end
  138. @#$#@#$#@
  139. GRAPHICS-WINDOW
  140. 452
  141. 10
  142. 972
  143. 551
  144. 8
  145. 8
  146. 30.0
  147. 1
  148. 10
  149. 1
  150. 1
  151. 1
  152. 0
  153. 1
  154. 1
  155. 1
  156. -8
  157. 8
  158. -8
  159. 8
  160. 0
  161. 0
  162. 1
  163. frames
  164. BUTTON
  165. 43
  166. 100
  167. 138
  168. 133
  169. New Game
  170. setup
  171. NIL
  172. 1
  173. T
  174. OBSERVER
  175. NIL
  176. R
  177. NIL
  178. NIL
  179. BUTTON
  180. 290
  181. 99
  182. 384
  183. 132
  184. Play Game
  185. go
  186. T
  187. 1
  188. T
  189. OBSERVER
  190. NIL
  191. G
  192. NIL
  193. NIL
  194. MONITOR
  195. 269
  196. 290
  197. 389
  198. 339
  199. Player Speed
  200. [speed] of player
  201. 8
  202. 1
  203. 12
  204. BUTTON
  205. 109
  206. 172
  207. 230
  208. 224
  209. FIRE!
  210. player-fire
  211. NIL
  212. 1
  213. T
  214. OBSERVER
  215. NIL
  216. F
  217. NIL
  218. NIL
  219. MONITOR
  220. 270
  221. 350
  222. 389
  223. 399
  224. Player Has Target?
  225. player-has-target?
  226. 5
  227. 1
  228. 12
  229. OUTPUT
  230. 998
  231. 30
  232. 1375
  233. 521
  234. 12
  235. MONITOR
  236. 55
  237. 290
  238. 149
  239. 339
  240. Player Deaths
  241. player-deaths
  242. 17
  243. 1
  244. 12
  245. MONITOR
  246. 55
  247. 350
  248. 148
  249. 399
  250. Player Kills
  251. player-kills
  252. 17
  253. 1
  254. 12
  255. MONITOR
  256. 160
  257. 290
  258. 261
  259. 339
  260. Player Ammo
  261. [ammunition] of player
  262. 17
  263. 1
  264. 12
  265. MONITOR
  266. 160
  267. 350
  268. 260
  269. 399
  270. Player Armor
  271. [armor] of player
  272. 17
  273. 1
  274. 12
  275. SWITCH
  276. 264
  277. 179
  278. 394
  279. 212
  280. enable-sound?
  281. enable-sound?
  282. 0
  283. 1
  284. -1000
  285. MONITOR
  286. 272
  287. 411
  288. 390
  289. 460
  290. Player Target
  291. word \"(\" player-target-xcor \", \" player-target-ycor \")\"
  292. 10
  293. 1
  294. 12
  295. @#$#@#$#@
  296. WHAT IS IT?
  297. -----------
  298. This section could give a general understanding of what the model is trying to show or explain.
  299. HOW IT WORKS
  300. ------------
  301. This section could explain what rules the agents use to create the overall behavior of the model.
  302. HOW TO USE IT
  303. -------------
  304. This section could explain how to use the model, including a description of each of the items in the interface tab.
  305. THINGS TO NOTICE
  306. ----------------
  307. This section could give some ideas of things for the user to notice while running the model.
  308. THINGS TO TRY
  309. -------------
  310. This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.
  311. EXTENDING THE MODEL
  312. -------------------
  313. This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.
  314. NETLOGO FEATURES
  315. ----------------
  316. This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.
  317. RELATED MODELS
  318. --------------
  319. This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.
  320. CREDITS AND REFERENCES
  321. ----------------------
  322. This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.
  323. @#$#@#$#@
  324. default
  325. true
  326. 0
  327. Polygon -7500403 true true 150 5 40 250 150 205 260 250
  328. bullet
  329. true
  330. 5
  331. Rectangle -16777216 true false 135 30 165 90
  332. Rectangle -1 true false 135 90 165 150
  333. Rectangle -1 true false 135 150 165 210
  334. Polygon -16777216 true false 135 30 150 0 165 30 135 30
  335. Rectangle -2674135 true false 135 210 165 270
  336. Rectangle -16777216 true false 120 270 180 300
  337. Polygon -7500403 true false 195 210 165 150 165 210 195 210
  338. Rectangle -7500403 true false 165 210 195 268
  339. Rectangle -7500403 true false 105 210 135 268
  340. Polygon -7500403 true false 105 210 135 150 135 210 105 210
  341. tank
  342. true
  343. 1
  344. Rectangle -7500403 true false 78 85 116 103
  345. Polygon -7500403 true false 105 270 210 271 210 105 180 105 180 135 120 135 120 105 90 105 89 270
  346. Polygon -2674135 true true 120 105 90 105 90 180 120 180 120 195 180 195 180 180 210 180 210 105 180 105 165 105 165 135 135 135 135 105 120 105
  347. Polygon -1 true false 135 15 135 150 165 150 165 15
  348. Polygon -1 true false 67 105 67 255 97 255 97 105
  349. Polygon -1 true false 202 105 202 255 232 255 232 105
  350. Rectangle -7500403 true false 184 85 222 103
  351. @#$#@#$#@
  352. NetLogo 4.1.3
  353. @#$#@#$#@
  354. @#$#@#$#@
  355. @#$#@#$#@
  356. @#$#@#$#@
  357. @#$#@#$#@
  358. default
  359. 0.0
  360. -0.2 0 1.0 0.0
  361. 0.0 1 1.0 0.0
  362. 0.2 0 1.0 0.0
  363. link direction
  364. true
  365. 0
  366. Line -7500403 true 150 150 90 180
  367. Line -7500403 true 150 150 210 180
  368. @#$#@#$#@
  369. 0
  370. @#$#@#$#@